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: 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: References: Date: Fri, 20 Jun 2014 09:47:03 -0400 Subject: Re: Matplotlib Colouring outline of histogram From: Jason Swails To: Jamie Mitchell Content-Type: multipart/alternative; boundary=001a1133db9475c68504fc44ba31 Cc: python list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 --001a1133db9475c68504fc44ba31 Content-Type: text/plain; charset=UTF-8 On Fri, Jun 20, 2014 at 4:10 AM, Jamie Mitchell 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 --001a1133db9475c68504fc44ba31 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Fri, Jun 20, 2014 at 4:10 AM, Jamie Mitchell <<= a href=3D"mailto:jamiemitchell1604@gmail.com" target=3D"_blank">jamiemitche= ll1604@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:=C2=A0http://matplotlib.org/api/pyplot_api.html#matplotlib= .pyplot.hist

In addition to the listed pa= rameters, you'll see the "Other Parameters" taken are those t= hat can be applied to the created Patch objects (which are the actual recta= ngles). =C2=A0For the Patch keywords, see the API documentation on the Patc= h 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. (unt= ested):
import= matplotlib.pyplot as plt

plt.hist(= dataset, bins=3D10, range=3D(-5, 5), normed=3DTrue,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0edg= ecolor=3D'b', linewidth=3D2, facecolor=3D'none', # Patch op= tions
)

plt.show()

2) Iterat= e over the Patch instances returned by plt.hist() and set the properties yo= u want.

e.g. (untested):
import matplotli= b.pyplot as plt

n, bins, patches = =3D plt.hist(dataset, bins=3D10, range=3D(-5, 5), normed=3DTrue)
for patch in patches:
=C2=A0 =C2=A0 patch.set_edgecolor('b') # color of the lines around = each bin
=C2= =A0 =C2=A0 patch.set_linewidth(2) # Set width of bin edge
=C2=A0 =C2=A0 patch.set_facecolor('none') # set no fill
=C2=A0 =C2=A0 # Anything = else you want to do

plt.show()
Approach (1)= is the "easy" way, and is there to satisfy the majority of use c= ases. =C2=A0However, approach (2) is _much_ more flexible. =C2=A0Suppose yo= u wanted to highlight a particular region of your data with a specific face= color or edgecolor -- you can apply the features you want to individual pat= ches using approach (2). =C2=A0Or if you wanted to highlight a specific bin= with thicker lines.

This is a common theme in ma= tplotlib -- you can use keywords to apply the same features to every part o= f a plot or you can iterate over the drawn objects and customize them indiv= idually. =C2=A0This is a large part of what makes matplotlib nice to me -- = it has a "simple" mode as well as a predictable API for customizi= ng a plot in almost any way you could possibly want.

HTH,
Jason

--
Jason M. Swails
BioMaPS,
Rutg= ers University
Postdoctoral Researcher
--001a1133db9475c68504fc44ba31--