Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73457
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed0.kamp.net!newsfeed.kamp.net!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <jason.swails@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'suppose': 0.07; 'iterate': 0.09; 'lines.': 0.09; 'matplotlib': 0.09; 'satisfy': 0.09; 'width': 0.09; 'api': 0.11; 'cc:addr:python-list': 0.11; '5),': 0.16; 'cc:name:python list': 0.16; 'customizing': 0.16; 'folks,': 0.16; 'highlight': 0.16; 'parameters,': 0.16; 'patches': 0.16; 'url:patch': 0.16; 'url:patches': 0.16; 'wrote:': 0.18; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'this?': 0.23; 'cc:2**0': 0.24; 'options': 0.25; 'possibly': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'patch': 0.29; 'properties': 0.29; 'mode': 0.30; 'returned': 0.30; 'message-id:@mail.gmail.com': 0.30; '(which': 0.31; 'lines': 0.31; 'keywords,': 0.31; 'python2.7': 0.31; 'anyone': 0.31; 'fri,': 0.33; 'actual': 0.34; 'could': 0.34; 'common': 0.35; 'created': 0.35; '(2)': 0.35; 'objects': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'edge': 0.36; 'i.e.': 0.36; 'instances': 0.36; 'url:org': 0.36; 'two': 0.37; 'skip:& 10': 0.38; 'e.g.': 0.38; 'jason': 0.38; 'anything': 0.39; 'does': 0.39; 'skip:p 20': 0.39; 'university': 0.39; 'how': 0.40; 'skip:\xc2 10': 0.60; 'color': 0.61; 'entire': 0.61; "you'll": 0.62; 'skip:n 10': 0.64; 'more': 0.64; 'to:addr:gmail.com': 0.65; '20,': 0.68; 'filling': 0.78; 'colour': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Q4w2ZM5p5c2CvZC2Z2nhPyDfStBdJ+p+71+tjlNhxjI=; b=Tq+aBrcVEOB+dHS+dKm58veHyAQbyTl4DoVCuu4D1ciIBtoEmTwo19mP0r8+QKhu2V 9h3IIGye4ooIG896tQ92pSSDY2kJ0FjOIdxyf4LjaDoFhxBMenJfUvoIg0Vir3jDgF80 nqiyV7THoMlYJPiwOSECHqpLwDTxgxMsliZgli/4J02k0XRnXYVagkofHeTwoUtJZz1P uoMwyJVGkqDYlb7UkwEkkRZCF4zpl2+vWshoXBoDAiaHLbAYIDeGnlMx9/0zxQWcxL0f DHjEndNaSC6eF2IXw/kAs/h4W9E9zUnT0OYthjT83YCO98PvC4bxVTLQAqGDiHFMDxwC AVYA== |
| MIME-Version | 1.0 |
| X-Received | by 10.236.1.36 with SMTP id 24mr5465957yhc.45.1403272023085; Fri, 20 Jun 2014 06:47:03 -0700 (PDT) |
| In-Reply-To | <ae0491e6-70de-4cc3-aea4-8922f72e17b8@googlegroups.com> |
| References | <ae0491e6-70de-4cc3-aea4-8922f72e17b8@googlegroups.com> |
| Date | Fri, 20 Jun 2014 09:47:03 -0400 |
| Subject | Re: Matplotlib Colouring outline of histogram |
| From | Jason Swails <jason.swails@gmail.com> |
| To | Jamie Mitchell <jamiemitchell1604@gmail.com> |
| Content-Type | multipart/alternative; boundary=001a1133db9475c68504fc44ba31 |
| Cc | python list <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.11167.1403272031.18130.python-list@python.org> (permalink) |
| Lines | 162 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1403272031 news.xs4all.nl 2911 [2001:888:2000:d::a6]:50746 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:73457 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
On Fri, Jun 20, 2014 at 4:10 AM, Jamie Mitchell <jamiemitchell1604@gmail.com
> wrote:
> Hi folks,
>
> 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?
> Version - Python2.7
>
Look at the matplotlib.pyplot.hist function documentation:
http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.hist
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 (
http://matplotlib.org/api/artist_api.html#matplotlib.patches.Patch). So you
can do one of two things:
1) Pass the necessary Patch keywords to effect what you want
e.g. (untested):
import matplotlib.pyplot as plt
plt.hist(dataset, bins=10, range=(-5, 5), normed=True,
edgecolor='b', linewidth=2, facecolor='none', # Patch options
)
plt.show()
2) Iterate over the Patch instances returned by plt.hist() and set the
properties you want.
e.g. (untested):
import matplotlib.pyplot as plt
n, bins, patches = plt.hist(dataset, bins=10, range=(-5, 5), normed=True)
for patch in patches:
patch.set_edgecolor('b') # color of the lines around each bin
patch.set_linewidth(2) # Set width of bin edge
patch.set_facecolor('none') # set no fill
# Anything else you want to do
plt.show()
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.
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.
HTH,
Jason
--
Jason M. Swails
BioMaPS,
Rutgers University
Postdoctoral Researcher
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Matplotlib Colouring outline of histogram Jamie Mitchell <jamiemitchell1604@gmail.com> - 2014-06-20 01:10 -0700
Re: Matplotlib Colouring outline of histogram Jason Swails <jason.swails@gmail.com> - 2014-06-20 09:47 -0400
Re: Matplotlib Colouring outline of histogram Jamie Mitchell <jamiemitchell1604@gmail.com> - 2014-06-20 07:27 -0700
Re: Matplotlib Colouring outline of histogram Jason Swails <jason.swails@gmail.com> - 2014-06-20 10:52 -0400
Re: Matplotlib Colouring outline of histogram Jamie Mitchell <jamiemitchell1604@gmail.com> - 2014-06-20 08:10 -0700
csiph-web