0

I want the Y-axis in the Graph with the Range in the Sum column.

total_by_year.plot(kind='bar' ,x='year',y='sum',rot=0, legend=False)
plt.show()

DataFrame output:

   year          sum
0  2010  42843534.38
1  2011  45349314.40
2  2012  35445927.76
3  2013         0.00

below is the Graph i am getting: enter image description here

Joe
  • 12,057
  • 5
  • 39
  • 55
user1882624
  • 303
  • 2
  • 4
  • 16
  • But the range of the y-axis does coincide with the range of the sum column?? The highest value in the sum column is 42843534.38 which is ~4.2e7 So, what exactly is not correct about the graph? – Amos Egel Sep 17 '18 at 06:47
  • @AmosEgel Instead of showing the y axis as 0,1,2,3 i want to display them as in the dataframe – user1882624 Sep 17 '18 at 06:56
  • 1
    Possible duplicate of [Matplotlib: Specify format of floats for tick lables](https://stackoverflow.com/questions/29188757/matplotlib-specify-format-of-floats-for-tick-lables) – msi_gerva Sep 17 '18 at 09:20

2 Answers2

1

You can use this:

import matplotlib.pyplot as plt
import matplotlib

y = total_by_year['sum']
ax = total_by_year.plot(kind='bar' ,x='year',y='sum',rot=0, legend=False)
ax.yaxis.set_major_formatter(matplotlib.ticker.FormatStrFormatter("%.2f"))
plt.yticks(y)
plt.show()

enter image description here

Or if you want just the scientific notation, remove plt.yticks(y)

Joe
  • 12,057
  • 5
  • 39
  • 55
0

I see.

So exactly you want to change the axis format of the graph. Maybe you could see How do I change the format of the axis label in matplotlib Ask Question

Or you could also do like that

total_by_year.plot(kind='bar' ,x='year',y='sum',rot=0, legend=False,yticks=total_by_year["sum"])

but it will be ugly. So I also recommend that you should capture the ax and revise the format of its.

tianhua liao
  • 655
  • 5
  • 9