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
(2)
3
(16)
4
(22)
5
(7)
6
7
(9)
8
(2)
9
10
(7)
11
(15)
12
(7)
13
(4)
14
(7)
15
(3)
16
(6)
17
(20)
18
(18)
19
(15)
20
(27)
21
(14)
22
23
(1)
24
(18)
25
(22)
26
(36)
27
(17)
28
(6)
29
(2)
30
(3)
31
(6)





Showing 7 results of 7

From: Jeff W. <js...@fa...> - 2010年05月10日 20:57:59
On 5/10/10 2:21 PM, Michael Hearne wrote:
> I have found a (possible) bug in Basemap - when using basemap.fillcontinents(), I see the chosen continent color only when the map I create includes some ocean. If I am in the interior of a continent (I've tested with North America and Asia), the continent color is white.
> 
Michael: If there are no continent boundaries inside the map projection 
region, basemap does not draw anything (hence you see the axis 
background color). In that case, you should just set the axis 
background color to whatever you wanted the continent color to be.
-Jeff
> A code sample is below. My version information:
> Basemap: 0.99.4
> Matplotlib: 0.99.1.1
> numpy: 1.4.0
> Python: 2.6.4
>
> To replicate my results, please try the following:
> ./maptest.py 37.894507 -121.816406 #map center is somewhere in the Bay Area in California
> ./maptest.py 41.880332 -100.47821 #map center is somewhere in Nebraska
>
> The script creates a file called "output.png" in the calling directory. In the California case, I see the ocean as blue, and the land as a sort of annoying salmon color. In the Nebraska case, I see white with blue denoting the various rivers and lakes in the area.
>
> Am I mis-using the basemap method calls in some way?
>
> Thanks,
>
> Mike
>
> --------------------------------------------------------------------
> #!/usr/bin/env python
>
> import matplotlib
> #use the non-interactive matplotlib setting
> matplotlib.use('agg')
> from mpl_toolkits.basemap import Basemap
> import numpy as np
> from pylab import *
> import sys
>
> clat = float(sys.argv[1])
> clon = float(sys.argv[2])
>
> figwidth = 5.4
>
>
> bounds = (clon-4, clon+4, clat-4, clat+4)
> dx = (bounds[1] - bounds[0])*111191 * np.cos(clat * np.pi/180)
> dy = (bounds[3] - bounds[2])*111191
> aspect = dy/dx
> figheight = aspect * figwidth
>
> fig = figure(figsize=(figwidth,figheight),edgecolor='g',facecolor='g')
> ax1 = fig.add_axes([0,0,1.0,1.0])
> mapcontour = Basemap(llcrnrlon=bounds[0],llcrnrlat=bounds[2],
> urcrnrlon=bounds[1],urcrnrlat=bounds[3],
> resolution='h',projection='merc',lat_ts=clat)
> water_color = [.47,.60,.81]
> mapcontour.drawrivers(color=water_color)
> mapcontour.drawcountries(color='k',linewidth=2.0)
> mapcontour.drawcoastlines()
> mapcontour.fillcontinents(color=[1.0,0.8,0.8],lake_color=water_color)
>
> plt.savefig('output.png')
> --------------------------------------------------------------------
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
From: Michael H. <mh...@us...> - 2010年05月10日 20:21:41
I have found a (possible) bug in Basemap - when using basemap.fillcontinents(), I see the chosen continent color only when the map I create includes some ocean. If I am in the interior of a continent (I've tested with North America and Asia), the continent color is white.
A code sample is below. My version information:
Basemap: 0.99.4
Matplotlib: 0.99.1.1
numpy: 1.4.0
Python: 2.6.4
To replicate my results, please try the following:
./maptest.py 37.894507 -121.816406 #map center is somewhere in the Bay Area in California
./maptest.py 41.880332 -100.47821 #map center is somewhere in Nebraska
The script creates a file called "output.png" in the calling directory. In the California case, I see the ocean as blue, and the land as a sort of annoying salmon color. In the Nebraska case, I see white with blue denoting the various rivers and lakes in the area.
Am I mis-using the basemap method calls in some way?
Thanks,
Mike
--------------------------------------------------------------------
#!/usr/bin/env python
import matplotlib
#use the non-interactive matplotlib setting
matplotlib.use('agg')
from mpl_toolkits.basemap import Basemap
import numpy as np
from pylab import *
import sys
clat = float(sys.argv[1])
clon = float(sys.argv[2])
figwidth = 5.4
bounds = (clon-4, clon+4, clat-4, clat+4)
dx = (bounds[1] - bounds[0])*111191 * np.cos(clat * np.pi/180)
dy = (bounds[3] - bounds[2])*111191
aspect = dy/dx
figheight = aspect * figwidth
 
fig = figure(figsize=(figwidth,figheight),edgecolor='g',facecolor='g')
ax1 = fig.add_axes([0,0,1.0,1.0])
mapcontour = Basemap(llcrnrlon=bounds[0],llcrnrlat=bounds[2],
 urcrnrlon=bounds[1],urcrnrlat=bounds[3],
 resolution='h',projection='merc',lat_ts=clat)
water_color = [.47,.60,.81]
mapcontour.drawrivers(color=water_color)
mapcontour.drawcountries(color='k',linewidth=2.0)
mapcontour.drawcoastlines()
mapcontour.fillcontinents(color=[1.0,0.8,0.8],lake_color=water_color)
plt.savefig('output.png') 
--------------------------------------------------------------------
From: Michael D. <md...@st...> - 2010年05月10日 20:19:28
It seems to be failing on the minus signs in the text, due to a recent 
(incorrect) change to declared encoding of the postscript file.
This has been corrected in r8305.
You didn't mention which version of matplotlib you are running... I'm 
not sure this bug would be in the latest released version, only SVN trunk.
Mike
afancy wrote:
> Hi,
>
> Could anybody help me to take a look my following code? When I save it 
> to eps format, the eps file is corrupted. But i can save as pdf format 
> successfully instead.
>
> Regards
> tommy
>
>
> from matplotlib.font_manager import FontProperties
> data = ((16.31, 76.35, 62.62, 135.2),
> (6.4, 12.64, 87, 124.8 ),
> (6.08,60.18,75.2,100.59))
>
> color=('b','r','g','y')
> width = 0.2 
> fig = plt.figure()
> fig.set_size_inches((4.2,4.2))
>
> ax = fig.add_axes((0.2,0.1,0.75,0.
> 8))
> rects=[]
> xticks=[]
> patterns = ('...','//','xx', '\\\\')
>
> for i in range(len(data)):
> row = data[i]
> for j in range(len(row)):
> rect, = ax.bar(i+width*j, row[j], width,fill=False, 
> edgecolor='black', hatch=patterns[j])
> rect.set_hatch(patterns[j])
> rect.set_fill(False)
> if i==0:
> rects.append(rect)
> xticks.append(i+2*width)
> 
> ax.set_xticks(xticks) 
> ax.set_xticklabels(('Q1(s,p1,*)','Q2(s,p2,*)','Q3(s,p3,*)')) 
> ax.set_ylabel('Resp. time (ms)')
> lg=fig.legend(rects, 
> ('3XL-Array','3XL-MP','Jena2(db-based)','Jena2(file-based)'), 
> loc=(0.65,0.7), prop=FontProperties(size=9))
> lg.draw_frame(False)
> draw() 
> fig.savefig("4b.eps", format="eps", bbox_inches='tight') # Failed 
> to save, the eps is corrupted 
> #fig.savefig("4b.pdf", format="pdf", bbox_inches='tight') # pdf 
> format can be save correctly.
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
>
> 
> ------------------------------------------------------------------------
>
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
-- 
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA
From: afancy <gr...@gm...> - 2010年05月10日 19:28:38
Hi,
Could anybody help me to take a look my following code? When I save it to
eps format, the eps file is corrupted. But i can save as pdf format
successfully instead.
Regards
tommy
from matplotlib.font_manager import FontProperties
data = ((16.31, 76.35, 62.62, 135.2),
 (6.4, 12.64, 87, 124.8 ),
 (6.08,60.18,75.2,100.59))
color=('b','r','g','y')
width = 0.2
fig = plt.figure()
fig.set_size_inches((4.2,4.2))
ax = fig.add_axes((0.2,0.1,0.75,0.
8))
rects=[]
xticks=[]
patterns = ('...','//','xx', '\\\\')
for i in range(len(data)):
 row = data[i]
 for j in range(len(row)):
 rect, = ax.bar(i+width*j, row[j], width,fill=False,
edgecolor='black', hatch=patterns[j])
 rect.set_hatch(patterns[j])
 rect.set_fill(False)
 if i==0:
 rects.append(rect)
 xticks.append(i+2*width)
ax.set_xticks(xticks)
ax.set_xticklabels(('Q1(s,p1,*)','Q2(s,p2,*)','Q3(s,p3,*)'))
ax.set_ylabel('Resp. time (ms)')
lg=fig.legend(rects,
('3XL-Array','3XL-MP','Jena2(db-based)','Jena2(file-based)'),
loc=(0.65,0.7), prop=FontProperties(size=9))
lg.draw_frame(False)
draw()
fig.savefig("4b.eps", format="eps", bbox_inches='tight') # Failed to
save, the eps is corrupted
#fig.savefig("4b.pdf", format="pdf", bbox_inches='tight') # pdf format
can be save correctly.
From: Nico S. <nic...@gm...> - 2010年05月10日 16:20:05
I just noticed something else now:
When tick labels are explicitly supplied, that may not actually
reflect in the return result of get_ticks. Specifically, I set the
tick labels in a color bar, but get_ticklabels() returns a list of
empty text objects Text(0,0,'').
For regular axes, that seems to work better.
Bug?
Cheers,
Nico
On Sat, May 8, 2010 at 10:36 AM, Nico Schlömer <nic...@gm...> wrote:
> Hi,
>
> say, is there a way to query an axis object whether or not the tick
> labels are drawn?
>
> I looked at -- one the x-axis -- get_xticks( and get_xticklabels()
> which in two different situations would spit out a list of doubles
> (the tick positions) and a list of text entries of the form
> Text(0,0,''). In one plot, though, the tick labels are drawn, not in
> the other one.
>
> Cheers,
> Nico
>
From: Michael D. <md...@st...> - 2010年05月10日 15:16:34
You may also try saving as SVG and then loading in Inkscape and using 
its various "artistic" vector plugins to achieve similar results.
Mike
John Hunter wrote:
> On Fri, May 7, 2010 at 1:09 PM, Eric Firing <ef...@ha...> wrote:
> 
>> On 05/06/2010 08:02 PM, oyster wrote:
>> 
>>> I know matplotlib mimics matlab, which offers scientific look.
>>> but can we use matplotlib to get a skecth(in other words,
>>> hand-drawing) style for bar/pie/etc in none formalist paper? for
>>> example, http://teethgrinder.co.uk/open-flash-chart/gallery-bar-7.php
>>> thanks
>>> 
>> With a considerable effort you could use mpl's capabilities to program
>> this sort of thing, but it will not be added as an option.
>> 
>
> JJ's demo_ribbon_box is pretty close -- you just need to create a base
> image you want stretched to the bar height.
>
> import matplotlib.pyplot as plt
> import numpy as np
> from matplotlib.image import BboxImage
>
> from matplotlib._png import read_png
> import matplotlib.colors
> from matplotlib.cbook import get_sample_data
>
> class RibbonBox(object):
>
> original_image = read_png(get_sample_data("Minduka_Present_Blue_Pack.png",
> asfileobj=False))
> cut_location = 70
> b_and_h = original_image[:,:,2]
> color = original_image[:,:,2] - original_image[:,:,0]
> alpha = original_image[:,:,3]
> nx = original_image.shape[1]
>
> def __init__(self, color):
> rgb = matplotlib.colors.colorConverter.to_rgb(color)
>
> im = np.empty(self.original_image.shape,
> self.original_image.dtype)
>
>
> im[:,:,:3] = self.b_and_h[:,:,np.newaxis]
> im[:,:,:3] -= self.color[:,:,np.newaxis]*(1.-np.array(rgb))
> im[:,:,3] = self.alpha
>
> self.im = im
>
>
> def get_stretched_image(self, stretch_factor):
> stretch_factor = max(stretch_factor, 1)
> ny, nx, nch = self.im.shape
> ny2 = int(ny*stretch_factor)
>
> stretched_image = np.empty((ny2, nx, nch),
> self.im.dtype)
> cut = self.im[self.cut_location,:,:]
> stretched_image[:,:,:] = cut
> stretched_image[:self.cut_location,:,:] = \
> self.im[:self.cut_location,:,:]
> stretched_image[-(ny-self.cut_location):,:,:] = \
> self.im[-(ny-self.cut_location):,:,:]
>
> self._cached_im = stretched_image
> return stretched_image
>
>
>
> class RibbonBoxImage(BboxImage):
> zorder = 1
>
> def __init__(self, bbox, color,
> cmap = None,
> norm = None,
> interpolation=None,
> origin=None,
> filternorm=1,
> filterrad=4.0,
> resample = False,
> **kwargs
> ):
>
> BboxImage.__init__(self, bbox,
> cmap = cmap,
> norm = norm,
> interpolation=interpolation,
> origin=origin,
> filternorm=filternorm,
> filterrad=filterrad,
> resample = resample,
> **kwargs
> )
>
> self._ribbonbox = RibbonBox(color)
> self._cached_ny = None
>
>
> def draw(self, renderer, *args, **kwargs):
>
> bbox = self.get_window_extent(renderer)
> stretch_factor = bbox.height / bbox.width
>
> ny = int(stretch_factor*self._ribbonbox.nx)
> if self._cached_ny != ny:
> arr = self._ribbonbox.get_stretched_image(stretch_factor)
> self.set_array(arr)
> self._cached_ny = ny
>
> BboxImage.draw(self, renderer, *args, **kwargs)
>
>
> if 1:
> from matplotlib.transforms import Bbox, TransformedBbox
> from matplotlib.ticker import ScalarFormatter
>
> fig = plt.gcf()
> fig.clf()
> ax = plt.subplot(111)
>
> years = np.arange(2004, 2009)
> box_colors = [(0.8, 0.2, 0.2),
> (0.2, 0.8, 0.2),
> (0.2, 0.2, 0.8),
> (0.7, 0.5, 0.8),
> (0.3, 0.8, 0.7),
> ]
> heights = np.random.random(years.shape) * 7000 + 3000
>
> fmt = ScalarFormatter(useOffset=False)
> ax.xaxis.set_major_formatter(fmt)
>
> for year, h, bc in zip(years, heights, box_colors):
> bbox0 = Bbox.from_extents(year-0.4, 0., year+0.4, h)
> bbox = TransformedBbox(bbox0, ax.transData)
> rb_patch = RibbonBoxImage(bbox, bc, interpolation="bicubic")
>
> ax.add_artist(rb_patch)
>
> ax.annotate(r"%d" % (int(h/100.)*100),
> (year, h), va="bottom", ha="center")
>
> patch_gradient = BboxImage(ax.bbox,
> interpolation="bicubic",
> zorder=0.1,
> )
> gradient = np.zeros((2, 2, 4), dtype=np.float)
> gradient[:,:,:3] = [1, 1, 0.]
> gradient[:,:,3] = [[0.1, 0.3],[0.3, 0.5]] # alpha channel
> patch_gradient.set_array(gradient)
> ax.add_artist(patch_gradient)
>
>
> ax.set_xlim(years[0]-0.5, years[-1]+0.5)
> ax.set_ylim(0, 10000)
>
> fig.savefig('ribbon_box.png')
> plt.show()
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> 
> ------------------------------------------------------------------------
>
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
-- 
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA
From: Michael D. <md...@st...> - 2010年05月10日 15:07:14
I believe there's only a handful of characters available as 
sub/superscript in Unicode:
http://www.unicode.org/charts/PDF/U2070.pdf
Mike
Gökhan Sever wrote:
> Hello,
>
> I have tendency to use unicode strings for my simple units e.g. 
> plt.xlabel(u"Concentration (# cm−3)")
>
> Wondering if it is possible to subscript and/or superscript any 
> character in unicode strings? In other words could the following be 
> done via unicode only?
>
> plt.title(r"N$_{ccn} = C s^k$")
>
>
> Thanks.
> 
> Gökhan
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
>
> 
> ------------------------------------------------------------------------
>
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
-- 
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Showing 7 results of 7

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 によって変換されたページ (->オリジナル) /