Home > Mobile >  Setting Y Axis values on matplotlib chart, incrementing
Setting Y Axis values on matplotlib chart, incrementing

Time:12-19

Please may someone assist me on this. I am trying to add Y Axis values to my matplotlib chart so the chart looks like this Excel Chart:

enter image description here

However, on my matplotlib chart, the Y Axis values are from 0-6:

enter image description here

Is there some code I have left out here to add the values to the chart? Do I need to manually specify the values for them to be in increments of £10 million? I'm still very new to this sorry!

df_total_gross_sales.set_index('Date').plot.bar()

plt.title('Gross Sales: Discounted Vs Full Price', pad = 10, Fontsize =16)
plt.ylabel("Gross Sales (£)", labelpad = 10, fontsize=14)
plt.xlabel("Year-Month", labelpad = 20, fontsize=14)

plt.tight_layout()
plt.legend(facecolor='white', fontsize =13,  framealpha=1)
plt.show()

enter image description here

CodePudding user response:

Just add

plt.gca().yaxis.set_major_formatter('₤{x:,}')

Somewhere before show.

A enter image description here

The same example, without that line, shows a y-axis with ticks labelled from 0 to 7, with, as in your example, in legend saying that those are ×10⁷ units.

Note that the ticks value in this format string is always named x (even tho it is y axis).

  • Related