Need to change pace of one of the axes in my chart matplotlib

203 Views Asked by At

Fairly new to plotting need help have this DATAFRAME that I'm working on. trying to change the pace on my left y_axis to be 5 instead of 10 but I guess 'AxesSubplot' object has no attribute 'yticks' so I can't use

ax.yticks(np.arange(0, max(GDP['GDP'])+5, 5))

This is my Code ( the plotting part)

fig = plt.figure() # Create matplotlib figure

ax = fig.add_subplot(111) # Create matplotlib axes
ax2 = ax.twinx() # Create another axes that shares the same x-axis as ax.

width = 0.7
newdf.GDP.plot(kind='bar', color='#8D99FB', ax=ax, width=width)
newdf.Unemployment.plot(kind='line', color='red', ax=ax2)

ax.set_ylabel('GDP over The years in billions of dollars')
#ax.yticks(np.arange(0, max(GDP['GDP'])+5, 5))
ax2.set_ylabel('Percentage of Unemployment/total Population')
ax.set_xticklabels(newdf.Year.tolist())

ax.set_xlim(-width,len(newdf.Year.tolist()))

plt.title('GDP over The years in billions of dollars')



'''
ax.yticks(np.arange(0, max(GDP['GDP'])+5, 5))

'''
plt.show()

Thanks

0

There are 0 best solutions below