Issue
I have a dataframe where I have formatted the numbers per the snip below, but when I plot this the formatting reverts to scientific. How do I format the chart to match the dataframe? the data type is float64 and I am using Pycharm. My code is below, Thanks
import pandas as pd
import matplotlib.pyplot as plt
gdp2019 = pd.read_csv("GDP2019.csv")
pd.options.display.float_format = '{:,.2f}'.format
newDF.plot(x='LOCATION', y='Value', kind='bar')
plt.show()
Solution
Add this line to your code to get rid of scientific notation on the y axis:
plt.ticklabel_format(axis = 'y', style= 'plain')
If you want the y-label numbers to be comma_separated and show two decimal points, use this line instead:
import matplotlib.ticker as ticker
plt.gca().yaxis.set_major_formatter(ticker.StrMethodFormatter('{x:,.2f}'))
Answered By - pakpe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.