<div dir="ltr"><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jun 20, 2014 at 4:10 AM, Jamie Mitchell <span dir="ltr"><<a href="mailto:jamiemitchell1604@gmail.com" target="_blank">jamiemitchell1604@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi folks,<br>
<br>
Instead of colouring the entire bar of a histogram i.e. filling it, I would like to colour just the outline of the histogram. Does anyone know how to do this?<br>
Version - Python2.7<br></blockquote><div><br></div><div class="gmail_default" style="color:rgb(0,0,0)">Look at the matplotlib.pyplot.hist function documentation: <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.hist">http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.hist</a></div>
<div class="gmail_default" style="color:rgb(0,0,0)"><br></div><div class="gmail_default" style="color:rgb(0,0,0)">In addition to the listed parameters, you'll see the "Other Parameters" taken are those that can be applied to the created Patch objects (which are the actual rectangles).  For the Patch keywords, see the API documentation on the Patch object (<a href="http://matplotlib.org/api/artist_api.html#matplotlib.patches.Patch">http://matplotlib.org/api/artist_api.html#matplotlib.patches.Patch</a>). So you can do one of two things:</div>
<div class="gmail_default" style="color:rgb(0,0,0)"><br></div><div class="gmail_default" style="color:rgb(0,0,0)">1) Pass the necessary Patch keywords to effect what you want</div><div class="gmail_default" style="color:rgb(0,0,0)">
<br></div><div class="gmail_default" style="color:rgb(0,0,0)">e.g. (untested):</div><div class="gmail_default" style="color:rgb(0,0,0)">import matplotlib.pyplot as plt</div><div class="gmail_default" style="color:rgb(0,0,0)">
<br></div><div class="gmail_default" style="color:rgb(0,0,0)">plt.hist(dataset, bins=10, range=(-5, 5), normed=True,</div><div class="gmail_default" style="color:rgb(0,0,0)">         edgecolor='b', linewidth=2, facecolor='none', # Patch options</div>
<div class="gmail_default" style="color:rgb(0,0,0)">)</div><div class="gmail_default" style="color:rgb(0,0,0)"><br></div><div class="gmail_default" style="color:rgb(0,0,0)">plt.show()</div><div class="gmail_default" style="color:rgb(0,0,0)">
<br></div><div class="gmail_default" style="color:rgb(0,0,0)">2) Iterate over the Patch instances returned by plt.hist() and set the properties you want.</div><div class="gmail_default" style="color:rgb(0,0,0)"><br></div>
<div class="gmail_default" style="color:rgb(0,0,0)">e.g. (untested):</div><div class="gmail_default" style="color:rgb(0,0,0)">import matplotlib.pyplot as plt</div><div class="gmail_default" style="color:rgb(0,0,0)"><br></div>
<div class="gmail_default" style="color:rgb(0,0,0)">n, bins, patches = plt.hist(dataset, bins=10, range=(-5, 5), normed=True)</div><div class="gmail_default" style="color:rgb(0,0,0)">for patch in patches:</div><div class="gmail_default" style="color:rgb(0,0,0)">
    patch.set_edgecolor('b') # color of the lines around each bin</div><div class="gmail_default" style="color:rgb(0,0,0)">    patch.set_linewidth(2) # Set width of bin edge</div><div class="gmail_default" style="color:rgb(0,0,0)">
    patch.set_facecolor('none') # set no fill</div><div class="gmail_default" style="color:rgb(0,0,0)">    # Anything else you want to do</div><div class="gmail_default" style="color:rgb(0,0,0)"><br></div><div class="gmail_default" style="color:rgb(0,0,0)">
plt.show()</div><div class="gmail_default" style="color:rgb(0,0,0)"><br></div><div class="gmail_default" style="color:rgb(0,0,0)">Approach (1) is the "easy" way, and is there to satisfy the majority of use cases.  However, approach (2) is _much_ more flexible.  Suppose you wanted to highlight a particular region of your data with a specific facecolor or edgecolor -- you can apply the features you want to individual patches using approach (2).  Or if you wanted to highlight a specific bin with thicker lines.</div>
<div class="gmail_default" style="color:rgb(0,0,0)"><br></div><div class="gmail_default" style="color:rgb(0,0,0)">This is a common theme in matplotlib -- you can use keywords to apply the same features to every part of a plot or you can iterate over the drawn objects and customize them individually.  This is a large part of what makes matplotlib nice to me -- it has a "simple" mode as well as a predictable API for customizing a plot in almost any way you could possibly want.</div>
<div class="gmail_default" style="color:rgb(0,0,0)"><br></div><div class="gmail_default" style="color:rgb(0,0,0)">HTH,</div><div class="gmail_default" style="color:rgb(0,0,0)">Jason</div><div class="gmail_default" style="color:rgb(0,0,0)">
<br></div></div>-- <br><div dir="ltr">Jason M. Swails<br>BioMaPS,<br>Rutgers University<br>Postdoctoral Researcher</div>
</div></div>