[Chicago] Suggestions on improving histogram in matplotlib?

Lewit, Douglas d-lewit at neiu.edu
Fri Mar 20 19:33:24 CET 2015


Hey there,

I'm attaching my script (done in Python 3 but it should work almost the
same in Python 2) and also a .png file that shows the resulting histogram.
It looks really good!  However, a couple of comments or criticisms.  First
off, if you look at my command *pyplot.title(.....)* you'll see that the
title begins with "\n" (the newline character) but it doesn't cause an
extra blank line above the title in my plot.  Any suggestions?  Or is that
just a minor bug in matplotlib?

Also, please note that the rectangles of the histogram are not squarely
placed over the corresponding tickmarks, except when you get closer to the
center of the histogram, around 11, 12, 13, 14, 15, 16, 17, 18, etc.  But
further out the rectangles appear toward the side of the corresponding
tickmark.  Again, I'm not sure if that's a true "bug" or maybe I'm just not
interpreting the histogram properly or maybe that's how all histograms
should be drawn!  I really don't know, but if you have any suggestions
please let me know.

In case you're wondering, this is the problem of rolling 4 dice and
recording their sums.  So the smallest sum should be 4 (1 + 1 + 1 + 1) and
the largest sum should be 24 (6 + 6 + 6 + 6).  The sum of 14 is the most
probable of all the sums, with a probability of close to 12%.  The other
sums are less probable, and the least probable sums of all are 4 and 24.
The data look normally distributed with a mean of about 14, but I'm not
sure about the variance and standard deviation.  I didn't bother to compute
those, but they are probably not that difficult to compute from the raw
data generated by Python.

The script won't work unless you have matplotlib as part of your Python
installation!  Matplotlib is pretty amazing, and produces graphics that are
on par with Maple, Mathematica and Matlab.  (Matplotlib's plots look very
"Matlabby" to me.  I'm not sure if that's a coincidence or if that was an
intentional part of the design.  What do you think? )

Okay, thanks!  I appreciate any constructive suggestions on improving the
histogram so that it has professional textbook quality.

Best,

Douglas Lewit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20150320/e714ea44/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Histogram4Dice.png
Type: image/png
Size: 64743 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/chicago/attachments/20150320/e714ea44/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Histogram4Dice.py
Type: text/x-python-script
Size: 924 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/chicago/attachments/20150320/e714ea44/attachment-0001.bin>


More information about the Chicago mailing list