Reputation: 69
Using the following code as an example i create a dataframe named dataset.
value1 = np.random.random(100)*30
value2 = np.random.random(100)*30
value3 = np.random.random(100)*30
value4 = np.random.random(100)*1000
dataset = pd.DataFrame({'value1': value1, 'value2': value2, 'value3': value3, 'value4': value4}, columns=['value1', 'value2', 'value3', 'value4'])
dataset[['value1', 'value2', 'value3']].plot(figsize=(20,10), linewidth=2, fontsize = 20, grid=True, marker="o", label='a').legend(loc='upper center', bbox_to_anchor=(0.5, -0.12),
ncol=12, prop={'size': 16});
dataset['value4'].plot(secondary_y=True, legend=True, linewidth=2, marker="o",)
plt.xlabel('Year',fontsize=20)
plt.ylabel('(b)',fontsize=20)
I plot this dataset on 2 axis but for some reason only the axis on the right is printed out but the left axis is not printing and am not sure why.
Secondly, am also trying to see how value1,2,3 respond to variable 4 (value4) so i would like the plot displayed as shown in the fig below. On the image we can see that we have variable 4 at the bottom of the graph and the rest at the top so we can clearly see how a rise or decline in variable 4 impacts variables 1,2,3. Currenly the display shows all all the variables mixed up but i would like it to look like the image below.
Any assitance would be great, thanks
Upvotes: 1
Views: 145
Reputation: 35115
Your code is correct. They are drawn on a range of two axes each. If you want to match it to your expected output, you can use ax1.set_ylim(-30,30)
or ax 2.set_ylim(0,4000)
.
ax1 = dataset[['value1', 'value2', 'value3']].plot(figsize=(20,10),
linewidth=2, fontsize = 20,
grid=True, marker="o", label='a')
ax1.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12), ncol=12, prop={'size': 16});
ax2 = dataset['value4'].plot(secondary_y=True,legend=True, linewidth=2, marker="o",)
ax1.set_ylim(-30,30)
ax2.set_ylim(0,4000)
ax1.set_xlabel('Year',fontsize=20)
ax2.set_ylabel('(b)',fontsize=20)
Upvotes: 2