Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot a grouped bar chart from multiple datasets

I am going through Think Stats and I would like to compare multiple data sets visually. I can see from the book examples that it is possible to generate an interleaved bar graph with a different color for each data set by using a module provided by the book author, how to obtain the same result in pyplot?

like image 505
tunnuz Avatar asked Apr 26 '11 15:04

tunnuz


1 Answers

Call the bar function multiple times, one for each series. You can control the left position of the bars using the left parameter, and you can use this to prevent overlap.

Entirely untested code:

pyplot.bar( numpy.arange(10) * 2, data1, color = 'red' )
pyplot.bar( numpy.arange(10) * 2 + 1, data2, color = 'red' )

Data2 will be drawn shifted over the right compared to where data one will be drawn.

like image 87
Winston Ewert Avatar answered Sep 30 '22 12:09

Winston Ewert