how to set values on y axis in barchart
I am new to Python and I need to generate bar chart using pyplot and matplotlib. So far i tried like this (I have attached only the important code snippet):
import matplotlib.pyplot as plt import numpy as np finalDataset=[finalAverage,final4Average] N=len(finalDataset) ind=np.arange(N) width=0.45 rects1=plt.bar(ind,finalDataset,width,color='blue') plt.xticks(ind+width/2,("A","B")) plt.ylabel('y-axis') plt.xlabel('x-axis') plt.savefig("sample.png")
Output of this code is:
But my problem is I need output like this (Expected output) :
If you'd like to keep the values of your final4Average
the same, you could try something like this, to plot the dataset with a new array:
final4AverageModified = [x/1000000 for x in final4Average]
And you could edit your dataset to make it like this:
finalDatasetModified =[finalAverage, final4AverageModified]
And then, finally, make the plot-graphing call to make it like this:
rects1=plt.bar(ind, finalDatasetModified, width, color='blue')
This way, you can keep your original data in final4Average
and keep the new data in final4AverageModified
. This just divides your data before plotting.
上一篇: Emacs :(几乎)随机崩溃了大约2
下一篇: 如何在条形图中设置y轴上的值