SourceForge logo
SourceForge logo
Menu

matplotlib-users — Discussion related to using matplotlib

You can subscribe to this list here.

2003 Jan
Feb
Mar
Apr
May
(3)
Jun
Jul
Aug
(12)
Sep
(12)
Oct
(56)
Nov
(65)
Dec
(37)
2004 Jan
(59)
Feb
(78)
Mar
(153)
Apr
(205)
May
(184)
Jun
(123)
Jul
(171)
Aug
(156)
Sep
(190)
Oct
(120)
Nov
(154)
Dec
(223)
2005 Jan
(184)
Feb
(267)
Mar
(214)
Apr
(286)
May
(320)
Jun
(299)
Jul
(348)
Aug
(283)
Sep
(355)
Oct
(293)
Nov
(232)
Dec
(203)
2006 Jan
(352)
Feb
(358)
Mar
(403)
Apr
(313)
May
(165)
Jun
(281)
Jul
(316)
Aug
(228)
Sep
(279)
Oct
(243)
Nov
(315)
Dec
(345)
2007 Jan
(260)
Feb
(323)
Mar
(340)
Apr
(319)
May
(290)
Jun
(296)
Jul
(221)
Aug
(292)
Sep
(242)
Oct
(248)
Nov
(242)
Dec
(332)
2008 Jan
(312)
Feb
(359)
Mar
(454)
Apr
(287)
May
(340)
Jun
(450)
Jul
(403)
Aug
(324)
Sep
(349)
Oct
(385)
Nov
(363)
Dec
(437)
2009 Jan
(500)
Feb
(301)
Mar
(409)
Apr
(486)
May
(545)
Jun
(391)
Jul
(518)
Aug
(497)
Sep
(492)
Oct
(429)
Nov
(357)
Dec
(310)
2010 Jan
(371)
Feb
(657)
Mar
(519)
Apr
(432)
May
(312)
Jun
(416)
Jul
(477)
Aug
(386)
Sep
(419)
Oct
(435)
Nov
(320)
Dec
(202)
2011 Jan
(321)
Feb
(413)
Mar
(299)
Apr
(215)
May
(284)
Jun
(203)
Jul
(207)
Aug
(314)
Sep
(321)
Oct
(259)
Nov
(347)
Dec
(209)
2012 Jan
(322)
Feb
(414)
Mar
(377)
Apr
(179)
May
(173)
Jun
(234)
Jul
(295)
Aug
(239)
Sep
(276)
Oct
(355)
Nov
(144)
Dec
(108)
2013 Jan
(170)
Feb
(89)
Mar
(204)
Apr
(133)
May
(142)
Jun
(89)
Jul
(160)
Aug
(180)
Sep
(69)
Oct
(136)
Nov
(83)
Dec
(32)
2014 Jan
(71)
Feb
(90)
Mar
(161)
Apr
(117)
May
(78)
Jun
(94)
Jul
(60)
Aug
(83)
Sep
(102)
Oct
(132)
Nov
(154)
Dec
(96)
2015 Jan
(45)
Feb
(138)
Mar
(176)
Apr
(132)
May
(119)
Jun
(124)
Jul
(77)
Aug
(31)
Sep
(34)
Oct
(22)
Nov
(23)
Dec
(9)
2016 Jan
(26)
Feb
(17)
Mar
(10)
Apr
(8)
May
(4)
Jun
(8)
Jul
(6)
Aug
(5)
Sep
(9)
Oct
(4)
Nov
Dec
2017 Jan
(5)
Feb
(7)
Mar
(1)
Apr
(5)
May
Jun
(3)
Jul
(6)
Aug
(1)
Sep
Oct
(2)
Nov
(1)
Dec
2018 Jan
Feb
Mar
Apr
(1)
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2020 Jan
Feb
Mar
Apr
May
(1)
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2025 Jan
(1)
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
S M T W T F S
1
2
(6)
3
(5)
4
(5)
5
6
7
8
(2)
9
10
(1)
11
(4)
12
(1)
13
14
(2)
15
(1)
16
(3)
17
(5)
18
19
(7)
20
(1)
21
(1)
22
23
(2)
24
(4)
25
(5)
26
(3)
27
28
(3)
29
(3)
30
(5)





Showing 6 results of 6

From: Alex G. <ale...@co...> - 2013年09月02日 20:33:34
Actually, sorry for the triple post, but is there a reason why we can't do
something like pass in the keyword arguments directly from the call to
contourf when instantiating each collection? Then the keyword arguments for
contourf (and ContourSet) could be used for the collections directly,
including clip_path. I know a similar approach is taken for the keyword
arguments in plot, since those can be used to modify the properties of each
Line2D instance.
Thanks,
Alex
On Mon, Sep 2, 2013 at 1:09 PM, Alex Goodman <ale...@co...>wrote:
> Actually, it seems I have partially answered my own question. Since I am
> calling axis('off'), I do not notice the effect of clipping the other
> artists since I made a call to axis('off'). Without it the spines and axes
> rectangle are still removed but the ticks are still visible. I suppose this
> is fine for my own purposes of contouring within one country on a map since
> I would want to use something like axis('off') anyway, but then it would
> not work if I wanted to use the axes background. Another approach I have
> tried is to use the clip_path keyword in the plotting functions themselves,
> which works for imshow and pcolor, but not contourf. Any other ideas?
>
> Alex
>
>
> On Mon, Sep 2, 2013 at 12:18 PM, Alex Goodman <ale...@co...>wrote:
>
>> Hi Phil,
>>
>> Thanks, that is more or less what I was looking for. However, I still
>> think that generalizing this approach for other types of plotting functions
>> that don't return artists directly would be useful. Your solution gave me
>> another idea for doing this, which would be to iterate through all of the
>> child artists on the axes using the get_children() method and then calling
>> set_clip_path() on each artist. This would make the methodology very
>> general but I am not sure if there are any negative side effects to
>> resetting the clip path on the other artists besides the PatchCollections.
>> I modified my simple example script and it seems to work well for
>> contourf(), pcolor(), and imshow():
>>
>> import numpy as np
>> import matplotlib.pyplot as plt
>> from matplotlib.patches import RegularPolygon
>>
>> data = np.arange(100).reshape(10, 10)
>> fig = plt.figure()
>> ax = fig.add_subplot(111)
>> ax.contourf(data)
>> poly = RegularPolygon([ 0.5, 0.5], 6, 0.4, fc='none',
>> ec='k', transform=ax.transAxes)
>> for artist in ax.get_children():
>> artist.set_clip_path(poly)
>>
>> ax.add_patch(poly)
>> ax.set_aspect('equal')
>> ax.axis('off')
>> plt.show()
>>
>>
>> Also, I appreciated the cartopy example. I think it has the potential to
>> be a good basemap replacement thanks to the more robust shapefile support
>> (which you have very elegantly shown), and I hope the development goes well.
>>
>> Thanks,
>> Alex
>>
>>
>> On Mon, Sep 2, 2013 at 2:33 AM, Phil Elson <pel...@gm...> wrote:
>>
>>> Great question. The contour set itself does not have a set_clip_path
>>> method but you can iterate over each of the contour collections and set
>>> their respective clip paths, i.e.:
>>>
>>> cs = plt.contourf(data)
>>> for collection in cs.collections:
>>> collection.set_clip_path(poly)
>>>
>>> Of course, you can use this approach in either Basemap or cartopy, but
>>> I've put together an example of doing it in cartopy to demonstrate the neat
>>> Shapely integration: http://nbviewer.ipython.org/6410510
>>>
>>> HTH,
>>>
>>> Phil
>>>
>>>
>>> On 2 September 2013 05:40, Alex Goodman <ale...@co...>wrote:
>>>
>>>> Hi all,
>>>>
>>>> I want to be able to plot data on maps (using basemap or cartopy)
>>>> inside specific regions, eg a single state, province or country. A similar
>>>> question was asked a long time ago on the mailing list and the suggested
>>>> solution back then was to read the bounding polygon from a shapefile and
>>>> then check if each individual point was inside that polygon. Currently I
>>>> have no problem doing this if I use matplotlib.path.Path.contains_points()
>>>> to mask the original data array, but the disadvantage to this solution is
>>>> that it is very slow. Another solution that I have discovered recently is
>>>> to use the set_clip_path() method for artists. In addition to being much
>>>> faster, this also makes the areas near the polygon boundary look much
>>>> smoother since the actual items being clipped are individual pixels and not
>>>> data points.
>>>>
>>>> Here is an example script that plots an image via imshow, but the only
>>>> part of the image that gets shown is inside the hexagon.
>>>>
>>>> import numpy as np
>>>> import matplotlib.pyplot as plt
>>>> from matplotlib.patches import RegularPolygon
>>>>
>>>> data = np.arange(100).reshape(10, 10)
>>>> fig = plt.figure()
>>>> ax = fig.add_subplot(111)
>>>> im = ax.imshow(data)
>>>> poly = RegularPolygon([ 0.5, 0.5], 6, 0.4, fc='none',
>>>> ec='k', transform=ax.transAxes)
>>>> im.set_clip_path(poly)
>>>> ax.add_patch(poly)
>>>> ax.axis('off')
>>>> plt.show()
>>>>
>>>> While this does seem like an ideal solution, it doesn't work for every
>>>> type of plot. The most notable example is contourf(). It returns a
>>>> QuadContourSet instance which does not inherit from Artist, so it does not
>>>> contain the set_clip_path() method. My main question is whether there is a
>>>> mechanism in matplotlib that can convert something like a QuadContourSet
>>>> into an image so I can make use of this solution for contourf() as well. Or
>>>> better yet, is there perhaps another artist within the axes that I can use
>>>> the set_clip_path() method for and still get what I want?
>>>>
>>>> Thanks,
>>>> Alex
>>>> --
>>>> Alex Goodman
>>>> Graduate Research Assistant
>>>> Department of Atmospheric Science
>>>> Colorado State University
>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
>>>> Discover the easy way to master current and previous Microsoft
>>>> technologies
>>>> and advance your career. Get an incredible 1,500+ hours of step-by-step
>>>> tutorial videos with LearnDevNow. Subscribe today and save!
>>>>
>>>> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
>>>> _______________________________________________
>>>> Matplotlib-users mailing list
>>>> Mat...@li...
>>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>>>
>>>>
>>>
>>
>>
>> --
>> Alex Goodman
>> Graduate Research Assistant
>> Department of Atmospheric Science
>> Colorado State University
>>
>
>
>
> --
> Alex Goodman
> Graduate Research Assistant
> Department of Atmospheric Science
> Colorado State University
>
-- 
Alex Goodman
Graduate Research Assistant
Department of Atmospheric Science
Colorado State University
From: Alex G. <ale...@co...> - 2013年09月02日 19:09:18
Actually, it seems I have partially answered my own question. Since I am
calling axis('off'), I do not notice the effect of clipping the other
artists since I made a call to axis('off'). Without it the spines and axes
rectangle are still removed but the ticks are still visible. I suppose this
is fine for my own purposes of contouring within one country on a map since
I would want to use something like axis('off') anyway, but then it would
not work if I wanted to use the axes background. Another approach I have
tried is to use the clip_path keyword in the plotting functions themselves,
which works for imshow and pcolor, but not contourf. Any other ideas?
Alex
On Mon, Sep 2, 2013 at 12:18 PM, Alex Goodman <ale...@co...>wrote:
> Hi Phil,
>
> Thanks, that is more or less what I was looking for. However, I still
> think that generalizing this approach for other types of plotting functions
> that don't return artists directly would be useful. Your solution gave me
> another idea for doing this, which would be to iterate through all of the
> child artists on the axes using the get_children() method and then calling
> set_clip_path() on each artist. This would make the methodology very
> general but I am not sure if there are any negative side effects to
> resetting the clip path on the other artists besides the PatchCollections.
> I modified my simple example script and it seems to work well for
> contourf(), pcolor(), and imshow():
>
> import numpy as np
> import matplotlib.pyplot as plt
> from matplotlib.patches import RegularPolygon
>
> data = np.arange(100).reshape(10, 10)
> fig = plt.figure()
> ax = fig.add_subplot(111)
> ax.contourf(data)
> poly = RegularPolygon([ 0.5, 0.5], 6, 0.4, fc='none',
> ec='k', transform=ax.transAxes)
> for artist in ax.get_children():
> artist.set_clip_path(poly)
>
> ax.add_patch(poly)
> ax.set_aspect('equal')
> ax.axis('off')
> plt.show()
>
>
> Also, I appreciated the cartopy example. I think it has the potential to
> be a good basemap replacement thanks to the more robust shapefile support
> (which you have very elegantly shown), and I hope the development goes well.
>
> Thanks,
> Alex
>
>
> On Mon, Sep 2, 2013 at 2:33 AM, Phil Elson <pel...@gm...> wrote:
>
>> Great question. The contour set itself does not have a set_clip_path
>> method but you can iterate over each of the contour collections and set
>> their respective clip paths, i.e.:
>>
>> cs = plt.contourf(data)
>> for collection in cs.collections:
>> collection.set_clip_path(poly)
>>
>> Of course, you can use this approach in either Basemap or cartopy, but
>> I've put together an example of doing it in cartopy to demonstrate the neat
>> Shapely integration: http://nbviewer.ipython.org/6410510
>>
>> HTH,
>>
>> Phil
>>
>>
>> On 2 September 2013 05:40, Alex Goodman <ale...@co...>wrote:
>>
>>> Hi all,
>>>
>>> I want to be able to plot data on maps (using basemap or cartopy) inside
>>> specific regions, eg a single state, province or country. A similar
>>> question was asked a long time ago on the mailing list and the suggested
>>> solution back then was to read the bounding polygon from a shapefile and
>>> then check if each individual point was inside that polygon. Currently I
>>> have no problem doing this if I use matplotlib.path.Path.contains_points()
>>> to mask the original data array, but the disadvantage to this solution is
>>> that it is very slow. Another solution that I have discovered recently is
>>> to use the set_clip_path() method for artists. In addition to being much
>>> faster, this also makes the areas near the polygon boundary look much
>>> smoother since the actual items being clipped are individual pixels and not
>>> data points.
>>>
>>> Here is an example script that plots an image via imshow, but the only
>>> part of the image that gets shown is inside the hexagon.
>>>
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from matplotlib.patches import RegularPolygon
>>>
>>> data = np.arange(100).reshape(10, 10)
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> im = ax.imshow(data)
>>> poly = RegularPolygon([ 0.5, 0.5], 6, 0.4, fc='none',
>>> ec='k', transform=ax.transAxes)
>>> im.set_clip_path(poly)
>>> ax.add_patch(poly)
>>> ax.axis('off')
>>> plt.show()
>>>
>>> While this does seem like an ideal solution, it doesn't work for every
>>> type of plot. The most notable example is contourf(). It returns a
>>> QuadContourSet instance which does not inherit from Artist, so it does not
>>> contain the set_clip_path() method. My main question is whether there is a
>>> mechanism in matplotlib that can convert something like a QuadContourSet
>>> into an image so I can make use of this solution for contourf() as well. Or
>>> better yet, is there perhaps another artist within the axes that I can use
>>> the set_clip_path() method for and still get what I want?
>>>
>>> Thanks,
>>> Alex
>>> --
>>> Alex Goodman
>>> Graduate Research Assistant
>>> Department of Atmospheric Science
>>> Colorado State University
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
>>> Discover the easy way to master current and previous Microsoft
>>> technologies
>>> and advance your career. Get an incredible 1,500+ hours of step-by-step
>>> tutorial videos with LearnDevNow. Subscribe today and save!
>>>
>>> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
>>> _______________________________________________
>>> Matplotlib-users mailing list
>>> Mat...@li...
>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>>
>>>
>>
>
>
> --
> Alex Goodman
> Graduate Research Assistant
> Department of Atmospheric Science
> Colorado State University
>
-- 
Alex Goodman
Graduate Research Assistant
Department of Atmospheric Science
Colorado State University
From: Alex G. <ale...@co...> - 2013年09月02日 18:19:06
Hi Phil,
Thanks, that is more or less what I was looking for. However, I still think
that generalizing this approach for other types of plotting functions that
don't return artists directly would be useful. Your solution gave me
another idea for doing this, which would be to iterate through all of the
child artists on the axes using the get_children() method and then calling
set_clip_path() on each artist. This would make the methodology very
general but I am not sure if there are any negative side effects to
resetting the clip path on the other artists besides the PatchCollections.
I modified my simple example script and it seems to work well for
contourf(), pcolor(), and imshow():
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import RegularPolygon
data = np.arange(100).reshape(10, 10)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.contourf(data)
poly = RegularPolygon([ 0.5, 0.5], 6, 0.4, fc='none',
ec='k', transform=ax.transAxes)
for artist in ax.get_children():
 artist.set_clip_path(poly)
ax.add_patch(poly)
ax.set_aspect('equal')
ax.axis('off')
plt.show()
Also, I appreciated the cartopy example. I think it has the potential to be
a good basemap replacement thanks to the more robust shapefile support
(which you have very elegantly shown), and I hope the development goes well.
Thanks,
Alex
On Mon, Sep 2, 2013 at 2:33 AM, Phil Elson <pel...@gm...> wrote:
> Great question. The contour set itself does not have a set_clip_path
> method but you can iterate over each of the contour collections and set
> their respective clip paths, i.e.:
>
> cs = plt.contourf(data)
> for collection in cs.collections:
> collection.set_clip_path(poly)
>
> Of course, you can use this approach in either Basemap or cartopy, but
> I've put together an example of doing it in cartopy to demonstrate the neat
> Shapely integration: http://nbviewer.ipython.org/6410510
>
> HTH,
>
> Phil
>
>
> On 2 September 2013 05:40, Alex Goodman <ale...@co...>wrote:
>
>> Hi all,
>>
>> I want to be able to plot data on maps (using basemap or cartopy) inside
>> specific regions, eg a single state, province or country. A similar
>> question was asked a long time ago on the mailing list and the suggested
>> solution back then was to read the bounding polygon from a shapefile and
>> then check if each individual point was inside that polygon. Currently I
>> have no problem doing this if I use matplotlib.path.Path.contains_points()
>> to mask the original data array, but the disadvantage to this solution is
>> that it is very slow. Another solution that I have discovered recently is
>> to use the set_clip_path() method for artists. In addition to being much
>> faster, this also makes the areas near the polygon boundary look much
>> smoother since the actual items being clipped are individual pixels and not
>> data points.
>>
>> Here is an example script that plots an image via imshow, but the only
>> part of the image that gets shown is inside the hexagon.
>>
>> import numpy as np
>> import matplotlib.pyplot as plt
>> from matplotlib.patches import RegularPolygon
>>
>> data = np.arange(100).reshape(10, 10)
>> fig = plt.figure()
>> ax = fig.add_subplot(111)
>> im = ax.imshow(data)
>> poly = RegularPolygon([ 0.5, 0.5], 6, 0.4, fc='none',
>> ec='k', transform=ax.transAxes)
>> im.set_clip_path(poly)
>> ax.add_patch(poly)
>> ax.axis('off')
>> plt.show()
>>
>> While this does seem like an ideal solution, it doesn't work for every
>> type of plot. The most notable example is contourf(). It returns a
>> QuadContourSet instance which does not inherit from Artist, so it does not
>> contain the set_clip_path() method. My main question is whether there is a
>> mechanism in matplotlib that can convert something like a QuadContourSet
>> into an image so I can make use of this solution for contourf() as well. Or
>> better yet, is there perhaps another artist within the axes that I can use
>> the set_clip_path() method for and still get what I want?
>>
>> Thanks,
>> Alex
>> --
>> Alex Goodman
>> Graduate Research Assistant
>> Department of Atmospheric Science
>> Colorado State University
>>
>>
>> ------------------------------------------------------------------------------
>> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
>> Discover the easy way to master current and previous Microsoft
>> technologies
>> and advance your career. Get an incredible 1,500+ hours of step-by-step
>> tutorial videos with LearnDevNow. Subscribe today and save!
>>
>> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
>> _______________________________________________
>> Matplotlib-users mailing list
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
>
-- 
Alex Goodman
Graduate Research Assistant
Department of Atmospheric Science
Colorado State University
From: Andrew J. <a.h...@gm...> - 2013年09月02日 16:40:37
Dear all,
On 06/08/2013 16:36, Andrew Jaffe wrote:
>> On 08/02/2013 06:53 AM, Andrew Jaffe wrote:
>>>
>>> On 01/08/2013 19:06, Michael Droettboom wrote:
>>>> On behalf of a veritable army of super coders, I'm pleased to announce the release of matplotlib 1.3.0.
>>> Two issues on OSX 10.8.4. I had been previously using the dmg installer.
>>> Lacking that, I tried easy-install and pip install, both of which gave me the following problems:
>>>
>>> - I needed to set CC=clang
>>> - When attempting to load matplotlib, I got the following error:
>>>
>>> /Volumes/Data/Users/jaffe/Library/Python/2.7/lib/python/site-packages/matplotlib/font_manager.py
>>>
>>> in <module>()
>>> ---> 53 from matplotlib import ft2font
>>>
>>> ImportError: dlopen(/Volumes/Data/Users/jaffe/Library/Python/2.7/lib/python/site-packages/matplotlib/ft2font.so,
>>>
>>> 2): Symbol not found: _FT_Attach_File
>>> Referenced from:
>>> /Volumes/Data/Users/jaffe/Library/Python/2.7/lib/python/site-packages/matplotlib/ft2font.so
>>>
>>> Expected in: flat namespace in
>>> /Volumes/Data/Users/jaffe/Library/Python/2.7/lib/python/site-packages/matplotlib/ft2font.so
>>>
>>> This is a freetype problem, probably an incompatible version somewhere. Ideas?
Some self-followup:
I was able to get the build to compile and install and pass most of the 
tests with the following change to the basedir_map dict (currently line 
147) in setupext.py:
 'darwin': ['/opt/X11', '/usr/local/', '/usr', '/opt/local'],
i.e. /opt/X11 in the front. I assume this accounts for my XQuartz X11 
install. I think both of those changes (i.e., usr->opt and moving to the 
front of the path) are necessary.
With this setup, I get lots of knownfails and a few real 
"ImageComparisonFailure" ones -- see below for the output. In all three 
cases, examining the images, it's clear that the system is not using 
styled fonts.
(I have no idea how these failures compare to my previous system with a 
dmg installation of matplotlib as I never ran the tests on it...)
Also, as mentioned previously, on one of my machines (but, strangely, 
not both) I also had to change CC and CXX to force use of clang (i.e., 
one worked with standard gcc). The test failures are the same in both 
cases, although, for what it's worth, the on-screen font rendering does 
appear different on the two machines, no doubt owing to slightly 
different installation histories of the various non-apple installed unix 
and other libraries...
Yours,
Andrew
======================================================================
FAIL: matplotlib.tests.test_backend_pdf.test_use14corefonts.test
----------------------------------------------------------------------
Traceback (most recent call last):
 File 
"/Volumes/Data/Users/jaffe/Library/Python/2.7/lib/python/site-packages/nose/case.py", 
line 197, in runTest
 self.test(*self.arg)
 File 
"/Volumes/Data/Users/jaffe/Library/Python/2.7/lib/python/site-packages/matplotlib-1.3.0-py2.7-macosx-10.6-intel.egg/matplotlib/testing/decorators.py", 
line 40, in failer
 result = f(*args, **kwargs)
 File 
"/Volumes/Data/Users/jaffe/Library/Python/2.7/lib/python/site-packages/matplotlib-1.3.0-py2.7-macosx-10.6-intel.egg/matplotlib/testing/decorators.py", 
line 159, in do_test
 '(RMS %(rms).3f)'%err)
ImageComparisonFailure: images not close: 
/Volumes/Data/Users/jaffe/result_images/test_backend_pdf/pdf_use14corefonts_pdf.png 
vs. 
/Volumes/Data/Users/jaffe/result_images/test_backend_pdf/pdf_use14corefonts-expected_pdf.png 
(RMS 57.518)
======================================================================
FAIL: matplotlib.tests.test_text.test_font_styles.test
----------------------------------------------------------------------
Traceback (most recent call last):
 File 
"/Volumes/Data/Users/jaffe/Library/Python/2.7/lib/python/site-packages/nose/case.py", 
line 197, in runTest
 self.test(*self.arg)
 File 
"/Volumes/Data/Users/jaffe/Library/Python/2.7/lib/python/site-packages/matplotlib-1.3.0-py2.7-macosx-10.6-intel.egg/matplotlib/testing/decorators.py", 
line 40, in failer
 result = f(*args, **kwargs)
 File 
"/Volumes/Data/Users/jaffe/Library/Python/2.7/lib/python/site-packages/matplotlib-1.3.0-py2.7-macosx-10.6-intel.egg/matplotlib/testing/decorators.py", 
line 159, in do_test
 '(RMS %(rms).3f)'%err)
ImageComparisonFailure: images not close: 
/Volumes/Data/Users/jaffe/result_images/test_text/font_styles.png vs. 
/Volumes/Data/Users/jaffe/result_images/test_text/font_styles-expected.png 
(RMS 13.676)
======================================================================
FAIL: matplotlib.tests.test_text.test_font_styles.test
----------------------------------------------------------------------
Traceback (most recent call last):
 File 
"/Volumes/Data/Users/jaffe/Library/Python/2.7/lib/python/site-packages/nose/case.py", 
line 197, in runTest
 self.test(*self.arg)
 File 
"/Volumes/Data/Users/jaffe/Library/Python/2.7/lib/python/site-packages/matplotlib-1.3.0-py2.7-macosx-10.6-intel.egg/matplotlib/testing/decorators.py", 
line 40, in failer
 result = f(*args, **kwargs)
 File 
"/Volumes/Data/Users/jaffe/Library/Python/2.7/lib/python/site-packages/matplotlib-1.3.0-py2.7-macosx-10.6-intel.egg/matplotlib/testing/decorators.py", 
line 159, in do_test
 '(RMS %(rms).3f)'%err)
ImageComparisonFailure: images not close: 
/Volumes/Data/Users/jaffe/result_images/test_text/font_styles_pdf.png 
vs. 
/Volumes/Data/Users/jaffe/result_images/test_text/font_styles-expected_pdf.png 
(RMS 14.120)
----------------------------------------------------------------------
Ran 1458 tests in 620.025s
FAILED (KNOWNFAIL=350, failures=3)
From: Phil E. <pel...@gm...> - 2013年09月02日 08:33:37
Great question. The contour set itself does not have a set_clip_path method
but you can iterate over each of the contour collections and set their
respective clip paths, i.e.:
cs = plt.contourf(data)
for collection in cs.collections:
 collection.set_clip_path(poly)
Of course, you can use this approach in either Basemap or cartopy, but I've
put together an example of doing it in cartopy to demonstrate the neat
Shapely integration: http://nbviewer.ipython.org/6410510
HTH,
Phil
On 2 September 2013 05:40, Alex Goodman <ale...@co...> wrote:
> Hi all,
>
> I want to be able to plot data on maps (using basemap or cartopy) inside
> specific regions, eg a single state, province or country. A similar
> question was asked a long time ago on the mailing list and the suggested
> solution back then was to read the bounding polygon from a shapefile and
> then check if each individual point was inside that polygon. Currently I
> have no problem doing this if I use matplotlib.path.Path.contains_points()
> to mask the original data array, but the disadvantage to this solution is
> that it is very slow. Another solution that I have discovered recently is
> to use the set_clip_path() method for artists. In addition to being much
> faster, this also makes the areas near the polygon boundary look much
> smoother since the actual items being clipped are individual pixels and not
> data points.
>
> Here is an example script that plots an image via imshow, but the only
> part of the image that gets shown is inside the hexagon.
>
> import numpy as np
> import matplotlib.pyplot as plt
> from matplotlib.patches import RegularPolygon
>
> data = np.arange(100).reshape(10, 10)
> fig = plt.figure()
> ax = fig.add_subplot(111)
> im = ax.imshow(data)
> poly = RegularPolygon([ 0.5, 0.5], 6, 0.4, fc='none',
> ec='k', transform=ax.transAxes)
> im.set_clip_path(poly)
> ax.add_patch(poly)
> ax.axis('off')
> plt.show()
>
> While this does seem like an ideal solution, it doesn't work for every
> type of plot. The most notable example is contourf(). It returns a
> QuadContourSet instance which does not inherit from Artist, so it does not
> contain the set_clip_path() method. My main question is whether there is a
> mechanism in matplotlib that can convert something like a QuadContourSet
> into an image so I can make use of this solution for contourf() as well. Or
> better yet, is there perhaps another artist within the axes that I can use
> the set_clip_path() method for and still get what I want?
>
> Thanks,
> Alex
> --
> Alex Goodman
> Graduate Research Assistant
> Department of Atmospheric Science
> Colorado State University
>
>
> ------------------------------------------------------------------------------
> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
> Discover the easy way to master current and previous Microsoft technologies
> and advance your career. Get an incredible 1,500+ hours of step-by-step
> tutorial videos with LearnDevNow. Subscribe today and save!
> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
From: Alex G. <ale...@co...> - 2013年09月02日 04:40:39
Attachments: clip_example.png
Hi all,
I want to be able to plot data on maps (using basemap or cartopy) inside
specific regions, eg a single state, province or country. A similar
question was asked a long time ago on the mailing list and the suggested
solution back then was to read the bounding polygon from a shapefile and
then check if each individual point was inside that polygon. Currently I
have no problem doing this if I use matplotlib.path.Path.contains_points()
to mask the original data array, but the disadvantage to this solution is
that it is very slow. Another solution that I have discovered recently is
to use the set_clip_path() method for artists. In addition to being much
faster, this also makes the areas near the polygon boundary look much
smoother since the actual items being clipped are individual pixels and not
data points.
Here is an example script that plots an image via imshow, but the only part
of the image that gets shown is inside the hexagon.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import RegularPolygon
data = np.arange(100).reshape(10, 10)
fig = plt.figure()
ax = fig.add_subplot(111)
im = ax.imshow(data)
poly = RegularPolygon([ 0.5, 0.5], 6, 0.4, fc='none',
 ec='k', transform=ax.transAxes)
im.set_clip_path(poly)
ax.add_patch(poly)
ax.axis('off')
plt.show()
While this does seem like an ideal solution, it doesn't work for every type
of plot. The most notable example is contourf(). It returns a
QuadContourSet instance which does not inherit from Artist, so it does not
contain the set_clip_path() method. My main question is whether there is a
mechanism in matplotlib that can convert something like a QuadContourSet
into an image so I can make use of this solution for contourf() as well. Or
better yet, is there perhaps another artist within the axes that I can use
the set_clip_path() method for and still get what I want?
Thanks,
Alex
-- 
Alex Goodman
Graduate Research Assistant
Department of Atmospheric Science
Colorado State University

Showing 6 results of 6

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /