Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib set bar starting point value

I have a dataset which I am plotting with the help of python's matplotlib as follows :

import matplotlib.pyplot as plt
%matplotlib inline

n_groups = 10
fig, ax = plt.subplots()
fig.set_size_inches(15,10)
index = np.arange(0, n_groups * 2, 2)
print index
bar_width = 0.35
opacity = 0.4
error_config = {'ecolor': '0.3'}

rects1 = plt.bar(index, df.Quant[0:10], bar_width,
                 alpha=opacity,
                 color='b',
                 error_kw=error_config,
                 label='Quant')

rects2 = plt.bar(index + bar_width, df.English[0:10], bar_width,
                 alpha=opacity,
                 color='r',
                 error_kw=error_config,
                 label='English')

rects3 = plt.bar(index + bar_width * 2, df.Logical[0:10], bar_width,
                 alpha=opacity,
                 color='g',
                 error_kw=error_config,
                 label='Logical')

plt.xlabel('Group')
plt.ylabel('Scores')
plt.title('Scores by Designation')
plt.xticks(index + bar_width, df.Designation[0:10], rotation='vertical')
plt.legend()

plt.tight_layout()
plt.show()

which results into the following chart :

enter image description here

As you can see, the values are differing just above 400 points. How do i reduce the scope of the chart from 400 and to beyond?

Also, I was trying to do the same in seaborn but couldn't find any example to do so.

like image 728
Koustuv Sinha Avatar asked Oct 19 '22 16:10

Koustuv Sinha


1 Answers

Using ax.set(ylim=[400, 600]) will do the trick. Here, 400 is the minimum value for y-axis and 600 is the maximum value for y-axis. Change it as required.

I have reproduced a part of your graph with the y-axis curtailed. enter image description here

like image 79
Pratanu Mandal Avatar answered Oct 21 '22 06:10

Pratanu Mandal