Re: [Matplotlib-users] savefig and StringIO error on Python3
Le 02/11/2014 09:34, Scott Lasley a écrit : > I wish I could say that it was because of a deep understanding of the inner > workings of matplotlib or a rock solid grasp of python 3's bytes vs strings, > but it wasn't. fig.savefig threw the "TypeError: string argument expected, > got 'bytes'" exception, so I figured BytesIO might work better with the > binary png data than StringIO, and it did. As a side note on the "bytes vs strings" topic, there is PyCon video that I found immensely useful: Pragmatic Unicode, or How Do I Stop the Pain http://nedbatchelder.com/text/unipain.html IMHO a 30 minutes talk worth watching. best, Pierre -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig and StringIO error on Python3
I wish I could say that it was because of a deep understanding of the inner workings of matplotlib or a rock solid grasp of python 3's bytes vs strings, but it wasn't. fig.savefig threw the "TypeError: string argument expected, got 'bytes'" exception, so I figured BytesIO might work better with the binary png data than StringIO, and it did. Your image URI included base64 encoding I added the base64 code and fiddled with decoding to get it to produce ASCII. iPython is great for this sort of playing around with snippets of code. btw, if you are not aware of the pros and cons of using data uri's to embed images take a look at this Wikipedia page for some helpful information http://en.wikipedia.org/wiki/Data_URI_scheme Apologies if you were expecting a more detailed answer, Scott On Nov 1, 2014, at 4:37 PM, Julien Hillairet wrote: > Indeed, it works also for me with Python 3.3.5. > > Could you explain the changes you made and the reasons behind the byte/string > encoding ? > > Best regards, > > 2014-11-01 17:21 GMT+01:00 Scott Lasley : > This works for me with python 3.4.2 > > import matplotlib.pyplot as plt > from io import BytesIO > import base64 > > fig = plt.figure() > ax = fig.add_subplot(111) > ax.plot([1,2,3]) > > sio = BytesIO() > > fig.savefig(sio, format="png") > > html = """ > > """.format(base64.encodebytes(sio.getvalue()).decode()) > > > For python 2.7.8 change html =""" to > > html = """ > > """ % base64.encodestring(sio.getvalue()) > > Best regards, > Scott > > > On Nov 1, 2014, at 7:37 AM, Julien Hillairet > wrote: > > > Dear all, > > I'm trying to write a html page content in which a png figure is generated > > by matplotlib, with Python3. > > However, the following piece of code does not work with matplotlib/Python3 > > (while it should work with Python2). The error is the following on > > TypeError: string argument expected, got 'bytes' > > when on fig.savefig(sio, format="png") > > Could someone explain me how to do it ? > > Best regards, > > Julien > > > > > > > > import matplotlib.pyplot as plt > > > > from io import StringIO > > fig = plt.figure() > > ax = fig.add_subplot(111) > > ax.plot([1,2,3]) > > > > sio = StringIO() > > > > fig.savefig(sio, format="png") > > > > html = """ > > ...a bunch of text and html here... > > > > ...more text and html... > > """ % sio.getvalue().strip() > > > > -- -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig and StringIO error on Python3
Well, the methodology is sufficient and efficient, I'm OK with that :) Thanks for these additional information. Regards, Le 2 nov. 2014 09:34, "Scott Lasley" a écrit : > I wish I could say that it was because of a deep understanding of the > inner workings of matplotlib or a rock solid grasp of python 3's bytes vs > strings, but it wasn't. fig.savefig threw the "TypeError: string argument > expected, got 'bytes'" exception, so I figured BytesIO might work better > with the binary png data than StringIO, and it did. Your image URI > included base64 encoding I added the base64 code and fiddled with decoding > to get it to produce ASCII. iPython is great for this sort of playing > around with snippets of code. > > btw, if you are not aware of the pros and cons of using data uri's to > embed images take a look at this Wikipedia page for some helpful information > http://en.wikipedia.org/wiki/Data_URI_scheme > > Apologies if you were expecting a more detailed answer, > Scott > > > On Nov 1, 2014, at 4:37 PM, Julien Hillairet > wrote: > > > Indeed, it works also for me with Python 3.3.5. > > > > Could you explain the changes you made and the reasons behind the > byte/string encoding ? > > > > Best regards, > > > > 2014-11-01 17:21 GMT+01:00 Scott Lasley : > > This works for me with python 3.4.2 > > > > import matplotlib.pyplot as plt > > from io import BytesIO > > import base64 > > > > fig = plt.figure() > > ax = fig.add_subplot(111) > > ax.plot([1,2,3]) > > > > sio = BytesIO() > > > > fig.savefig(sio, format="png") > > > > html = """ > > > > """.format(base64.encodebytes(sio.getvalue()).decode()) > > > > > > For python 2.7.8 change html =""" to > > > > html = """ > > > > """ % base64.encodestring(sio.getvalue()) > > > > Best regards, > > Scott > > > > > > On Nov 1, 2014, at 7:37 AM, Julien Hillairet > wrote: > > > > > Dear all, > > > I'm trying to write a html page content in which a png figure is > generated by matplotlib, with Python3. > > > However, the following piece of code does not work with > matplotlib/Python3 (while it should work with Python2). The error is the > following on > > > TypeError: string argument expected, got 'bytes' > > > when on fig.savefig(sio, format="png") > > > Could someone explain me how to do it ? > > > Best regards, > > > Julien > > > > > > > > > > > > import matplotlib.pyplot as plt > > > > > > from io import StringIO > > > fig = plt.figure() > > > ax = fig.add_subplot(111) > > > ax.plot([1,2,3]) > > > > > > sio = StringIO() > > > > > > fig.savefig(sio, format="png") > > > > > > html = """ > > > ...a bunch of text and html here... > > > > > > ...more text and html... > > > """ % sio.getvalue().strip() > > > > > > > -- > > -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig and StringIO error on Python3
Indeed, it works also for me with Python 3.3.5. Could you explain the changes you made and the reasons behind the byte/string encoding ? Best regards, 2014-11-01 17:21 GMT+01:00 Scott Lasley : > This works for me with python 3.4.2 > > import matplotlib.pyplot as plt > from io import BytesIO > import base64 > > fig = plt.figure() > ax = fig.add_subplot(111) > ax.plot([1,2,3]) > > sio = BytesIO() > > fig.savefig(sio, format="png") > > html = """ > > """.format(base64.encodebytes(sio.getvalue()).decode()) > > > For python 2.7.8 change html =""" to > > html = """ > > """ % base64.encodestring(sio.getvalue()) > > Best regards, > Scott > > > On Nov 1, 2014, at 7:37 AM, Julien Hillairet > wrote: > > > Dear all, > > I'm trying to write a html page content in which a png figure is > generated by matplotlib, with Python3. > > However, the following piece of code does not work with > matplotlib/Python3 (while it should work with Python2). The error is the > following on > > TypeError: string argument expected, got 'bytes' > > when on fig.savefig(sio, format="png") > > Could someone explain me how to do it ? > > Best regards, > > Julien > > > > > > > > import matplotlib.pyplot as plt > > > > from io import StringIO > > fig = plt.figure() > > ax = fig.add_subplot(111) > > ax.plot([1,2,3]) > > > > sio = StringIO() > > > > fig.savefig(sio, format="png") > > > > html = """ > > ...a bunch of text and html here... > > > > ...more text and html... > > """ % sio.getvalue().strip() > > > > > -- > > -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig and StringIO error on Python3
Many Thanks for your support. It is Python 3.3.5 and matplotlib 1.4.0 I've also found that it worked with ByteIO(), but then I was stuck by the encode/decode things. Thanks very much ! The traceback is below: Traceback (most recent call last): File "", line 1, in runfile('/home/hash/example.py', wdir='/home/hash') File "/usr/lib/python3.3/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 586, in runfile execfile(filename, namespace) File "/usr/lib/python3.3/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 48, in execfile exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace) File "/home/hash/example.py", line 10, in fig.savefig(sio, format="png") File "/usr/lib64/python3.3/site-packages/matplotlib/figure.py", line 1470, in savefig self.canvas.print_figure(*args, **kwargs) File "/usr/lib64/python3.3/site-packages/matplotlib/backend_bases.py", line 2192, in print_figure **kwargs) File "/usr/lib64/python3.3/site-packages/matplotlib/backends/backend_agg.py", line 525, in print_png filename_or_obj, self.figure.dpi) TypeError: string argument expected, got 'bytes' 2014-11-01 17:21 GMT+01:00 Scott Lasley : > This works for me with python 3.4.2 > > import matplotlib.pyplot as plt > from io import BytesIO > import base64 > > fig = plt.figure() > ax = fig.add_subplot(111) > ax.plot([1,2,3]) > > sio = BytesIO() > > fig.savefig(sio, format="png") > > html = """ > > """.format(base64.encodebytes(sio.getvalue()).decode()) > > > For python 2.7.8 change html =""" to > > html = """ > > """ % base64.encodestring(sio.getvalue()) > > Best regards, > Scott > > > On Nov 1, 2014, at 7:37 AM, Julien Hillairet > wrote: > > > Dear all, > > I'm trying to write a html page content in which a png figure is > generated by matplotlib, with Python3. > > However, the following piece of code does not work with > matplotlib/Python3 (while it should work with Python2). The error is the > following on > > TypeError: string argument expected, got 'bytes' > > when on fig.savefig(sio, format="png") > > Could someone explain me how to do it ? > > Best regards, > > Julien > > > > > > > > import matplotlib.pyplot as plt > > > > from io import StringIO > > fig = plt.figure() > > ax = fig.add_subplot(111) > > ax.plot([1,2,3]) > > > > sio = StringIO() > > > > fig.savefig(sio, format="png") > > > > html = """ > > ...a bunch of text and html here... > > > > ...more text and html... > > """ % sio.getvalue().strip() > > > > > -- > > -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig and StringIO error on Python3
This works for me with python 3.4.2 import matplotlib.pyplot as plt from io import BytesIO import base64 fig = plt.figure() ax = fig.add_subplot(111) ax.plot([1,2,3]) sio = BytesIO() fig.savefig(sio, format="png") html = """ """.format(base64.encodebytes(sio.getvalue()).decode()) For python 2.7.8 change html =""" to html = """ """ % base64.encodestring(sio.getvalue()) Best regards, Scott On Nov 1, 2014, at 7:37 AM, Julien Hillairet wrote: > Dear all, > I'm trying to write a html page content in which a png figure is generated by > matplotlib, with Python3. > However, the following piece of code does not work with matplotlib/Python3 > (while it should work with Python2). The error is the following on > TypeError: string argument expected, got 'bytes' > when on fig.savefig(sio, format="png") > Could someone explain me how to do it ? > Best regards, > Julien > > > > import matplotlib.pyplot as plt > > from io import StringIO > fig = plt.figure() > ax = fig.add_subplot(111) > ax.plot([1,2,3]) > > sio = StringIO() > > fig.savefig(sio, format="png") > > html = """ > ...a bunch of text and html here... > > ...more text and html... > """ % sio.getvalue().strip() > > -- -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig and StringIO error on Python3
Please post the entire traceback so that we can know the context of the error message. Also, exactly which versions of matplotlib and python are you using? Ben Root On Sat, Nov 1, 2014 at 7:37 AM, Julien Hillairet wrote: > Dear all, > > I'm trying to write a html page content in which a png figure is generated > by matplotlib, with Python3. > > However, the following piece of code does not work with matplotlib/Python3 > (while it should work with Python2). The error is the following on > > TypeError: string argument expected, got 'bytes' > > when on fig.savefig(sio, format="png") > > > Could someone explain me how to do it ? > > Best regards, > > Julien > > > > import matplotlib.pyplot as plt > > > from io import StringIO > > fig = plt.figure() > > ax = fig.add_subplot(111) > > ax.plot([1,2,3]) > > > sio = StringIO() > > > fig.savefig(sio, format="png") > > > html = """ > > ...a bunch of text and html here... > > > > ...more text and html... > > """ % sio.getvalue().strip() > > > > -- > > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig - legend only
Is it legend(loc='auto') or legend(loc='best')? I always used the latter. I think that http://matplotlib.org/api/legend_api.html supports me here. -Sterling On Jan 31, 2014, at 8:31AM, Benjamin Root wrote: > I would also like to point out that you can specify "auto" for a location, > and matplotlib will attempt to find a good location for you (within the plot > area). It isn't perfect, but it can be useful. > > Cheers! > Ben Root > > > On Fri, Jan 31, 2014 at 7:02 AM, Skip Montanaro wrote: > > 1. PNG file of figure without legend. > > 2. PNG file of legend only. > > > > The end user would import both images into another tool (e.g. microsoft > > power point) and arrange figure and legend interactively for the final > > product. > > As someone pointed out to me not long ago, you can call > > my_legend.draggable(True) > > then drag the legend where you want (in normal pointer mode). Then you > just need to save the figure and not worry about fiddling with it > later. > > Skip Montanaro > > -- > WatchGuard Dimension instantly turns raw network data into actionable > security intelligence. It gives you real-time visual feedback on key > security issues and trends. Skip the complicated setup - simply import > a virtual appliance and go from zero to informed in seconds. > http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- > WatchGuard Dimension instantly turns raw network data into actionable > security intelligence. It gives you real-time visual feedback on key > security issues and trends. Skip the complicated setup - simply import > a virtual appliance and go from zero to informed in seconds. > http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- WatchGuard Dimension instantly turns raw network data into actionable security intelligence. It gives you real-time visual feedback on key security issues and trends. Skip the complicated setup - simply import a virtual appliance and go from zero to informed in seconds. http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig - legend only
I would also like to point out that you can specify "auto" for a location, and matplotlib will attempt to find a good location for you (within the plot area). It isn't perfect, but it can be useful. Cheers! Ben Root On Fri, Jan 31, 2014 at 7:02 AM, Skip Montanaro wrote: > > 1. PNG file of figure without legend. > > 2. PNG file of legend only. > > > > The end user would import both images into another tool (e.g. microsoft > > power point) and arrange figure and legend interactively for the final > > product. > > As someone pointed out to me not long ago, you can call > > my_legend.draggable(True) > > then drag the legend where you want (in normal pointer mode). Then you > just need to save the figure and not worry about fiddling with it > later. > > Skip Montanaro > > > -- > WatchGuard Dimension instantly turns raw network data into actionable > security intelligence. It gives you real-time visual feedback on key > security issues and trends. Skip the complicated setup - simply import > a virtual appliance and go from zero to informed in seconds. > > http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- WatchGuard Dimension instantly turns raw network data into actionable security intelligence. It gives you real-time visual feedback on key security issues and trends. Skip the complicated setup - simply import a virtual appliance and go from zero to informed in seconds. http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig - legend only
> 1. PNG file of figure without legend. > 2. PNG file of legend only. > > The end user would import both images into another tool (e.g. microsoft > power point) and arrange figure and legend interactively for the final > product. As someone pointed out to me not long ago, you can call my_legend.draggable(True) then drag the legend where you want (in normal pointer mode). Then you just need to save the figure and not worry about fiddling with it later. Skip Montanaro -- WatchGuard Dimension instantly turns raw network data into actionable security intelligence. It gives you real-time visual feedback on key security issues and trends. Skip the complicated setup - simply import a virtual appliance and go from zero to informed in seconds. http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig - legend only
Hi Peter, just get the legend handlers and labels with handles,labels = ax.get_legend_handles_labels() then create an empty plot with axes `axe` and do axe.legend(handles, labels, loc=loc) If you want to hide the axis: axe.xaxis.set_visible(False) axe.yaxis.set_visible(False) and/or for v in axe.spines.values(): v.set_visible(False) Enjoy, Fra 2014-01-31 Peter Van Wieren > > I would like to ask if there is a way to print only the legend box of a > figure. > > The motiviation for wanting to do this is a work around to the problem of > having the legend box obscuring data without resorting to "outside" > placement of the legend. The idea here is that matplotlib would provide > two images: > > 1. PNG file of figure without legend. > 2. PNG file of legend only. > > The end user would import both images into another tool (e.g. microsoft > power point) and arrange figure and legend interactively for the final > product. > > Example follows: > > import numpy as np > import matplotlib.pyplot as plt > > x = np.linspace(0, 1) > fig, (ax) = plt.subplots(nrows=1) > ax.plot( x , np.sin(2*np.pi*x) , label='Curve1') > ax.plot( x , np.sin(2*np.pi*x+0.2) , label='Curve2') > ax.set_title('Set default color cycle to rgby') > plt.savefig('without_legend.png',dpi=75) > > if True: # Difficult to automatically make a location choice robust > ax.legend(loc='upper left') # in this particular case, a poor choice for > placement > else: > ax.legend(loc='upper right') # in this particular case, a good choice > for placement > > plt.savefig('with_legend.png',dpi=75) > > # worst case solution could be post processing these files with imagemagick > # begin with "composite without_legend.png with_legend.png -compose > difference alpha_channel.png" > #... then filter with alpha_channel.png against with_legend.png > #... finally crop this to get "legend_only.png" > > > > -- > WatchGuard Dimension instantly turns raw network data into actionable > security intelligence. It gives you real-time visual feedback on key > security issues and trends. Skip the complicated setup - simply import > a virtual appliance and go from zero to informed in seconds. > > http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- WatchGuard Dimension instantly turns raw network data into actionable security intelligence. It gives you real-time visual feedback on key security issues and trends. Skip the complicated setup - simply import a virtual appliance and go from zero to informed in seconds. http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig
Thank you, This is some thing new, which I learned. with best regards, Sudheer *** Sudheer Joseph Indian National Centre for Ocean Information Services Ministry of Earth Sciences, Govt. of India POST BOX NO: 21, IDA Jeedeemetla P.O. Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55 Tel:+91-40-23886047(O),Fax:+91-40-23895011(O), Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile) E-mail:sjo.in...@gmail.com;sudheer.jos...@yahoo.com Web- http://oppamthadathil.tripod.com *** > > From: Paul Hobson >To: Sudheer Joseph >Cc: "matplotlib-users@lists.sourceforge.net" > >Sent: Friday, 14 June 2013 9:05 PM >Subject: Re: [Matplotlib-users] savefig > > > >On Thu, Jun 13, 2013 at 11:40 PM, Sudheer Joseph >wrote: > >Thank you, >>I don't see a way other than starting in normal mode as the moment I type >>plot command it get displayed and I don't need to do a show command. >> > > >In the qtconsole, you can enter multi-line mode with crtl+enter. > > > > >-- This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig
On Thu, Jun 13, 2013 at 11:40 PM, Sudheer Joseph wrote: > Thank you, > I don't see a way other than starting in normal mode as the moment I type > plot command it get displayed and I don't need to do a show command. > In the qtconsole, you can enter multi-line mode with crtl+enter. -- This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig
Thank you, I don't see a way other than starting in normal mode as the moment I type plot command it get displayed and I don't need to do a show command. With best regards sudheer-- This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig
Thank you Roban, Your that trick worked, if I keep ts.plot(), savefig('ts.pdf') both on same line it works! with best regards Sudheer *** Sudheer Joseph Indian National Centre for Ocean Information Services Ministry of Earth Sciences, Govt. of India POST BOX NO: 21, IDA Jeedeemetla P.O. Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55 Tel:+91-40-23886047(O),Fax:+91-40-23895011(O), Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile) E-mail:sjo.in...@gmail.com;sudheer.jos...@yahoo.com Web- http://oppamthadathil.tripod.com *** > > From: Roban Kramer >To: sudheer.jos...@yahoo.com >Cc: Paul Hobson ; "matplotlib-users@lists.sourceforge.net" > >Sent: Thursday, 13 June 2013 8:12 PM >Subject: Re: [Matplotlib-users] savefig > > > >savefig works for me when I put both the plotting commands and the savefig >call in the *same* code cell. > > > >On Thu, Jun 13, 2013 at 10:31 AM, Sudheer Joseph >wrote: > >Thank you, >>I don't see a way other than starting in normal mode as the moment I type >>plot command it get displayed and I don't need to do a show command. >>With best regards sudheer >> >> >> >>________ >> From: Paul Hobson ; >>To: Sudheer Joseph ; >>Cc: matplotlib-users@lists.sourceforge.net >>; >>Subject: Re: [Matplotlib-users] savefig >>Sent: Thu, Jun 13, 2013 2:23:05 PM >> >> >> >> >> >>On Wed, Jun 12, 2013 at 10:28 PM, Sudheer Joseph >>wrote: >> >>Dear experts, >>>I start ipython in ipython qtconsole --pylab=inline mode and make a plot. >>>But if I use savefig('fig.png') the figure do not get saved instead I get a >>>blank page. >>> >>> I also tried img.save('fig.png',png) but no use. Is there a way out or I >>>need to do this after quitting and restarting in normal mode each time I >>>want to save? >>> >>>ipython qtconsole --pylab=inline >>> >>> >>>In [93]: ts.plot() >>>Out[93]: >>> >> >> >>The fig is destroyed after it has been displayed by the console. Try saving >>it before it gets shown. >>-p >>-- >>This SF.net email is sponsored by Windows: >> >>Build for Windows Store. >> >>http://p.sf.net/sfu/windows-dev2dev >>___ >>Matplotlib-users mailing list >>Matplotlib-users@lists.sourceforge.net >>https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> >> > > > -- This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig
close_figures, not close_all Haven't tried to switch it at run time using %config magic though. $ ipython [qtconsole|notebook|whatever] --help-all to get all option as examples in config files are **not** updated with IPython. InlineBackend options - --InlineBackend.close_figures= Default: True Close all figures at the end of each cell. When True, ensures that each cell starts with no active figures, but it also means that one must keep track of references in order to edit or redraw figures in subsequent cells. This mode is ideal for the notebook, where residual plots from other cells might be surprising. When False, one must call figure() to create new figures. This means that gcf() and getfigs() can reference figures created in other cells, and the active figure can continue to be edited with pylab/pyplot methods that reference the current active figure. This mode facilitates iterative editing of figures, and behaves most consistently with other matplotlib backends, but figure barriers between cells must be explicit. -- This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig
savefig works for me when I put both the plotting commands and the savefig call in the *same* code cell. On Thu, Jun 13, 2013 at 10:31 AM, Sudheer Joseph wrote: > Thank you, > I don't see a way other than starting in normal mode as the moment I type > plot command it get displayed and I don't need to do a show command. > With best regards sudheer > > -- > * From: * Paul Hobson ; > * To: * Sudheer Joseph ; > * Cc: * matplotlib-users@lists.sourceforge.net < > matplotlib-users@lists.sourceforge.net>; > * Subject: * Re: [Matplotlib-users] savefig > * Sent: * Thu, Jun 13, 2013 2:23:05 PM > > > On Wed, Jun 12, 2013 at 10:28 PM, Sudheer Joseph > wrote: > >> Dear experts, >> I start ipython in ipython qtconsole --pylab=inline mode and make a plot. >> But if I use savefig('fig.png') the figure do not get saved instead I get a >> blank page. >> >> I also tried img.save('fig.png',png) but no use. Is there a way out or I >> need to do this after quitting and restarting in normal mode each time I >> want to save? >> >> ipython qtconsole --pylab=inline >> >> >> In [93]: ts.plot() >> Out[93]: >> > > The fig is destroyed after it has been displayed by the console. Try > saving it before it gets shown. > -p > > > -- > This SF.net email is sponsored by Windows: > > Build for Windows Store. > > http://p.sf.net/sfu/windows-dev2dev > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig
Thank you, I don't see a way other than starting in normal mode as the moment I type plot command it get displayed and I don't need to do a show command. With best regards sudheer-- This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig
On Wed, Jun 12, 2013 at 10:28 PM, Sudheer Joseph wrote: > Dear experts, > I start ipython in ipython qtconsole --pylab=inline mode and make a plot. > But if I use savefig('fig.png') the figure do not get saved instead I get a > blank page. > > I also tried img.save('fig.png',png) but no use. Is there a way out or I > need to do this after quitting and restarting in normal mode each time I > want to save? > > ipython qtconsole --pylab=inline > > > In [93]: ts.plot() > Out[93]: > The fig is destroyed after it has been displayed by the console. Try saving it before it gets shown. -p -- This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig problem
Ben: That's what I did: plt.show() then plt.savefig(). I now know to reverse the order. Thanks! - Roy On Fri, Jul 29, 2011 at 7:32 PM, Benjamin Root wrote: > On Fri, Jul 29, 2011 at 6:19 PM, Roy Lowrance wrote: > >> I'm using matplotlib on ubuntu 11.04. >> >> I create a figure and an axes and then show it via plt.show(). >> >> From the window that plt.show() opens, I save the file to plot-3.png. This >> works as I can open the file with evince. >> >> However, when my program executes plt.savefig('plot-3.png'), something is >> saved as a file is created, but when I open the file with evince (or GIMP), >> I see just the canvas, not the figure. >> >> How do I save under program control? >> >> - Roy >> >> > There are a few common mistakes that might have happened. First, if you > did a plt.show() and then closed the displayed figure, and *then* saved the > figure, you will be saving the image of a new figure as you have already > "destroyed" the old figure. If this is the case, put the savefig command > *before* plt.show(). > > Another possibility is that another figure was somehow created between the > last plotting > function and the call to savefig(). plt.savefig() assumes the current > (active) figure, and so if another figure is accidentially created before > calling savefig(), then you will be saving a blank figure. > > I hope this helps, and let us know if you have further questions! > Ben Root > > -- Roy Lowrance home: 212 674 9777 mobile: 347 255 2544 -- Got Input? Slashdot Needs You. Take our quick survey online. Come on, we don't ask for help often. Plus, you'll get a chance to win $100 to spend on ThinkGeek. http://p.sf.net/sfu/slashdot-survey___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig problem
On Fri, Jul 29, 2011 at 6:19 PM, Roy Lowrance wrote: > I'm using matplotlib on ubuntu 11.04. > > I create a figure and an axes and then show it via plt.show(). > > From the window that plt.show() opens, I save the file to plot-3.png. This > works as I can open the file with evince. > > However, when my program executes plt.savefig('plot-3.png'), something is > saved as a file is created, but when I open the file with evince (or GIMP), > I see just the canvas, not the figure. > > How do I save under program control? > > - Roy > > There are a few common mistakes that might have happened. First, if you did a plt.show() and then closed the displayed figure, and *then* saved the figure, you will be saving the image of a new figure as you have already "destroyed" the old figure. If this is the case, put the savefig command *before* plt.show(). Another possibility is that another figure was somehow created between the last plotting function and the call to savefig(). plt.savefig() assumes the current (active) figure, and so if another figure is accidentially created before calling savefig(), then you will be saving a blank figure. I hope this helps, and let us know if you have further questions! Ben Root -- Got Input? Slashdot Needs You. Take our quick survey online. Come on, we don't ask for help often. Plus, you'll get a chance to win $100 to spend on ThinkGeek. http://p.sf.net/sfu/slashdot-survey___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Savefig Question
It's hard to say from the code snippet, but I would track down whether self.page_graph.figure is the figure that you think it is. It could be a Figure object without any axes on it. Cheers, Mike On 07/08/2011 03:55 AM, Sebastian Rhode wrote: Hi, I use the followng function for my application: def OnSaveAs(self, event): dlg = wx.FileDialog(self, 'Choose a Filename', os.getcwd(), '', '*.png*', wx.SAVE | wx.OVERWRITE_PROMPT) if dlg.ShowModal() == wx.ID_OK: savename = dlg.GetPath() self.page_graph.figure.savefig(savename) dlg.Destroy() This seems to work, but when I open the resulting PNG, only the figure is saved without the graph ... But when I use the save button from the figure itself, the result is fine, the figure is save with the graph. So I can just removed that function, but I am curious, why it does not work as expected. Any ideas, what my mistake is? Cheers, Sebi -- All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2d-c2 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2d-c2___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig very slow
Can you provide a standalone script that reproduces the problem? How many points are you plotting? Cheers, Mike On 06/15/2011 06:09 AM, Francesco Benincasa wrote: > Hi all, > I've noticed that savefig is very slow when I draw wind (using "quiver" and > "quiverkey" commands). > > If I don't draw winds is very fast (2 seconds against 13 seconds). > > Is possible to make the program faster? Any idea? > > I use the 'Agg' backend and the latest version of matplotlib. > > Thank you in advance, > -- Michael Droettboom Science Software Branch Space Telescope Science Institute Baltimore, Maryland, USA -- EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig not deducing file format
Ah, sorry for the duplicate message! Cheers, G On 15/03/2011 11:30, Giovanni Luca Ciampaglia wrote: > Hi all, > I call savefig by passing to it a file-like object but it appears to not > get the graphics format right: > > f = open('not_a_pdf.pdf', 'w') > plot([1,2,3]) > savefig(f) > > but it produces a PNG image. Can anybody confirm this? I am on > matplotlib 0.99.3 > > Cheers, -- Enable your software for Intel(R) Active Management Technology to meet the growing manageability and security demands of your customers. Businesses are taking advantage of Intel(R) vPro (TM) technology - will your software be a part of the solution? Download the Intel(R) Manageability Checker today! http://p.sf.net/sfu/intel-dev2devmar ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig not deducing file format
Le mardi 15 mars 2011 à 11:30 +0100, Giovanni Luca Ciampaglia a écrit : > Hi all, > I call savefig by passing to it a file-like object but it appears to not > get the graphics format right: > > f = open('not_a_pdf.pdf', 'w') > plot([1,2,3]) > savefig(f) > > but it produces a PNG image. Can anybody confirm this? I am on > matplotlib 0.99.3 > > Cheers, You may give savefig a filename (string 'tmp.pdf') instead of the file descriptor (file object f), or use the format keyword argument. Automatic format selection is not handled for file object (as visible in backend_bases.py:FigureCanvasBase.print_figure method). -- Fabrice -- Enable your software for Intel(R) Active Management Technology to meet the growing manageability and security demands of your customers. Businesses are taking advantage of Intel(R) vPro (TM) technology - will your software be a part of the solution? Download the Intel(R) Manageability Checker today! http://p.sf.net/sfu/intel-dev2devmar ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig not deducing file format
On 3/15/2011 8:51 AM, Michael Droettboom wrote: > It has no way of deducing the file format from the file object. Inspect f.name? Alan Isaac -- Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig not deducing file format
My fault, I didn't read the docstring properly. Thanks for both replies. Best, G On 15/03/2011 13:51, Michael Droettboom wrote: > It has no way of deducing the file format from the file object. > > You need to explicitly pass the format keyword to savefig, e.g.: > > savefig(f, format='pdf') > > Mike > > On 03/15/2011 07:11 AM, Giovanni Luca Ciampaglia wrote: >> Hi all, >> I call savefig by passing to it a file-like object but it appears to not >> get the graphics format right: >> >> f = open('not_a_pdf.pdf', 'w') >> plot([1,2,3]) >> savefig(f) >> >> but it produces a PNG image. Can anybody confirm this? I am on >> matplotlib 0.99.3 >> >> Cheers, >> >> Giovanni >> >> -- >> Colocation vs. Managed Hosting >> A question and answer guide to determining the best fit >> for your organization - today and in the future. >> http://p.sf.net/sfu/internap-sfd2d >> ___ >> Matplotlib-users mailing list >> Matplotlib-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> > -- Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig not deducing file format
It has no way of deducing the file format from the file object. You need to explicitly pass the format keyword to savefig, e.g.: savefig(f, format='pdf') Mike On 03/15/2011 07:11 AM, Giovanni Luca Ciampaglia wrote: > Hi all, > I call savefig by passing to it a file-like object but it appears to not > get the graphics format right: > > f = open('not_a_pdf.pdf', 'w') > plot([1,2,3]) > savefig(f) > > but it produces a PNG image. Can anybody confirm this? I am on > matplotlib 0.99.3 > > Cheers, > > Giovanni > > -- > Colocation vs. Managed Hosting > A question and answer guide to determining the best fit > for your organization - today and in the future. > http://p.sf.net/sfu/internap-sfd2d > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- Michael Droettboom Science Software Branch Space Telescope Science Institute Baltimore, Maryland, USA -- Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle
On Sun, 6 Mar 2011 21:47:04 +0900 Jae-Joon Lee wrote: > > Ok, I can understand that, but shouldn't all artists used to construct the > > picture, as suptitle, be considered? > > I think considering all the artists is not very practical (as some of > them could have spline paths), but what we may be able to do is to > consider all the texts in the figure. I'll try to implement them. Can you describe a scenario where considering all artists may produce wrong/unintended results? Considering all texts in the figure might be a good-enough solution, but I honestly have an hard time figuring out a case where bbox_inches should ignore some elements. I come from a gnuplot/asymptote background, so my view could be biased. > > import matplotlib as mpl > > import matplotlib.figure > > import matplotlib.backends.backend_agg > > > > fig = mpl.figure.Figure() > > cvs = mpl.backends.backend_agg.FigureCanvasAgg(fig) > > fig.set_size_inches((20,20)) > > plot = fig.add_subplot(111) > > plot.set_title("Subtitle") > > plot.plot([1,2,3], [3,2,1]) > > st = fig.suptitle("Horray!", fontsize=20) > > fig.savefig("out.png", bbox_inches='tight', bbox_extra_artists=[st]) > > > > I believe you're using a matplotlib version that the > "bbox_extra_artists" keyword was not yet implemented. > Can you try to install 1.0 version of matpltolib? > As Benjamin has confirmed, this is supposed to work (with recent > version of matplotlib). > If upgrading is not possible, I'll try to come up with a workaround (I > don't think it will be done with a few lines of code though). Yes, thanks. By upgrading to 1.0, bbox_extra_artists now works. -- Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle
On Mon, 7 Mar 2011 13:41:49 -0600 Benjamin Root wrote: > > I've > > been using matplotlib a lot the last few months and was totally > > unaware that pyplot was "required". Good thing I read this message! :-) I'm glad I'm not the only one :) > > > The interface should create the figure objects, the figure objects should > > > create the axes objects, the axes objects should create the axis objects, > > > and so on and so forth. I've read the revised link you posted: https://github.com/WeatherGod/matplotlib/blob/62a02cce1ef98ff2360049ef31074bd9e82670d3/doc/faq/usage_faq.rst I think you should definitely put the above sentence, which IMHO makes the relation of pyplot (and usage of matplotlib) astoundingly clear. -- What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle
On Mon, Mar 7, 2011 at 12:42 PM, Brendan Barnwell wrote: > On 2011-03-07 08:59, Benjamin Root wrote: > > On Mon, Mar 7, 2011 at 10:33 AM, Yuri D'Elia wrote: > >> I was reading this at the time: > >> > >> http://matplotlib.sourceforge.net/faq/usage_faq.html > >> > >> I inferred pyplot was just a matlab-like interface on top of > matplotlib, > >> and figured using directly the matplotlib was acceptable. > >> > > > > Yeah, I am guessing that page is a little out-dated and could be better > > worded. However, the page does say that the preferred style is the > pyplot > > interface. Also notice that it is extremely rare for any of the > > documentation to directly create the matplotlib objects without the > pyplot > > or pylab interface. > > I think this documentation should definitely be updated, then. > I've > been using matplotlib a lot the last few months and was totally > unaware that pyplot was "required". Good thing I read this message! :-) > > > The interface should create the figure objects, the figure objects should > > create the axes objects, the axes objects should create the axis objects, > > and so on and so forth. > > That makes perfect sense, but is not at all what's implied by the > text on the page linked above. > > Best wishes, > -- > Brendan Barnwell > "Do not follow where the path may lead. Go, instead, where there is > no path, and leave a trail." >--author unknown > > Tell me what you think about this wording. Don't worry about the links on the page: https://github.com/WeatherGod/matplotlib/blob/62a02cce1ef98ff2360049ef31074bd9e82670d3/doc/faq/usage_faq.rst I greatly appreciate any further comments you have. Your perspective is invaluable for improving our docs for users like you. Ben Root -- What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle
On 2011-03-07 08:59, Benjamin Root wrote: > On Mon, Mar 7, 2011 at 10:33 AM, Yuri D'Elia wrote: >> I was reading this at the time: >> >> http://matplotlib.sourceforge.net/faq/usage_faq.html >> >> I inferred pyplot was just a matlab-like interface on top of matplotlib, >> and figured using directly the matplotlib was acceptable. >> > > Yeah, I am guessing that page is a little out-dated and could be better > worded. However, the page does say that the preferred style is the pyplot > interface. Also notice that it is extremely rare for any of the > documentation to directly create the matplotlib objects without the pyplot > or pylab interface. I think this documentation should definitely be updated, then. I've been using matplotlib a lot the last few months and was totally unaware that pyplot was "required". Good thing I read this message! :-) > The interface should create the figure objects, the figure objects should > create the axes objects, the axes objects should create the axis objects, > and so on and so forth. That makes perfect sense, but is not at all what's implied by the text on the page linked above. Best wishes, -- Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown -- What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle
On Tue, Mar 8, 2011 at 2:20 AM, Benjamin Root wrote: > And this appears to be a bug. Looks like the call signature for the legend > object's get_window_extent() doesn't match the call signature for all other > artists. > Yes. It is a bug. Meanwhile, you may use bbox_extra_artists=[leg.legendPatch] as a workaround. Regards, -JJ -- What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle
On Mon, Mar 7, 2011 at 11:09 AM, Yuri D'Elia wrote: > On Tue, 8 Mar 2011 02:03:54 +0900 > Jae-Joon Lee wrote: > > > On Mon, Mar 7, 2011 at 7:36 PM, Yuri D'Elia wrote: > > In fact, supporting the "bbox_inches" is a real hack. > > As I mentioned in my previous email, matplotlib artists can have > > spline paths. And artists can also be clipped by an arbitrary spline > > path. And, generally speaking, finding out the exact bounding box of > > an artist is difficult (but I must confess that I'm not an expert on > > this field and any correction or advise will be appreciated). I > > believe the AGG library, that matplotlib is based on, can provide an > > approximate bounding box for spline paths, but I'm not sure if it will > > work when clipping is involved (at least, the *get_window_extent* > > does not properly work when clipping is involved). > > I see. But can't you simply skip spline paths from the calculation? > This would remove the need for bbox_extra_artists for 99% of the cases. > > > I'll consider to support all artists in a "tight" bbox mode if > > *get_window_extent* gives back exact bounding box (accounting the > > clipping) for "all" artists. Otherwise, I'm not inclined to do this. > > I don't know if you read this already, but: all artists should at least > work with bbox_extra_artists, right? > > While placing the legend outside the plot I tried the following: > > egend = plot.legend() > pic.savefig(..., bbox_extra_artists=[legend]) > > but it fails: > > Traceback (most recent call last): > File "./plot.py", line 108, in > fig.savefig(sys.argv[1], bbox_inches='tight', bbox_extra_artists=xa) > File "/usr/lib/pymodules/python2.6/matplotlib/figure.py", line 1084, in > savefig >self.canvas.print_figure(*args, **kwargs) > File "/usr/lib/pymodules/python2.6/matplotlib/backend_bases.py", line > 1894, in print_figure >in kwargs.pop("bbox_extra_artists", [])] > TypeError: get_window_extent() takes exactly 1 argument (2 given) > > And this appears to be a bug. Looks like the call signature for the legend object's get_window_extent() doesn't match the call signature for all other artists. I will write up a patch for this. Ben Root -- What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle
On Tue, 8 Mar 2011 02:03:54 +0900 Jae-Joon Lee wrote: > On Mon, Mar 7, 2011 at 7:36 PM, Yuri D'Elia wrote: > In fact, supporting the "bbox_inches" is a real hack. > As I mentioned in my previous email, matplotlib artists can have > spline paths. And artists can also be clipped by an arbitrary spline > path. And, generally speaking, finding out the exact bounding box of > an artist is difficult (but I must confess that I'm not an expert on > this field and any correction or advise will be appreciated). I > believe the AGG library, that matplotlib is based on, can provide an > approximate bounding box for spline paths, but I'm not sure if it will > work when clipping is involved (at least, the *get_window_extent* > does not properly work when clipping is involved). I see. But can't you simply skip spline paths from the calculation? This would remove the need for bbox_extra_artists for 99% of the cases. > I'll consider to support all artists in a "tight" bbox mode if > *get_window_extent* gives back exact bounding box (accounting the > clipping) for "all" artists. Otherwise, I'm not inclined to do this. I don't know if you read this already, but: all artists should at least work with bbox_extra_artists, right? While placing the legend outside the plot I tried the following: egend = plot.legend() pic.savefig(..., bbox_extra_artists=[legend]) but it fails: Traceback (most recent call last): File "./plot.py", line 108, in fig.savefig(sys.argv[1], bbox_inches='tight', bbox_extra_artists=xa) File "/usr/lib/pymodules/python2.6/matplotlib/figure.py", line 1084, in savefig self.canvas.print_figure(*args, **kwargs) File "/usr/lib/pymodules/python2.6/matplotlib/backend_bases.py", line 1894, in print_figure in kwargs.pop("bbox_extra_artists", [])] TypeError: get_window_extent() takes exactly 1 argument (2 given) -- What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle
On Mon, Mar 7, 2011 at 7:36 PM, Yuri D'Elia wrote: > I consider bbox_extra_artists some kind of a hack (IMHO, all artists should > be considered with a 'tight' box), but coming from gnuplot/asymptote maybe my > point of view is biased. > What would be the point of a 'tight' box that excludes parts of the plot? I > would specify the coordinates myself if I needed clipping. > In fact, supporting the "bbox_inches" is a real hack. As I mentioned in my previous email, matplotlib artists can have spline paths. And artists can also be clipped by an arbitrary spline path. And, generally speaking, finding out the exact bounding box of an artist is difficult (but I must confess that I'm not an expert on this field and any correction or advise will be appreciated). I believe the AGG library, that matplotlib is based on, can provide an approximate bounding box for spline paths, but I'm not sure if it will work when clipping is involved (at least, the *get_window_extent* does not properly work when clipping is involved). I'll consider to support all artists in a "tight" bbox mode if *get_window_extent* gives back exact bounding box (accounting the clipping) for "all" artists. Otherwise, I'm not inclined to do this. Regards, -JJ -- What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle
On Mon, Mar 7, 2011 at 10:33 AM, Yuri D'Elia wrote: > On Mon, 7 Mar 2011 09:25:23 -0600 > Benjamin Root wrote: > > > The problem is that you are creating your figure wrong. Try this: > > > > import matplotlib as mpl > > mpl.use("Agg") > > import matplotlib.pyplot as plt > > > > fig = plt.figure(figsize=(20, 20)) > > ax = fig.add_subplot(111) > > ax.set_title("Subtitle") > > ax.plot([1, 2, 3], [3, 2, 1]) > > st = fig.suptitle("Horray!", fontsize=20) > > fig.savefig("out.png", bbox_inches='tight', bbox_extra_artists=[st]) > > > > Notice that I am using the pyplot interface. Matplotlib was intended to > be > > used through either this pyplot interface or the pylab interface (which I > do > > not personally recommend if you want full control over your plots). If > you > > don't use either interfaces, then don't be surprised when things do not > work > > properly. In particular, creating the figure object by directly calling > the > > Figure constructor bypasses important steps that involves attaching the > > appropriate backend to the figure object. > > I was reading this at the time: > > http://matplotlib.sourceforge.net/faq/usage_faq.html > > I inferred pyplot was just a matlab-like interface on top of matplotlib, > and figured using directly the matplotlib was acceptable. > Yeah, I am guessing that page is a little out-dated and could be better worded. However, the page does say that the preferred style is the pyplot interface. Also notice that it is extremely rare for any of the documentation to directly create the matplotlib objects without the pyplot or pylab interface. The pointof the statement "MATLAB-like" is that most of the plotting functions available in MATLAB are also available in matplotlib. In addition, the phrase "more MATLAB-like" is meant to state that various mathematical functions are made available as well. This was designed to make transitions from MATLAB to matplotlib easier for the user. Ultimately, we desire that the user transitions completely over to the pyplot interface. Note that this has nothing to do with interactivity or proceedural. If anything, pylab was more intended for interactivity because its syntax is more concise, but you lose a lot of control. > Reading the documentation of the single objects of matplotlib was enough to > get me started. I see pyplot as having more shortcuts for common operations, > but I was unsure how far can I could go by using pyplot only. > > Think of it this way. Matplotlib depends a lot upon hierarchical design. The pyplot (or pylab) interfaces sit on top of that heirarchy and represents the matplotlib environment. This environment creates figures. These figures can many components, the most important of which are one or more axes objects. Each axes object has two or more axis objects and are responsible for plotting themselves. While there are some convenience functions through pyplot for doing some things like setting an axis label, it is not required to use pyplot for that. You can (and often should) use the axes object's method for doing so. The point is that you can use the matplotlib objects for a lot of things, and it is great that you are embracing the object oriented nature of matplotlib. However, your problem was caused by-passing the hierarchy: The interface should create the figure objects, the figure objects should create the axes objects, the axes objects should create the axis objects, and so on and so forth. I hope that makes it clearer for you, and I hope you continue to use matplotlib and find it useful! Ben Root -- What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle
On Mon, 7 Mar 2011 09:25:23 -0600 Benjamin Root wrote: > The problem is that you are creating your figure wrong. Try this: > > import matplotlib as mpl > mpl.use("Agg") > import matplotlib.pyplot as plt > > fig = plt.figure(figsize=(20, 20)) > ax = fig.add_subplot(111) > ax.set_title("Subtitle") > ax.plot([1, 2, 3], [3, 2, 1]) > st = fig.suptitle("Horray!", fontsize=20) > fig.savefig("out.png", bbox_inches='tight', bbox_extra_artists=[st]) > > Notice that I am using the pyplot interface. Matplotlib was intended to be > used through either this pyplot interface or the pylab interface (which I do > not personally recommend if you want full control over your plots). If you > don't use either interfaces, then don't be surprised when things do not work > properly. In particular, creating the figure object by directly calling the > Figure constructor bypasses important steps that involves attaching the > appropriate backend to the figure object. I was reading this at the time: http://matplotlib.sourceforge.net/faq/usage_faq.html I inferred pyplot was just a matlab-like interface on top of matplotlib, and figured using directly the matplotlib was acceptable. Reading the documentation of the single objects of matplotlib was enough to get me started. I see pyplot as having more shortcuts for common operations, but I was unsure how far can I could go by using pyplot only. Generally, I didn't have any trouble. The includes are a bit verbose, but that's it. > Also notice that I name the object coming from add_subplot() "ax" instead of > "plot". This is for clarity and to avoid confusion with the command > "plot". This is also the generally accepted coding convention in > matplotlib. Indeed, thanks for the remark. Thanks again for your comments. -- What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle
On Mon, Mar 7, 2011 at 4:36 AM, Yuri D'Elia wrote: > On Fri, 4 Mar 2011 14:57:34 -0600 > Benjamin Root wrote: > > > Which version of matplotlib are you using? This example works for me > using > > the latest matplotlib from source. Also, why the awkward usage and > > Yes, with matplotlib 1.0 bbox_extra_artists now works. > > I consider bbox_extra_artists some kind of a hack (IMHO, all artists should > be considered with a 'tight' box), but coming from gnuplot/asymptote maybe > my point of view is biased. > What would be the point of a 'tight' box that excludes parts of the plot? I > would specify the coordinates myself if I needed clipping. > > > imports? If you want to force the Agg backend to be used, you could just > > do: > > > > import matplotlib > > matplotlib.use("Agg") > > > > before any other matplotlib imports. > > Thanks for the suggestion, that looks promising, but doesn't work: > > > import matplotlib as mpl > mpl.use("Agg") > import matplotlib.figure > fig = mpl.figure.Figure() > fig.set_size_inches((20,20)) > plot = fig.add_subplot(111) > plot.set_title("Subtitle") > plot.plot([1,2,3], [3,2,1]) > st = fig.suptitle("Horray!", fontsize=20) > fig.savefig("out.png", bbox_inches='tight', bbox_extra_artists=[st]) > > > The problem is that you are creating your figure wrong. Try this: import matplotlib as mpl mpl.use("Agg") import matplotlib.pyplot as plt fig = plt.figure(figsize=(20, 20)) ax = fig.add_subplot(111) ax.set_title("Subtitle") ax.plot([1, 2, 3], [3, 2, 1]) st = fig.suptitle("Horray!", fontsize=20) fig.savefig("out.png", bbox_inches='tight', bbox_extra_artists=[st]) Notice that I am using the pyplot interface. Matplotlib was intended to be used through either this pyplot interface or the pylab interface (which I do not personally recommend if you want full control over your plots). If you don't use either interfaces, then don't be surprised when things do not work properly. In particular, creating the figure object by directly calling the Figure constructor bypasses important steps that involves attaching the appropriate backend to the figure object. Also notice that I name the object coming from add_subplot() "ax" instead of "plot". This is for clarity and to avoid confusion with the command "plot". This is also the generally accepted coding convention in matplotlib. > > I find the documentation a bit scattered around this subject. > I'm not using the pyplot interface, so I guess that .use("Agg") doesn't do > anything for me? > I also have no reason to use the pyplot interface, why should I? I have no > matlab background, and I mostly use matplotlib procedurally (ie not > interactively). > The only accepted ways to use matplotlib are through either the pyplot or the pylab interfaces. This is why they are called interfaces. It does not matter if you are using matplotlib interactively or procedurally. I personally use the pyplot interface in all of my scripts, as I rarely ever do interactive plotting. The pylab interface is more geared towards interactive plotting. These interfaces are designed to make your life easier. Think of it this way. The developers can make many changes to matplotlib internals from one release to the next, but we do our best to make the interface as stable as possible. If you write code that do not utilize the pylab or pyplot interfaces, then your scripts will likely break at the next release. Trust me, a lot of your problems will be solved by picking an interface (I recommend pyplot) and sticking with it. I hope this is helpful, Ben Root -- What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle
On Mon, 7 Mar 2011 11:36:45 +0100 Yuri D'Elia wrote: > On Fri, 4 Mar 2011 14:57:34 -0600 > Benjamin Root wrote: > > > Which version of matplotlib are you using? This example works for me using > > the latest matplotlib from source. Also, why the awkward usage and > > Yes, with matplotlib 1.0 bbox_extra_artists now works. Just out of curiosity, is this: legend = plot.legend() pic.savefig(..., bbox_extra_artists=[legend]) supposed to work? Traceback (most recent call last): File "./plot.py", line 108, in fig.savefig(sys.argv[1], bbox_inches='tight', bbox_extra_artists=xa) File "/usr/lib/pymodules/python2.6/matplotlib/figure.py", line 1084, in savefig self.canvas.print_figure(*args, **kwargs) File "/usr/lib/pymodules/python2.6/matplotlib/backend_bases.py", line 1894, in print_figure in kwargs.pop("bbox_extra_artists", [])] TypeError: get_window_extent() takes exactly 1 argument (2 given) -- What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle
On Fri, 4 Mar 2011 14:57:34 -0600 Benjamin Root wrote: > Which version of matplotlib are you using? This example works for me using > the latest matplotlib from source. Also, why the awkward usage and Yes, with matplotlib 1.0 bbox_extra_artists now works. I consider bbox_extra_artists some kind of a hack (IMHO, all artists should be considered with a 'tight' box), but coming from gnuplot/asymptote maybe my point of view is biased. What would be the point of a 'tight' box that excludes parts of the plot? I would specify the coordinates myself if I needed clipping. > imports? If you want to force the Agg backend to be used, you could just > do: > > import matplotlib > matplotlib.use("Agg") > > before any other matplotlib imports. Thanks for the suggestion, that looks promising, but doesn't work: import matplotlib as mpl mpl.use("Agg") import matplotlib.figure fig = mpl.figure.Figure() fig.set_size_inches((20,20)) plot = fig.add_subplot(111) plot.set_title("Subtitle") plot.plot([1,2,3], [3,2,1]) st = fig.suptitle("Horray!", fontsize=20) fig.savefig("out.png", bbox_inches='tight', bbox_extra_artists=[st]) produces: Traceback (most recent call last): File "test.py", line 13, in fig.savefig("out.png", bbox_inches='tight', bbox_extra_artists=[st]) File "/usr/lib/pymodules/python2.6/matplotlib/figure.py", line 1084, in savefig self.canvas.print_figure(*args, **kwargs) AttributeError: 'NoneType' object has no attribute 'print_figure' I find the documentation a bit scattered around this subject. I'm not using the pyplot interface, so I guess that .use("Agg") doesn't do anything for me? I also have no reason to use the pyplot interface, why should I? I have no matlab background, and I mostly use matplotlib procedurally (ie not interactively). -- What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle
On Wed, Mar 2, 2011 at 8:46 AM, Yuri D'Elia wrote: > > > > On Wed, 2 Mar 2011 22:01:02 +0900 > Jae-Joon Lee wrote: > > > >> > Is this a bug? > > >> > > >> Unfortunately, bbox_inches option is never meant to be complete in > > >> figuring out the exact size of the figure area. > > > > > > Why not? What's the purpose of bbox_inches='tight' otherwise? > > > > Figuring out enclosing bbox when arbitrary spline paths are involved > > is difficult (I think there is no exact solution). So I only intended > > to support common cases. > > Ok, I can understand that, but shouldn't all artists used to construct the > picture, as suptitle, be considered? > > > >> However, you can use "bbox_extra_artists" keyword argument to specify > > >> additional artists that should be considered when dertermining the > > >> plot size. > > >> > > >> mytitle = fig.suptitle("Horray!", fontsize=20) > > >> > > >> ... > > >> > > >> fig.savefig("out.png", bbox_inches='tight', > bbox_extra_artists=[mytitle]) > > > > > > That doesn't work for me either. > > > > Can you be more specific? Does it throw an exception? Or the code runs > > without any error but the output is still wrong? > > No error/exception are produced. The output is simply identical to the one > without bbox_extra_artists. > > This also works in my previous example: > > import matplotlib as mpl > import matplotlib.figure > import matplotlib.backends.backend_agg > > fig = mpl.figure.Figure() > cvs = mpl.backends.backend_agg.FigureCanvasAgg(fig) > fig.set_size_inches((20,20)) > plot = fig.add_subplot(111) > plot.set_title("Subtitle") > plot.plot([1,2,3], [3,2,1]) > st = fig.suptitle("Horray!", fontsize=20) > fig.savefig("out.png", bbox_inches='tight', bbox_extra_artists=[st]) > > Which version of matplotlib are you using? This example works for me using the latest matplotlib from source. Also, why the awkward usage and imports? If you want to force the Agg backend to be used, you could just do: import matplotlib matplotlib.use("Agg") before any other matplotlib imports. Ben Root -- What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle
On Wed, 2 Mar 2011 22:01:02 +0900 Jae-Joon Lee wrote: > >> > Is this a bug? > >> > >> Unfortunately, bbox_inches option is never meant to be complete in > >> figuring out the exact size of the figure area. > > > > Why not? What's the purpose of bbox_inches='tight' otherwise? > > Figuring out enclosing bbox when arbitrary spline paths are involved > is difficult (I think there is no exact solution). So I only intended > to support common cases. Ok, I can understand that, but shouldn't all artists used to construct the picture, as suptitle, be considered? > >> However, you can use "bbox_extra_artists" keyword argument to specify > >> additional artists that should be considered when dertermining the > >> plot size. > >> > >> mytitle = fig.suptitle("Horray!", fontsize=20) > >> > >> ... > >> > >> fig.savefig("out.png", bbox_inches='tight', bbox_extra_artists=[mytitle]) > > > > That doesn't work for me either. > > Can you be more specific? Does it throw an exception? Or the code runs > without any error but the output is still wrong? No error/exception are produced. The output is simply identical to the one without bbox_extra_artists. This also works in my previous example: import matplotlib as mpl import matplotlib.figure import matplotlib.backends.backend_agg fig = mpl.figure.Figure() cvs = mpl.backends.backend_agg.FigureCanvasAgg(fig) fig.set_size_inches((20,20)) plot = fig.add_subplot(111) plot.set_title("Subtitle") plot.plot([1,2,3], [3,2,1]) st = fig.suptitle("Horray!", fontsize=20) fig.savefig("out.png", bbox_inches='tight', bbox_extra_artists=[st]) -- What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle
On Tue, 1 Mar 2011 12:44:20 +0900 Jae-Joon Lee wrote: > > Is this a bug? > > Unfortunately, bbox_inches option is never meant to be complete in > figuring out the exact size of the figure area. Why not? What's the purpose of bbox_inches='tight' otherwise? > However, you can use "bbox_extra_artists" keyword argument to specify > additional artists that should be considered when dertermining the > plot size. > > mytitle = fig.suptitle("Horray!", fontsize=20) > > ... > > fig.savefig("out.png", bbox_inches='tight', bbox_extra_artists=[mytitle]) That doesn't work for me either. -- Free Software Download: Index, Search & Analyze Logs and other IT data in Real-Time with Splunk. Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. http://p.sf.net/sfu/splunk-dev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle
On Fri, Feb 25, 2011 at 9:15 PM, Yuri D'Elia wrote: > In the following: > > <<< > import matplotlib as mpl > import matplotlib.figure > import matplotlib.backends.backend_agg > > fig = mpl.figure.Figure() > cvs = mpl.backends.backend_agg.FigureCanvasAgg(fig) > fig.set_size_inches((20,20)) > fig.suptitle("Horray!", fontsize=20) > plot = fig.add_subplot(111) > plot.set_title("Subtitle") > plot.plot([1,2,3], [3,2,1]) > fig.savefig("out.png", bbox_inches='tight') > > suptitle is stripped from the figure. > Of course the title is present if you unset bbox_inches, but that's > unexpected behavior for me. > > Is this a bug? Unfortunately, bbox_inches option is never meant to be complete in figuring out the exact size of the figure area. However, you can use "bbox_extra_artists" keyword argument to specify additional artists that should be considered when dertermining the plot size. mytitle = fig.suptitle("Horray!", fontsize=20) ... fig.savefig("out.png", bbox_inches='tight', bbox_extra_artists=[mytitle]) Regards, -JJ > > Thanks > > > -- > Free Software Download: Index, Search & Analyze Logs and other IT data in > Real-Time with Splunk. Collect, index and harness all the fast moving IT data > generated by your applications, servers and devices whether physical, virtual > or in the cloud. Deliver compliance at lower cost and gain new business > insights. http://p.sf.net/sfu/splunk-dev2dev > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- Free Software Download: Index, Search & Analyze Logs and other IT data in Real-Time with Splunk. Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. http://p.sf.net/sfu/splunk-dev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig eps error
alex arsenovic writes: > the main error is > > Error: /nocurrentpoint in --lineto-- Sounds like this bug: http://sourceforge.net/tracker/index.php?func=detail&aid=2879910&group_id=80706&atid=560720 It's fixed in svn, but I don't think there has been a release after the fix. One way to test if it is indeed the same bug is to apply the following change (svn revision 7899) and try saving a pdf file - it should exit with an error. Index: lib/matplotlib/backends/backend_pdf.py === --- lib/matplotlib/backends/backend_pdf.py (revision 7898) +++ lib/matplotlib/backends/backend_pdf.py (revision 7899) @@ -1206,8 +1206,12 @@ last_points = None for points, code in path.iter_segments(transform, clip=clip): if code == Path.MOVETO: +# This is allowed anywhere in the path cmds.extend(points) cmds.append(Op.moveto) +elif last_points is None: +# The other operations require a previous point +raise ValueError, 'Path lacks initial MOVETO' elif code == Path.LINETO: cmds.extend(points) cmds.append(Op.lineto) If it is the same bug, revision 7900 (attached) should fix it, but that requires recompilation and not just patching python files. Index: src/path_converters.h === --- src/path_converters.h (revision 7899) +++ src/path_converters.h (revision 7900) @@ -684,9 +684,15 @@ { if (m_origdNorm2 != 0.0) { -queue_push(agg::path_cmd_line_to, m_nextX, m_nextY); +queue_push((m_moveto || m_after_moveto) ? + agg::path_cmd_move_to : agg::path_cmd_line_to, + m_nextX, m_nextY); +m_moveto = false; } -queue_push(agg::path_cmd_line_to, m_lastx, m_lasty); +queue_push((m_moveto || m_after_moveto) ? + agg::path_cmd_move_to : agg::path_cmd_line_to, + m_lastx, m_lasty); +m_moveto = false; queue_push(agg::path_cmd_stop, 0.0, 0.0); } Index: lib/matplotlib/tests/test_simplification.py === --- lib/matplotlib/tests/test_simplification.py (revision 7899) +++ lib/matplotlib/tests/test_simplification.py (revision 7900) @@ -2,11 +2,10 @@ import matplotlib from matplotlib.testing.decorators import image_comparison, knownfailureif import matplotlib.pyplot as plt -from matplotlib import patches, path from pylab import * import numpy as np -from matplotlib import patches, path +from matplotlib import patches, path, transforms nan = np.nan Path = path.Path @@ -134,6 +133,38 @@ assert len(simplified) == 13 +def test_start_with_moveto(): +# Should be entirely clipped away to a single MOVETO +data = """ +Zwku+v9UAQAA+Tj6/z8CAADpQ/r/KAMAANlO+v8QBAAAyVn6//UEAAC6ZPr/2gUAAKpv+v+8 +BgAAm3r6/50HAACLhfr/ewgAAHyQ+v9ZCQAAbZv6/zQKAABepvr/DgsAAE+x+v/lCwAAQLz6/7wM +AAAxx/r/kA0AACPS+v9jDgAAFN36/zQPAAAF6Pr/AxAAAPfy+v/QEAAA6f36/5wRAADbCPv/ZhIA +AMwT+/8uEwAAvh77//UTAACwKfv/uRQAAKM0+/98FQAAlT/7/z0WAACHSvv//RYAAHlV+/+7FwAA +bGD7/3cYAABea/v/MRkAAFF2+//pGQAARIH7/6AaAAA3jPv/VRsAACmX+/8JHAAAHKL7/7ocAAAP +rfv/ah0AAAO4+/8YHgAA9sL7/8QeAADpzfv/bx8AANzY+/8YIAAA0OP7/78gAADD7vv/ZCEAALf5 ++/8IIgAAqwT8/6kiAACeD/z/SiMAAJIa/P/oIwAAhiX8/4QkAAB6MPz/HyUAAG47/P+4JQAAYkb8 +/1AmAABWUfz/5SYAAEpc/P95JwAAPmf8/wsoAAAzcvz/nCgAACd9/P8qKQAAHIj8/7cpAAAQk/z/ +QyoAAAWe/P/MKgAA+aj8/1QrAADus/z/2isAAOO+/P9eLAAA2Mn8/+AsAADM1Pz/YS0AAMHf/P/g +LQAAtur8/10uAACr9fz/2C4AAKEA/f9SLwAAlgv9/8ovAACLFv3/QDAAAIAh/f+1MAAAdSz9/ycx +AABrN/3/mDEAAGBC/f8IMgAAVk39/3UyAABLWP3/4TIAAEFj/f9LMwAANm79/7MzAAAsef3/GjQA +ACKE/f9+NAAAF4/9/+E0AAANmv3/QzUAAAOl/f+iNQAA+a/9/wA2AADvuv3/XDYAAOXF/f+2NgAA +29D9/w83AADR2/3/ZjcAAMfm/f+7NwAAvfH9/w44AACz/P3/XzgAAKkH/v+vOAAAnxL+//04AACW +Hf7/SjkAAIwo/v+UOQAAgjP+/905AAB5Pv7/JDoAAG9J/v9pOgAAZVT+/606AABcX/7/7zoAAFJq +/v8vOwAASXX+/207AAA/gP7/qjsAADaL/v/lOwAALZb+/x48AAAjof7/VTwAABqs/v+LPAAAELf+ +/788AAAHwv7/8TwAAP7M/v8hPQAA9df+/1A9AADr4v7/fT0AAOLt/v+oPQAA2fj+/9E9AADQA/// ++T0AAMYO//8fPgAAvRn//0M+AAC0JP//ZT4AAKsv//+GPgAAojr//6U+AACZRf//wj4AAJBQ///d +PgAAh1v///c+AAB+Zv//Dz8AAHRx//8lPwAAa3z//zk/AABih///TD8AAFmS//9dPwAAUJ3//2w/ +AABHqP//ej8AAD6z//+FPwAANb7//48/AAAsyf//lz8AACPU//+ePwAAGt///6M/AAAR6v//pj8A +AAj1//+nPwAA/w==""" + +verts = np.fromstring(data.decode('base64'), dtype=' -- Jouni K. Seppänen http://www.iki.fi/jks -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig Memory Leak
Hello Michael, I have not tried using plt.figure() and plt.close(fig) but you are right; I should investigate it as well for completeness. I had, actually, purposefully avoided doing this because I read that the pyplot API is stateful. It keeps references to figures in the same way that MatLab does and these figures need to be explicitly closed (via plt.close). By calling Figure(...) directly I am trying to use matplotlib's object-oriented API and avoid pyplot's statefullness. Something interesting and perhaps enlightening is to switch backends from Agg to something else (say Cairo). In the demonstration script that I posted you would do so like this: #from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.backends.backend_cairo import FigureCanvasCairo as FigureCanvas When using the Cairo backend the memory leak disappears. In my mind, this indicates a memory leak when using the Agg backend that DOES NOT appear when using the Cairo backend. Thanks for the advice; I will give pyplot a try and see if I get different behaviour. Sincerely, Keegan Callin On 04/19/2010 11:28 AM, K.-Michael Aye wrote: > Could you try to use figure() instead of Figure()? That often creates a > mess on my side. > Or should one use Figure() in the 'Artist's style? I am still importing > pyplot as plt, and in that case, I have to use figure(), otherwise > things don't work. > > I also had the feeling of a leak and am currently doing this without > much 'leaking': :) > > fig = plt.figure() > ax = fig.add_subplot(111) > im = ax.imshow(nData) > cb = plt.colorbar(im) > ax.set_title(bname + ', ' + mode) > fig.savefig(filename + '.equal.png') > plt.close(fig) > > I think, the plt.close(fig) was quite important in my case. > Give it a try! > -- Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig Memory Leak
On 2010-04-16 19:18:56 +0200, Keegan Callin said: > Hello, > > I have written a small script that, I think, demonstrates a memory leak > in savefig. A search of the mailing list shows a thread started by Ralf > Gommers about > 2009-07-01 that seems to > cover a very similar issue. I have appended the demonstration script at > the end of this e-mail text. > > [kee...@grizzly ~]$ python2.6 > Python 2.6.4 (r264:75706, Jan 20 2010, 12:34:05) > [GCC 4.4.2 20091222 (Red Hat 4.4.2-20)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import matplotlib > >>> matplotlib.__version__ > '0.99.1.1' > ''' > # Import standard python modules > import sys > import os > from ConfigParser import SafeConfigParser as ConfigParser > from cStringIO import StringIO > > # import numpy > import numpy > from numpy import zeros > > # Import matplotlib > from matplotlib.figure import Figure > from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas > > > def build_figure(a): > '''Returns a new figure containing array a.''' > > # Create figure and setup graph > fig = Figure() Could you try to use figure() instead of Figure()? That often creates a mess on my side. Or should one use Figure() in the 'Artist's style? I am still importing pyplot as plt, and in that case, I have to use figure(), otherwise things don't work. I also had the feeling of a leak and am currently doing this without much 'leaking': :) fig = plt.figure() ax = fig.add_subplot(111) im = ax.imshow(nData) cb = plt.colorbar(im) ax.set_title(bname + ', ' + mode) fig.savefig(filename + '.equal.png') plt.close(fig) I think, the plt.close(fig) was quite important in my case. Give it a try! Best regards, Michael -- Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig 0.91
Samuel Teixeira Santos wrote: > I fix it. > > It was a dumb error > > I using '\' on windows > and on ubuntu-linux I must use '/'... note that '\' works in Windows for the most part. Or, better yet, use os.path.join() and friends. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov -- Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig 0.91
I fix it. It was a dumb error I using '\' on windows and on ubuntu-linux I must use '/'... sorry... and thanks 2010/3/16 Michael Droettboom > Can you please post the entire traceback? > > Mike > > Samuel Teixeira Santos wrote: > >> Hi folks >> >> I'm using ubuntu 8.04 lts and matplotlib 0.91 >> >> I cannot upgrade in this moment. >> >> On my app (for web) I fix several errors (because I did her in 0.99) >> >> My last error (I think it is) is on savefig >> >> It tells me that cannot open file >> >> on log error, appears on write_png method. >> >> Is this permission on directory? or a bug? >> >> >> thanks in advanced >> >> >> >> -- >> Download Intel® Parallel Studio Eval >> Try the new software tools for yourself. Speed compiling, find bugs >> proactively, and fine-tune applications for parallel performance. >> See why Intel Parallel Studio got high marks during beta. >> http://p.sf.net/sfu/intel-sw-dev >> >> >> ___ >> Matplotlib-users mailing list >> Matplotlib-users@lists.sourceforge.net >> 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 > > -- Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig 0.91
Can you please post the entire traceback? Mike Samuel Teixeira Santos wrote: > Hi folks > > I'm using ubuntu 8.04 lts and matplotlib 0.91 > > I cannot upgrade in this moment. > > On my app (for web) I fix several errors (because I did her in 0.99) > > My last error (I think it is) is on savefig > > It tells me that cannot open file > > on log error, appears on write_png method. > > Is this permission on directory? or a bug? > > > thanks in advanced > > > -- > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > > > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > 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 -- Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig as pdf not generating vector graphics?
--- On Sun, 6/28/09, Jouni K. Seppänen wrote: > The file you sent was not generated by the pdf backend but > by "Mac OS X 10.5.6 Quartz PDFContext", which probably means > that the OS X backend saves pdf files using the OS X machinery > and not the pdf backend. Indeed the formulas look like bitmaps. Previously the Mac OS X backend indeed used its own machinery to create PDF files. Recent versions of the backend in SVN, however, use matplotlib's pdf backend. So the problem should go away if you use matplotlib from SVN. The Mac OS X backend itself can actually be fixed to use vector graphics on screen instead of bitmaps. That will need some time, but I'll get round to it one of these weeks. --Michiel. -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig as pdf not generating vector graphics?
per freem writes: > you're right, i don't need to use "usetex" -- i removed it, but the problem > still persists. here is the pdf that it generates (code below). any idea > what is happening here? thanks very much for your help. The file you sent was not generated by the pdf backend but by "Mac OS X 10.5.6 Quartz PDFContext", which probably means that the OS X backend saves pdf files using the OS X machinery and not the pdf backend. Indeed the formulas look like bitmaps. > from scipy import * > import matplotlib.pyplot as plt > from matplotlib import rc > rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']}) > import matplotlib > matplotlib.use('PDF') You are trying to use the pdf backend, but the last line quoted above has no effect because you have already imported pyplot, which causes the backend to be set as directed by your matplotlibrc file. Any call to matplotlib.use needs to be done before you import pyplot. -- Jouni K. Seppänen http://www.iki.fi/jks -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig as pdf not generating vector graphics?
per freem writes: > i am using matplotlib 0.98.5.2 on Mac OS X. i am plotting a histogram > and then saving it as .pdf. The x and y labels use some symbols from > latex, and i have useTex set to true in my rcParams. Do you really need usetex? Matplotlib's usual mathtext engine is pretty good and doesn't require any external programs. > The problem is that myfig.pdf for some reason renders the figure's x > and y labels as *images* rather than vector graphics. Could you send the resulting pdf file to me off-list? -- Jouni K. Seppänen http://www.iki.fi/jks -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig behaviour with transparent patches
On Mon, Jun 1, 2009 at 4:37 PM, Kurt Forrester wrote: > > I am searched the mailing list and web without success with this problem. I > am getting unexpected behaviour when using savefig in the eps format. PS/EPS do not support alpha transparency. This is not a limitation of mpl, but of the format. You will need to use SVG or PDF if you need a vector output that supports transparency. JDH -- OpenSolaris 2009.06 is a cutting edge operating system for enterprises looking to deploy the next generation of Solaris that includes the latest innovations from Sun and the OpenSource community. Download a copy and enjoy capabilities such as Networking, Storage and Virtualization. Go to: http://p.sf.net/sfu/opensolaris-get ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bug
It works great now - thanks for fixing this! Thomas On Apr 23, 2009, at 10:29 AM, Michael Droettboom wrote: > I think Jae-Joon's assesment is correct, since the logical dpi in PS > is hardcoded to 72.0. I have made this change in the SVN repository. > > Mike > > Thomas Robitaille wrote: >> Thanks for your quick reply! >> >> I'll be patient and wait for the fix to be made in the SVN >> repository, rather than trying to patch it myself. Do I need to >> add any information to the bug report? >> >> Best, >> >> Thomas >> >> On Apr 21, 2009, at 1:06 PM, Jae-Joon Lee wrote: >> >> >>> I can reproduce this bug with the current svn. >>> >>> It works correctly If you set dpi=72, but it seems that it would not >>> be an option in your case. >>> >>> It seems to me that this is related with the change in r6847 that >>> Michael made. >>> >>> http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/backends/backend_ps.py?r1=6734&r2=6847 >>> >>> At line 431 of the backend_ps.py, >>> >>>clip = (0.0, 0.0, self.width * self.imagedpi, >>> self.height * self.imagedpi) >>> >>> I think we should use the dpi of the figure, instead of the imagedpi >>> of the renderer. >>> Replacing self.imagedpi with 72 (which is the dpi of the figure when >>> ps backend is used) seems to solve the problem. >>> >>> Thomas, I don't see any easy workaround for this bug other than >>> patching the code. Others may have better insight though. >>> >>> Regards, >>> >>> -JJ >>> >>> >>> >>> On Tue, Apr 21, 2009 at 9:59 AM, Thomas Robitaille >>> wrote: >>> Hi, I've come across a bug with the savefig method when using the dpi= argument and saving an EPS file. If you try the following code, you will see that the frame is incomplete. Is there a way to solve this from a user point of view? --- import matplotlib matplotlib.use('Agg') from matplotlib.pyplot import * import numpy as np nx,ny = 10,10 image = np.random.random((nx,ny)) fig = figure(figsize=(4,4)) ax = fig.add_subplot(111) ax.imshow(image,interpolation='nearest') fig.savefig('plot.eps',dpi=30) --- I've submitted a bug report: https://sourceforge.net/tracker/?func=detail&aid=2777476&group_id=80706&atid=560720 Thanks, Thomas -- Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> >> >> -- >> Stay on top of everything new and different, both inside and around >> Java (TM) technology - register by April 22, and save >> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. >> 300 plus technical and hands-on sessions. Register today. Use >> priority code J9JMT32. http://p.sf.net/sfu/p >> ___ >> Matplotlib-users mailing list >> Matplotlib-users@lists.sourceforge.net >> 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 > -- Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensign option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bug
I think Jae-Joon's assesment is correct, since the logical dpi in PS is hardcoded to 72.0. I have made this change in the SVN repository. Mike Thomas Robitaille wrote: > Thanks for your quick reply! > > I'll be patient and wait for the fix to be made in the SVN repository, > rather than trying to patch it myself. Do I need to add any > information to the bug report? > > Best, > > Thomas > > On Apr 21, 2009, at 1:06 PM, Jae-Joon Lee wrote: > > >> I can reproduce this bug with the current svn. >> >> It works correctly If you set dpi=72, but it seems that it would not >> be an option in your case. >> >> It seems to me that this is related with the change in r6847 that >> Michael made. >> >> http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/backends/backend_ps.py?r1=6734&r2=6847 >> >> At line 431 of the backend_ps.py, >> >> clip = (0.0, 0.0, self.width * self.imagedpi, >> self.height * self.imagedpi) >> >> I think we should use the dpi of the figure, instead of the imagedpi >> of the renderer. >> Replacing self.imagedpi with 72 (which is the dpi of the figure when >> ps backend is used) seems to solve the problem. >> >> Thomas, I don't see any easy workaround for this bug other than >> patching the code. Others may have better insight though. >> >> Regards, >> >> -JJ >> >> >> >> On Tue, Apr 21, 2009 at 9:59 AM, Thomas Robitaille >> wrote: >> >>> Hi, >>> >>> I've come across a bug with the savefig method when using the dpi= >>> argument and saving an EPS file. If you try the following code, you >>> will see that the frame is incomplete. Is there a way to solve this >>> from a user point of view? >>> >>> --- >>> >>> import matplotlib >>> matplotlib.use('Agg') >>> from matplotlib.pyplot import * >>> >>> import numpy as np >>> >>> nx,ny = 10,10 >>> >>> image = np.random.random((nx,ny)) >>> >>> fig = figure(figsize=(4,4)) >>> ax = fig.add_subplot(111) >>> ax.imshow(image,interpolation='nearest') >>> fig.savefig('plot.eps',dpi=30) >>> >>> --- >>> >>> I've submitted a bug report: >>> >>> https://sourceforge.net/tracker/?func=detail&aid=2777476&group_id=80706&atid=560720 >>> >>> Thanks, >>> >>> Thomas >>> >>> -- >>> Stay on top of everything new and different, both inside and >>> around Java (TM) technology - register by April 22, and save >>> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. >>> 300 plus technical and hands-on sessions. Register today. >>> Use priority code J9JMT32. http://p.sf.net/sfu/p >>> ___ >>> Matplotlib-users mailing list >>> Matplotlib-users@lists.sourceforge.net >>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >>> >>> > > > -- > Stay on top of everything new and different, both inside and > around Java (TM) technology - register by April 22, and save > $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. > 300 plus technical and hands-on sessions. Register today. > Use priority code J9JMT32. http://p.sf.net/sfu/p > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > 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 -- Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bug
Thanks for your quick reply! I'll be patient and wait for the fix to be made in the SVN repository, rather than trying to patch it myself. Do I need to add any information to the bug report? Best, Thomas On Apr 21, 2009, at 1:06 PM, Jae-Joon Lee wrote: > I can reproduce this bug with the current svn. > > It works correctly If you set dpi=72, but it seems that it would not > be an option in your case. > > It seems to me that this is related with the change in r6847 that > Michael made. > > http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/backends/backend_ps.py?r1=6734&r2=6847 > > At line 431 of the backend_ps.py, > > clip = (0.0, 0.0, self.width * self.imagedpi, >self.height * self.imagedpi) > > I think we should use the dpi of the figure, instead of the imagedpi > of the renderer. > Replacing self.imagedpi with 72 (which is the dpi of the figure when > ps backend is used) seems to solve the problem. > > Thomas, I don't see any easy workaround for this bug other than > patching the code. Others may have better insight though. > > Regards, > > -JJ > > > > On Tue, Apr 21, 2009 at 9:59 AM, Thomas Robitaille > wrote: >> Hi, >> >> I've come across a bug with the savefig method when using the dpi= >> argument and saving an EPS file. If you try the following code, you >> will see that the frame is incomplete. Is there a way to solve this >> from a user point of view? >> >> --- >> >> import matplotlib >> matplotlib.use('Agg') >> from matplotlib.pyplot import * >> >> import numpy as np >> >> nx,ny = 10,10 >> >> image = np.random.random((nx,ny)) >> >> fig = figure(figsize=(4,4)) >> ax = fig.add_subplot(111) >> ax.imshow(image,interpolation='nearest') >> fig.savefig('plot.eps',dpi=30) >> >> --- >> >> I've submitted a bug report: >> >> https://sourceforge.net/tracker/?func=detail&aid=2777476&group_id=80706&atid=560720 >> >> Thanks, >> >> Thomas >> >> -- >> Stay on top of everything new and different, both inside and >> around Java (TM) technology - register by April 22, and save >> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. >> 300 plus technical and hands-on sessions. Register today. >> Use priority code J9JMT32. http://p.sf.net/sfu/p >> ___ >> Matplotlib-users mailing list >> Matplotlib-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> -- Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig bug
I can reproduce this bug with the current svn. It works correctly If you set dpi=72, but it seems that it would not be an option in your case. It seems to me that this is related with the change in r6847 that Michael made. http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/backends/backend_ps.py?r1=6734&r2=6847 At line 431 of the backend_ps.py, clip = (0.0, 0.0, self.width * self.imagedpi, self.height * self.imagedpi) I think we should use the dpi of the figure, instead of the imagedpi of the renderer. Replacing self.imagedpi with 72 (which is the dpi of the figure when ps backend is used) seems to solve the problem. Thomas, I don't see any easy workaround for this bug other than patching the code. Others may have better insight though. Regards, -JJ On Tue, Apr 21, 2009 at 9:59 AM, Thomas Robitaille wrote: > Hi, > > I've come across a bug with the savefig method when using the dpi= > argument and saving an EPS file. If you try the following code, you > will see that the frame is incomplete. Is there a way to solve this > from a user point of view? > > --- > > import matplotlib > matplotlib.use('Agg') > from matplotlib.pyplot import * > > import numpy as np > > nx,ny = 10,10 > > image = np.random.random((nx,ny)) > > fig = figure(figsize=(4,4)) > ax = fig.add_subplot(111) > ax.imshow(image,interpolation='nearest') > fig.savefig('plot.eps',dpi=30) > > --- > > I've submitted a bug report: > > https://sourceforge.net/tracker/?func=detail&aid=2777476&group_id=80706&atid=560720 > > Thanks, > > Thomas > > -- > Stay on top of everything new and different, both inside and > around Java (TM) technology - register by April 22, and save > $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. > 300 plus technical and hands-on sessions. Register today. > Use priority code J9JMT32. http://p.sf.net/sfu/p > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Savefig('file.pdf') error with latex custom font
I finally got around to addressing this issue from October: "David Krapohl" writes: >> I am getting an error with savefig and pdf when I try to used >> matplotlib with latex font rendering (attached below). In >> etc/matplotlibrc, I set text.latex.preamble : >> \usepackage{MinionPro}, Jouni K. Seppänen writes: > However, the output seems to have some encoding problems. I will look > into the encoding issue, but cannot promise any particular time frame > for a solution. I think I have fixed the encoding bug in revision 6707. While the only user-visible change should be that some custom LaTeX fonts now work (specifically, large fonts such as Minion Pro and MnSymbol that need several different encodings), the changes in backend_pdf.py were big enough that I'm hesitant to check this in on the maintenance branch. -- Jouni K. Seppänen http://www.iki.fi/jks -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Savefig('file.pdf') error with latex custom font
"David Krapohl" <[EMAIL PROTECTED]> writes: >> >From your backtrace, it looks like dviread fails to parse a tfm file: >> >> > File "/usr/lib/python2.5/site-packages/matplotlib/dviread.py", line >> 398, >> > in __init__ >> > for char in range(0, max(tfm.width)) ] >> > ValueError: max() arg is an empty sequence >> > > Yes, with --verbose-debug-annoying I can see that it stops at: > find_tex_file: MinionPro-It--lcdfj.vf -> I was able to reproduce the problem, and have fixed the immediate problem, so you should no longer get an exception with the latest trunk version of matplotlib. However, the output seems to have some encoding problems. I will look into the encoding issue, but cannot promise any particular time frame for a solution. If using the Postscript backend and then converting to pdf is an option for you, it may be a workaround. -- Jouni K. Seppänen http://www.iki.fi/jks - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig to StringIO and import into PIL
Hi Michael, 2008/10/22 Michael Droettboom <[EMAIL PROTECTED]>: > You need to "rewind" the StringIO cursor before opening with PIL: > > imgdata = StringIO.StringIO() > fig.savefig(imgdata, format='png') > imgdata.seek(0) > im = Image.open(imgdata) Thanks. It works fine now. Best regards, Jesper - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Savefig('file.pdf') error with latex custom font
On Thu, Oct 23, 2008 at 7:04 AM, Jouni K. Seppänen <[EMAIL PROTECTED]> wrote: > "David Krapohl" <[EMAIL PROTECTED]> > writes: > > > I am getting an error with savefig and pdf when I try to used matplotlib > > with latex font rendering (attached below). In etc/matplotlibrc, I set > > text.latex.preamble : \usepackage{MinionPro}, > > \renewcommand{\sfdefault}{Myriad-LF} > > It seems that the dviread backend does not find a specific *.vf, > > MinionPro-It--lcdfj.vf to be specific, > > file that is not needed in my opinion. Any ideas how to solve that? > > Is that a commercial font? What exact files are installed when you > install that font in your texmf tree? Can dvipdfm/dvipdfmx/dvipdft > create a pdf file from a dvi file that uses this font? > It is an adobe font that is bundled with the Acrobat Reader. It is an otf font that was converted with "cfftot1" to *.pfb postscript font. Font metrics and scripts can be downloaded at http://developer.berlios.de/projects/minionpro/ I use it very often and so far I didn't have problems. > > >From your backtrace, it looks like dviread fails to parse a tfm file: > > > File "/usr/lib/python2.5/site-packages/matplotlib/dviread.py", line > 398, > > in __init__ > > for char in range(0, max(tfm.width)) ] > > ValueError: max() arg is an empty sequence > Yes, with --verbose-debug-annoying I can see that it stops at: find_tex_file: MinionPro-It--lcdfj.vf -> Followed by the same error message as in the first post. Unfortunately the vf-file is not there but the tfm file. As far as I know does this file describe the dotless-j for whatever reasons. So I think this particular file is not very important for math output. > -- > Jouni K. Seppänen > http://www.iki.fi/jks > > > - > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win great > prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > David Krapohl - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Savefig('file.pdf') error with latex custom font
"David Krapohl" <[EMAIL PROTECTED]> writes: > I am getting an error with savefig and pdf when I try to used matplotlib > with latex font rendering (attached below). In etc/matplotlibrc, I set > text.latex.preamble : \usepackage{MinionPro}, > \renewcommand{\sfdefault}{Myriad-LF} > It seems that the dviread backend does not find a specific *.vf, > MinionPro-It--lcdfj.vf to be specific, > file that is not needed in my opinion. Any ideas how to solve that? Is that a commercial font? What exact files are installed when you install that font in your texmf tree? Can dvipdfm/dvipdfmx/dvipdft create a pdf file from a dvi file that uses this font? >From your backtrace, it looks like dviread fails to parse a tfm file: > File "/usr/lib/python2.5/site-packages/matplotlib/dviread.py", line 398, > in __init__ > for char in range(0, max(tfm.width)) ] > ValueError: max() arg is an empty sequence -- Jouni K. Seppänen http://www.iki.fi/jks - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig to StringIO and import into PIL
Jesper Larsen wrote: > Hi mpl users, > > I am trying to save a figure to a file like object (a StringIO object) > and load this object into PIL (Python Imaging Library). The code for > this is really simple (fig is my figure object): > > # This works > fig.savefig('test.png', format='png') > im = Image.open('test.png') > > # This fails > imgdata = StringIO.StringIO() > fig.savefig(imgdata, format='png') > im = Image.open(imgdata) > > File "/home/jl/testfile.py", line 551, in contour > im = Image.open(imgdata) > File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 1916, in open > raise IOError("cannot identify image file") > IOError: cannot identify image file > You need to "rewind" the StringIO cursor before opening with PIL: imgdata = StringIO.StringIO() fig.savefig(imgdata, format='png') imgdata.seek(0) im = Image.open(imgdata) Hope that helps, Mike -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig memory useage
Mike, Updating to 0.91.1 fixed it. Python's memory usage was climbing in excess of 1 GB when running this script before (eventually crashing) -- now it hovers nicely around 60MB and completes with no problems. Excellent! Thanks, --Jordan Michael Droettboom wrote: > You can try running the garbage collector after each savefig. > ("import gc" and then call "gc.collect()"). If you are using a GUI > backend, you may want to try using the "raw" Agg backend instead -- > there are fewer moving parts that way. > > There have been a number of memory leaks that have been fixed since > 0.90.1. You may want to try 0.91 or a SVN checkout to see if that > fixes your problem. > > There is additional information about memory leaks in the FAQ. I > don't know if any are relevant to your particular situation: > > http://matplotlib.sourceforge.net/faq.html#LEAKS > > If none of the above helps, please send a complete but short script > that reproduces the error (basing it on memleak_gui.py or > memleak_hawaii.py is even more helpful), and one of the developers can > look into it. > > Cheers, > Mike > > Jordan Atlas wrote: > >> Hi all, >> >> I've noticed that when I save my figures using savefig the memory >> is not immediately released. For example, in pseudocode, >> >> times = get_times() >> for var_id in var_list: >> Plotting.figure() >> var_values = get_values(var_id) >> pylab.plot(times, values) >> Plotting.savefig(var+'.png', dpi=150) >> Plotting.close() >> >> This pseudo code loops over a list of variables, gets their values, >> and saves a plot for each one. The variable list has hundreds of >> items. If I run the code like this, the memory usage grows very >> quickly until python crashes. If I comment out the savefig line, or >> shorten the list of variables, the code completes without error. >> >> Can anyone suggest how I might write this differently so that I can >> process the long list of variables and save the figures? Is there >> any way to force the program to release memory once the figures are >> saved? >> >> I'm using matplotlib 0.90.1 and python 2.4 on windows XP. >> >> Thank you, >> >> --Jordan Atlas >> >> >> - >> >> SF.Net email is sponsored by: The Future of Linux Business White Paper >> from Novell. From the desktop to the data center, Linux is going >> mainstream. Let it simplify your IT future. >> http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4 >> ___ >> Matplotlib-users mailing list >> Matplotlib-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > - SF.Net email is sponsored by: The Future of Linux Business White Paper from Novell. From the desktop to the data center, Linux is going mainstream. Let it simplify your IT future. http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig memory useage
You can try running the garbage collector after each savefig. ("import gc" and then call "gc.collect()"). If you are using a GUI backend, you may want to try using the "raw" Agg backend instead -- there are fewer moving parts that way. There have been a number of memory leaks that have been fixed since 0.90.1. You may want to try 0.91 or a SVN checkout to see if that fixes your problem. There is additional information about memory leaks in the FAQ. I don't know if any are relevant to your particular situation: http://matplotlib.sourceforge.net/faq.html#LEAKS If none of the above helps, please send a complete but short script that reproduces the error (basing it on memleak_gui.py or memleak_hawaii.py is even more helpful), and one of the developers can look into it. Cheers, Mike Jordan Atlas wrote: > Hi all, > > I've noticed that when I save my figures using savefig the memory is > not immediately released. For example, in pseudocode, > > times = get_times() > for var_id in var_list: > Plotting.figure() > var_values = get_values(var_id) > pylab.plot(times, values) > Plotting.savefig(var+'.png', dpi=150) > Plotting.close() > > This pseudo code loops over a list of variables, gets their values, and > saves a plot for each one. The variable list has hundreds of items. If > I run the code like this, the memory usage grows very quickly until > python crashes. If I comment out the savefig line, or shorten the list > of variables, the code completes without error. > > Can anyone suggest how I might write this differently so that I can > process the long list of variables and save the figures? Is there any > way to force the program to release memory once the figures are saved? > > I'm using matplotlib 0.90.1 and python 2.4 on windows XP. > > Thank you, > > --Jordan Atlas > > > - > SF.Net email is sponsored by: The Future of Linux Business White Paper > from Novell. From the desktop to the data center, Linux is going > mainstream. Let it simplify your IT future. > http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4 > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > 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 - SF.Net email is sponsored by: The Future of Linux Business White Paper from Novell. From the desktop to the data center, Linux is going mainstream. Let it simplify your IT future. http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig pdf doesn't work anymore
Lionel Roubeyrie <[EMAIL PROTECTED]> writes: > I've got a problem with saving plots in pdf format like you can see in the > following output. It seems encodings.cp1252 doesn't have a decoding_map > method (but a decoding_table one). > Is it a bug or a problem in my encodings file? It's a bug, fixed in svn some time ago. Here's the patch if you want to fix it in your version: Index: backend_pdf.py === --- backend_pdf.py (revision 3449) +++ backend_pdf.py (revision 3476) @@ -500,11 +500,20 @@ # composite font, based on multi-byte characters. from encodings import cp1252 -firstchar, lastchar = 0, 255 +# The "decoding_map" was changed to a "decoding_table" as of Python 2.5. +if hasattr(cp1252, 'decoding_map'): +def decode_char(charcode): +return cp1252.decoding_map[charcode] or 0 +else: +def decode_char(charcode): +return ord(cp1252.decoding_table[charcode]) + def get_char_width(charcode): -unicode = cp1252.decoding_map[charcode] or 0 +unicode = decode_char(charcode) width = font.load_char(unicode, flags=LOAD_NO_SCALE).horiAdvance return cvt(width) + +firstchar, lastchar = 0, 255 widths = [ get_char_width(charcode) for charcode in range(firstchar, lastchar+1) ] widthsObject = self.reserveObject('font widths') -- Jouni K. Seppänen http://www.iki.fi/jks - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] savefig problems
Dominik Szczerba <[EMAIL PROTECTED]> writes: > I want bright information (fonts,lines) on dark background (figure > bg, axes bg) and I can fully achieve this goal while DISPLAYING > plots. However, SAVING damages their colors The following works for me (svn revision 3159): figure(facecolor='k') subplot(111, axisbg='k') plot([3,1,4,1,5,9,2], color='w', lw=2) savefig('foo.png', facecolor='k') savefig('foo.pdf', facecolor='k') > ingloriously (I could not trace down the rule what is aimed to be achieved) > and tweaking the two options in the example matplotlibrc (savefig.facecolor > and savefig.edgecolor) would not help. The following works for me: rc('savefig', facecolor='k') savefig('foo.png'); savefig('foo.pdf') Perhaps this has been fixed by somebody between your question and now. If you are still having problems, could you be more specific about how you are trying to accomplish your goal? -- Jouni K. Seppänen http://www.iki.fi/jks - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users