3
votes

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: output

But my problem is I need output like this (Expected output) : expected output

1
Can't you just divide your data by 1000000 before plotting?tmdavison

1 Answers

3
votes

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.