0

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

  • 1
    Please add the actual data instead of a screenshot – mhannani Oct 12 '20 at 20:23
  • 1
    `ax.set_yticks(np.arange(0, max(GDP['GDP'])+5, 5))` and I'd like you to give your attention to the `set_` part… – gboffi Oct 12 '20 at 20:43
  • 1
    You can use `from matplotlib.ticker import MultipleLocator` and `ax.yaxis.set_major_locator(MultipleLocator(5))` to get ticks at every multiple of 5 without the need to calculate the maximum. – JohanC Oct 12 '20 at 21:00

0 Answers0