2017-08-05 165 views
1

我是Python新手,需要使用pyplot和matplotlib生成条形图。到目前为止,我想是这样的(我附上只有重要的代码片段):这段代码的Python Matplotlib - 如何在条形图中设置y轴上的值

 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") 

输出是: enter image description here

但我的问题是我需要这样的(预期输出)输出: enter image description here

预先感谢您的答复

+0

在绘图之前,你不能只将数据除以1000000吗? – tom

回答

2

如果你想保持你的final4Average的值相同,你可以尝试这样的事情,有一个新的数组绘制数据集:

final4AverageModified = [x/1000000 for x in final4Average] 

而且你可以编辑你的数据集,使它像这样:

finalDatasetModified =[finalAverage, final4AverageModified] 

然后,最后,使情节制图打电话使它像这样:

rects1=plt.bar(ind, finalDatasetModified, width, color='blue') 

这样,您就可以保留原来的数据final4Average并保持新数据final4AverageModified。这只是在绘图之前划分你的数据。

+0

谢谢!这正是我所期待的! –

+2

不客气!如果这已回答您的问题,请考虑“接受”此答案,并在此答案旁边的复选标记! – sccoding

相关问题