Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 870
Gowthamy Vaseekaran Avatar asked Sep 06 '25 18:09

Gowthamy Vaseekaran


1 Answers

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.

like image 158
sccoding Avatar answered Sep 08 '25 07:09

sccoding