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



Showing 11 results of 11

From: John H. <jdh...@ac...> - 2005年08月24日 22:57:32
>>>>> "David" == David Cameron <dc...@ce...> writes:
 David> Thanks for the suggestion I've now got lines through the
 David> origin. Do you know of anyway to add tick marks and labels
 David> to those lines? David
There is no built-in support for this currently, you would have to
draw the ticks and tick labels yourself (eg with the TICKLEFT,
TICKRIGHT, TICKUP, TICKDOWN linestyles). Making axis and tick
placement much more flexible is a high priority and is listed under
the "Axis autoranging and tick customization" section of the goals
page at http://matplotlib.sourceforge.net/goals.html. 
Feel free to file a support request on
http://sourceforge.net/tracker/?group_id=80706&atid=560721 to help us
track this issue.
Thanks,
JDH
From: John H. <jdh...@ac...> - 2005年08月24日 22:51:37
>>>>> "Vinj" == Vinj Vinj <vin...@ya...> writes:
 Vinj> I'm getting the following error: from matplotlib.pylab
 Vinj> import * File
 Vinj> "/usr/lib/python2.4/site-packages/matplotlib/pylab.py", line
 Vinj> 709, in ? figimage.__doc__ = Figure.figimage.__doc__ + """
 Vinj> TypeError: unsupported operand type(s) for +: 'NoneType' and
 Vinj> 'str' "
 Vinj> Any ideas what it might be and how I can get around it?
Any chance you are getting this with a py2exe frozen app?
If I recall correctly, there is an optimize flag in py2exe that
suppresses doc strings. This might explain your problem.
Please provide as much information as you can with posts. 
JDH
From: <m.a...@ri...> - 2005年08月24日 14:49:54
Hi John
> Not sure what you are doing wrong, but here's an example I just tested
> that created two PNGs with the indicated sizes in pixels (verified in
> the GIMP)
> 
> from pylab import *
> 
> Perhaps you can adapt it to your code.
> 
I tested it on my system and it did as it should. So I started to strip 
down my code to the basics. Replacing/Adding bit by bit. One error might 
have been that I used _F_igure() instead of _f_igure(). But the problem 
didn't go away. So I removed all "references" (var: fig) to the created 
figure... and it worked from then on...
Thanks John to bringing me back to the basics... but I still don't know 
what the reason was!
Merry greetings,
Marco - goes now after bug squashing to a real Squash session 8o)
The working code:
import matplotlib
matplotlib.use('Agg') # Agg, Cairo, GTK, GTKAgg, GTKCairo, PS, TkAgg, WX, 
WXAgg, Paint, GD, Template
from pylab import *
def create_png(filename, width_in_pixel, height_in_pixel):
 
 bar_colors = ["#E3E3AA", "#BFE0FF", "#FFE8C4", "#C6DFDA", 
"#D9D1EB"]
 bar_performances = [0.705, 1.757, 1.057, -0.635, -1.347]
 bar_descriptions = ('Scenario 1\nExpected\n%.2f%%', 'Scenario 
2\nBest case\n%.2f%%', 'Scenario 3\nBoom\n%.2f%%', 'Scenario 
4\nRecession\n%.2f%%', 'Scenario 5\nWorst case\n%.2f%%')
 
 dpi = 100
 figure(figsize=(int(width_in_pixel / dpi), int(height_in_pixel / 
dpi)))
 for b_num, b_perf in enumerate(bar_performances):
 bar((b_num + 0.55,), (b_perf,), width=.9, 
color=bar_colors[b_num])
 # Place the text in the middle of the bar
 t = text(b_num + 1, b_perf / 2.0, bar_descriptions[b_num] 
% b_perf, 
 horizontalalignment='center', 
 verticalalignment='center',
 size=9)
 
 gca()
 grid(True)
 xticks(arange(1,6), [''] * 5)
 ylabel('Performance %')
 draw() # force a draw
 savefig(filename, dpi=100)
if __name__ == '__main__':
 create_png('c:/temp/aaaaa_scenarios_600_300.png', 600, 300)
 create_png('c:/temp/aaaaa_scenarios_600_800.png', 600, 800)
 create_png('c:/temp/aaaaa_scenarios_800_600.png', 800, 600)
 create_png('c:/temp/aaaaa_scenarios_1000_200.png', 1000, 200)
From: John H. <jdh...@ac...> - 2005年08月24日 13:26:45
>>>>> "Yves" == Yves Moisan <ym...@gr...> writes:
 Yves> Hi All, I'm striving to understand how I ca stuff a file
 Yves> object (e.g. StringIO) to print_figure for an Agg backend.
 Yves> backend_agg.py states : "If filename is a fileobject, write
 Yves> png to file object (thus you can, for example, write the png
 Yves> to stdout".
This has come up a number of times. I worked on this once. The
sticking point is that libpng takes a FILE pointer, and the cstringio
doesn't provide one. There must be a way to do it, but I haven't
figured it out yet. Please file a support request on the sf site to
remind us to figure it out!
Thanks,
JDH
From: John H. <jdh...@ac...> - 2005年08月24日 13:25:40
>>>>> "m" == m aschwanden <m.a...@ri...> writes:
 m> All the rendered pngs have a size of 800x600 pixels!!!
 m> What the heck am I missing? Here the latest code:
Not sure what you are doing wrong, but here's an example I just tested
that created two PNGs with the indicated sizes in pixels (verified in
the GIMP)
 from pylab import *
 fig = figure(figsize=(8,6))
 plot([1,2,3])
 savefig('test1.png', dpi=100) # 800 x 600
 savefig('test2.png', dpi=200) #1600 x 1200
 show()
Perhaps you can adapt it to your code.
Hope this helps,
JDH
From: Nicholas Y. <su...@su...> - 2005年08月24日 13:10:13
On Wed, 2005年08月24日 at 12:58 +0200, Jesper Larsen wrote:
> CherryPy is able to serve/stream the image directly to the browser if it is 
> converted to a string using an appropriate encoding (png, rgb maybe). PIL is 
> able to do this conversion:
> 
> http://www.theorganization.net/mt/archives/2005/05/30/ive_finally_got_it.html
> 
> I would like to do something similar with my matplotlib image (i.e. convert it 
> to a string with an appropriate encoding) instead of writing it to the 
> harddisk. Does anyone know if that is possible?
I've just been working on something similar (although not for web use)
myself and came up with the following solution although it's possible
there's a better way.
Using the agg backend you can obtain an RGBA buffer or RGB string which
can then be loaded as a PIL Image for processing. I've adapted a the
examples/agg_oo.py to demonstrate.
----
from matplotlib.backends.backend_agg \
 import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
import Image
fig = Figure()
canvas = FigureCanvas(fig)
ax = fig.add_subplot(111)
ax.plot([1,2,3])
ax.set_title('hi mom')
ax.grid(True)
ax.set_xlabel('time')
ax.set_ylabel('volts')
canvas.draw()
size = canvas.get_width_height()
usebuffer = True
if usebuffer:
 # Load the agg buffer directly as the source of the PIL image
 # - could be less stable as agg and PIL share memory.
 buf = canvas.buffer_rgba()
 im = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1)
else:
 # Save the agg buffer to a string and load this into the PIL image.
 buf = canvas.tostring_rgb()
 im = Image.fromstring('RGB', size, buf, 'raw', 'RGB', 0, 1)
im.show()
----
Hope this helps,
Nick
From: <m.a...@ri...> - 2005年08月24日 12:16:58
Hi
Me once more. I am still working on the problem. The figures / canvases 
have the proper sizes (see print-log) but when they are saved, they will 
end up being 800x600 pixel pictures. The print-statements show the 
following log:
- - - - - - - -
Width: 2000
Height: 10000
dpi: 72
fig.get_dpi() = 72
Canvas size: (1944, 9936)
Figure size: (27.0, 138.0)
- - - - - - - -
Width: 600
Height: 800
dpi: 72
fig.get_dpi() = 72
Canvas size: (576, 792)
Figure size: (8.0, 11.0)
- - - - - - - -
Width: 800
Height: 600
dpi: 72
fig.get_dpi() = 72
Canvas size: (792, 576)
Figure size: (11.0, 8.0)
- - - - - - - -
Width: 1000
Height: 200
dpi: 72
fig.get_dpi() = 72
Canvas size: (936, 144)
Figure size: (13.0, 2.0)
All the rendered pngs have a size of 800x600 pixels!!!
What the heck am I missing? Here the latest code:
import matplotlib
matplotlib.use('Agg') # Agg, Cairo, GTK, GTKAgg, GTKCairo, PS, TkAgg, WX, 
WXAgg, Paint, GD, Template
from pylab import *
def create_png(filename, width_in_pixel, height_in_pixel):
 
 bar_colors = ["#E3E3AA", "#BFE0FF", "#FFE8C4", "#C6DFDA", 
"#D9D1EB"]
 bar_performances = [0.705, 1.757, 1.057, -0.635, -1.347]
 bar_descriptions = ('Scenario 1\nExpected\n%.2f%%', 'Scenario 
2\nBest case\n%.2f%%', 'Scenario 3\nBoom\n%.2f%%', 'Scenario 
4\nRecession\n%.2f%%', 'Scenario 5\nWorst case\n%.2f%%')
 
 dpi = 72
 fig = Figure(figsize=(width_in_pixel / dpi, height_in_pixel / 
dpi), dpi=dpi,facecolor="#D2D2D2")
 canvas = FigureCanvasBase(fig)
 fig.add_subplot(111)
 
 for b_num, b_perf in enumerate(bar_performances):
 bar((b_num + 0.55,), (b_perf,), width=.9, 
color=bar_colors[b_num])
 # Place the text in the middle of the bar
 t = text(b_num + 1, b_perf / 2.0, bar_descriptions[b_num] 
% b_perf, 
 horizontalalignment='center', 
 verticalalignment='center',
 size=9)
 
 gca()
 grid(True)
 xticks(arange(1,6), [''] * 5)
 ylabel('Performance %')
 draw() # force a draw
 print "- - - - - - - -"
 print "Width: %d" % width_in_pixel
 print "Height: %d" % height_in_pixel
 print "dpi: %d" % dpi
 print "fig.get_dpi() = %d" % fig.get_dpi()
 print "Canvas size: ", canvas.get_width_height() 
 print "Figure size: ", fig.get_size_inches()
 print 
 
 savefig(filename)
if __name__ == '__main__':
 create_png('c:/temp/aaaaa_scenarios_2000_10000.png', 2000, 10000)
 create_png('c:/temp/aaaaa_scenarios_600_800.png', 600, 800)
 create_png('c:/temp/aaaaa_scenarios_800_600.png', 800, 600)
 create_png('c:/temp/aaaaa_scenarios_1000_200.png', 1000, 200)
Even more desperate greetings,
Marco
From: Jeff W. <js...@fa...> - 2005年08月24日 11:44:10
Jesper Larsen wrote:
>Hi,
>
>When I run the following script (I hope the code indentations aren't messed up 
>by the mailing list software):
>
>#!/usr/bin/env /usr/bin/python
>
>import pylab
>import matplotlib.toolkits.basemap as basemap
>
>def main():
> filename = 'world.png'
> m = basemap.Basemap()
> pylab.figure(figsize=(8,m.aspect*8))
> m.drawcoastlines() # draw coastlines
> m.drawmeridians(pylab.arange(0.,420.,60.),labels=[0,0,0,1]) # draw meridians
> pylab.savefig(filename)
>
>if __name__ == '__main__': main()
>
>The meridians are not drawn at 60W and 120W. Is this a bug in basemap or have 
>I misunderstood something?
>
>Kind regards,
>Jesper
>
> 
>
Jesper: Just change
m.drawmeridians(pylab.arange(0.,420.,60.),labels=[0,0,0,1])
to
m.drawmeridians(pylab.arange(-180.,180.,60.),labels=[0,0,0,1])
and you will see those missing meridians.
-Jeff
-- 
Jeffrey S. Whitaker Phone : (303)497-6313
NOAA/OAR/CDC R/CDC1 FAX : (303)497-6449
325 Broadway Web : http://www.cdc.noaa.gov/~jsw
Boulder, CO, USA 80305-3328 Office: Skaggs Research Cntr 1D-124
From: Jesper L. <jl...@dm...> - 2005年08月24日 11:30:19
Hi,
When I run the following script (I hope the code indentations aren't messed up 
by the mailing list software):
#!/usr/bin/env /usr/bin/python
import pylab
import matplotlib.toolkits.basemap as basemap
def main():
 filename = 'world.png'
 m = basemap.Basemap()
 pylab.figure(figsize=(8,m.aspect*8))
 m.drawcoastlines() # draw coastlines
 m.drawmeridians(pylab.arange(0.,420.,60.),labels=[0,0,0,1]) # draw meridians
 pylab.savefig(filename)
if __name__ == '__main__': main()
The meridians are not drawn at 60W and 120W. Is this a bug in basemap or have 
I misunderstood something?
Kind regards,
Jesper
From: Jesper L. <jl...@dm...> - 2005年08月24日 10:59:06
Hi matplotlib users,
I'm using matplotlib for an application for producing tsunami travel time 
contour maps. Recently I discovered the CherryPy (cherrypy.org) web server 
framework which allows you to very easily embed a web server in your 
application. This allows the application to be accessed remotely through a 
web browser.
At present the application produces the contour plots when it receives input 
from a web browser that it should do so. The contour plot png image is then 
saved to disk and served to the user.
CherryPy is able to serve/stream the image directly to the browser if it is 
converted to a string using an appropriate encoding (png, rgb maybe). PIL is 
able to do this conversion:
http://www.theorganization.net/mt/archives/2005/05/30/ive_finally_got_it.html
I would like to do something similar with my matplotlib image (i.e. convert it 
to a string with an appropriate encoding) instead of writing it to the 
harddisk. Does anyone know if that is possible?
Kind regards,
Jesper
From: <m.a...@ri...> - 2005年08月24日 07:38:59
Hi there
I would like to generate pngs. The trouble I have: I can't size the png. I 
tried so many variations and browsed through lots of mailings... it seems, 
I am too stupid for it. Here is my last approach:
from pylab import *
def create_png(filename, width_in_pixel, height_in_pixel):
 bar_colors = ["#E3E3AA", "#BFE0FF", "#FFE8C4", "#C6DFDA", 
"#D9D1EB"]
 bar_performances = [7.05, 17.57, 10.45, -6.35, -13.47]
 
 fig = Figure()
 canvas = FigureCanvasBase(fig)
 fig.add_subplot(111)
 
 for b_num, b_perf in enumerate(bar_performances):
 bar((b_num + 0.55,), (b_perf,), width=.9, 
color=bar_colors[b_num])
 
 gca()
 grid(True)
 xticks(arange(1,6), ('Scenario 1\nExpected', 'Scenario 2\nBest 
case', 'Scenario 3\nBoom', 'Scenario 4\nRecession', 'Scenario 5\nWorst 
case'))
 ylabel('Performance')
 
 dpi = canvas.figure.get_dpi()
 fig.set_figsize_inches(width_in_pixel / dpi, height_in_pixel / 
dpi)
 
 canvas.draw() # force a draw
 
 savefig(filename, dpi=dpi)
if __name__ == '__main__':
 create_png('c:/temp/aaaaa_scenarios.png', 400, 150)
Can you give me any hints how to correct the problem? The png is always 
around (600,400) pixel... My next approach would be to create the png and 
afterwards scale it with PIL - but it can't be that matplotlib does not 
offer a proper scaling/resizing feature - does it?
Desperate Greetings,
Marco

Showing 11 results of 11

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