Re: [Matplotlib-users] PIL + pyplot.savefig() size change
The dpi value, which can be overridden, will determine the size of the output image. It looks to me like you just want the output to always be the same size as your input image, so use imsave() instead of imshow() followed by savefig() for this: i.e. just do map = Basemap(..) pilImg = Image.open('bkgmap.gif') rgba = pil_to_array(pilImg) pyplot.imsave('outimg.png', rgba) On Fri, Sep 23, 2011 at 9:10 AM, Isidora isid...@juno.com wrote: Hi, I am new to matplotlib so I may not have found the right answer because I am looking in the wrong places. I wrote a script to draw lines on a 800x600 pixels GIF background map. The output image I get is 620x450. Could someone let me know what I am doing wrong? Code Snippet: map = Basemap(..) pilImg = Image.open('bkgmap.gif') rgba = pil_to_array(pilImg) map.imshow(rgba) # Plot some lines and labels here pyplot.savefig('outimg.png',format='PNG',bbox_inches='tight',pad_inches=0) Thank you -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 ___ 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-d2dcopy2 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] subclassing ndarry
Hi, I found that ndarray is the wrong class to use for this purpose. The vector I created in the example below was just en uninitialised 3D vector. Arrays cannot be subclassed: class Vector(np.array): pass returns an error. But using a matrix as base class works: class Vector(np.matrix): def __abs__(self): l = np.sqrt(self*self.transpose()) return(l[0,0]) V1 = Vector([1,2,2]) V2 = Vector([5,0,4]) print abs(V2-2*V1) prints 5.0, as it should. It is very crude (no check on dimensions!), but works. Martijn On Thu, 2011-09-22 at 23:54 +0200, Martijn wrote: Hi, I am trying to create an ndarry subclass for vector calculations. The result is not what I intent: import numpy as np class Vector(np.ndarray): def __abs__(self): return(np.sqrt(sum(self**2))) V = Vector([1,2,3]) print np.sqrt(sum(self**2)) print abs(V) I do not understand the docs at http://www.scipy.org/Subclasses but it is late now. Martijn P.S. I know this is not strictly matplotlib related, but since MP uses numpy so heavily, I felt free to ask. -- All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 ___ 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-d2dcopy2 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] axis labels clipped
Tony Yu-3 wrote: A while back, I wrote some functions to calculate a good set of parameters for subplots_adjust (see attached; examples in if-main block at bottom). I've been using these functions pretty regularly, and it works pretty well for my purposes. The function has to draw the figure a couple of times to calculate correct spacing. When redrawing the figure (e.g. when you resize the window), you'd have to re-call the function, which would redraw the figure a couple of times before drawing the final figure. That's all to say: this is a fairly slow function. If you don't have subplots (like in your example), you can call layout.tight_borders() (instead of layout.tight()), which only requires a single redraw. When I originally posted this to the developers list, the functions didn't work with the GtkAgg backend. As far as I know, this hasn't changed. It should work fine for Qt4Agg, macosx, and TkAgg backends. Hi Tony, I copied your layout.py. Then run the following python script: -- import matplotlib.pyplot as plt import layout import random fontsizes = [8, 16, 24, 32] def example_plot(ax): ax.plot([1, 2]) ax.set_xlabel('x-label', fontsize=random.choice(fontsizes)) ax.set_ylabel('y-label', fontsize=random.choice(fontsizes)) ax.set_title('Title', fontsize=random.choice(fontsizes)) fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2) example_plot(ax1) example_plot(ax2) example_plot(ax3) example_plot(ax4) def on_resize(event): print( 'on_resize()' ) layout.tight() def on_close(event): print( 'on_close()' ) fig.canvas.mpl_disconnect( rsiz_id ) print rsiz_id layout.tight() if False: #if True: rsiz_id = fig.canvas.mpl_connect('resize_event', on_resize) print rsiz_id fig.canvas.mpl_connect('close_event', on_close) plt.show() -- Without the resize event it works as expected. With the resize event (as you suggested), it only adjusts the borders of the four axes to the outside of the figure. But between the axes there is no space at all. Do I miss something? Thanks a lot Kurt -- View this message in context: http://old.nabble.com/axis-labels-clipped-tp29738218p32503869.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- 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-d2dcopy2 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] axis labels clipped
quote author=Tony Yu-3 A while back, I wrote some functions to calculate a good set of parameters for subplots_adjust (see attached; examples in if-main block at bottom). I've been using these functions pretty regularly, and it works pretty well for my purposes. The function has to draw the figure a couple of times to calculate correct spacing. When redrawing the figure (e.g. when you resize the window), you'd have to re-call the function, which would redraw the figure a couple of times before drawing the final figure. That's all to say: this is a fairly slow function. If you don't have subplots (like in your example), you can call layout.tight_borders() (instead of layout.tight()), which only requires a single redraw. When I originally posted this to the developers list, the functions didn't work with the GtkAgg backend. As far as I know, this hasn't changed. It should work fine for Qt4Agg, macosx, and TkAgg backends. /quote Hi Tony, I copied your layout.py. Then run the following python script: -- import matplotlib.pyplot as plt import layout import random fontsizes = [8, 16, 24, 32] def example_plot(ax): ax.plot([1, 2]) ax.set_xlabel('x-label', fontsize=random.choice(fontsizes)) ax.set_ylabel('y-label', fontsize=random.choice(fontsizes)) ax.set_title('Title', fontsize=random.choice(fontsizes)) fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2) example_plot(ax1) example_plot(ax2) example_plot(ax3) example_plot(ax4) def on_resize(event): print( 'on_resize()' ) layout.tight() def on_close(event): print( 'on_close()' ) fig.canvas.mpl_disconnect( rsiz_id ) print rsiz_id layout.tight() if False: #if True: rsiz_id = fig.canvas.mpl_connect('resize_event', on_resize) print rsiz_id fig.canvas.mpl_connect('close_event', on_close) plt.show() -- Without the resize event it works as expected. With the resize event (as you suggested), it only adjusts the borders of the four axes to the outside of the figure. But between the axes there is no space at all. Do I miss something? Thanks a lot Kurt -- Kurt Mueller -- 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-d2dcopy2 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] axis labels clipped
On Fri, Sep 23, 2011 at 9:01 AM, Kurt Mueller kurt.alfred.muel...@gmail.com wrote: Without the resize event it works as expected. With the resize event (as you suggested), it only adjusts the borders of the four axes to the outside of the figure. But between the axes there is no space at all. Do I miss something? I think I was saying (I'm not certain, since it's been a while since the original email) that the function (layout.tight) had to be called again *after* resizing. BTW, one of the matplotlib devs (Jae Joon Lee, I believe) completely rewrote/improved this function and added it to matplotlib as tight_layouthttps://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/figure.py#L1312(both as a pyplot function and a figure method). I'm not sure if the function is in the current mpl release, but there's a pending release in the works. Best, -Tony -- 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-d2dcopy2___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Picking after a subplot geometry change
Hi, I have a canvas with two subplots on it and the user can pick curves on each subplot (all lines are pickable). I have created the ability to hide one subplot and only show one of the two. The remaining subplot is also enlarged to fit the canvas. This is done using: self.subplot1.set_visible(True) self.subplot2.set_visible(False) self.subplot1.change_geometry(1,1,1) self.canvas.draw() However, when I do that, its only possible to pick curves in the area where the original subplot was located.. like it hasn't updated the geometry for picking feature. Is there a way for me to do this? Thanks, Soren -- 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-d2dcopy2___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] NavigationToolbar2Wx with mplot3d
On Wednesday, September 21, 2011, Benjamin Root ben.r...@ou.edu wrote: On Wednesday, September 21, 2011, Keith Jones k.jo...@irl.cri.nz wrote: Hi, I have two questions about using NavigationToolbar2Wx with mplot3d. 1/ Initially the 3D scatter plot will rotate as usual with a mouse, but after selecting the ‘pan’ or ‘zoom’ buttons the plot responds with some confusion. How can I restore it to rotation only, i.e. disconnect the zoom or pan behaviour? That is a bug that should be resolved in the upcoming release. Use the right mouse button for zooming instead. In the upcoming release, the zoom and pan button should have no effect on axes3d objects, if I remember correctly. 2/ When using the ‘save’ button I get different behaviours depending on the backend. With ‘WXAgg’ the saved png image shows only the axes, not the scatter points. The scatter points and axes do appear correctly in a pdf file. Using the ‘WX’ backend gives both scatter points and axes for the png file. I dont use WxAgg regularly. I will use your code to test this. Ben Root I could not reproduce your problem with WxAgg backend on the development branch. I could only test on Linux, though. However, if there is a difference between platforms with WxAgg backend, then it is likely a Wx bug and not a mpl bug (although the fact that the Wx backend worked is odd). We are putting out an RC of v1.1.0 later today. Could you try out that version within the next few days and let me know if it still happens for you? Ben Root -- 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-d2dcopy2___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Problem with tick locater
Hello, Considering this example plot: http://imageshack.us/photo/my-images/27/imagefki.png/ How can I get the minor ticks showing correctly? (ie., 9 minor ticks per decade likewise for the x-axis) For some reason axis.set_minor_locator(LogLocator(numdecs=9) is not producing the desired output. Any hints? Thanks. -- Gökhan -- 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-d2dcopy2___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Problem with tick locater
On Fri, Sep 23, 2011 at 2:07 PM, Gökhan Sever gokhanse...@gmail.com wrote: Hello, Considering this example plot: http://imageshack.us/photo/my-images/27/imagefki.png/ How can I get the minor ticks showing correctly? (ie., 9 minor ticks per decade likewise for the x-axis) For some reason axis.set_minor_locator(LogLocator(numdecs=9) is not producing the desired output. Any hints? Thanks. -- Gökhan By default, setting the scale to log (e.g., ax.set_yscale('log')) should automatically turn the minor ticks on for you. Note that depending on your version of mpl, there may be a slight error in the documentation for LogLocator. Ben Root -- 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-d2dcopy2___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Problem with tick locater
On Fri, Sep 23, 2011 at 1:22 PM, Benjamin Root ben.r...@ou.edu wrote: On Fri, Sep 23, 2011 at 2:07 PM, Gökhan Sever gokhanse...@gmail.comwrote: Hello, Considering this example plot: http://imageshack.us/photo/my-images/27/imagefki.png/ How can I get the minor ticks showing correctly? (ie., 9 minor ticks per decade likewise for the x-axis) For some reason axis.set_minor_locator(LogLocator(numdecs=9) is not producing the desired output. Any hints? Thanks. -- Gökhan By default, setting the scale to log (e.g., ax.set_yscale('log')) should automatically turn the minor ticks on for you. Note that depending on your version of mpl, there may be a slight error in the documentation for LogLocator. Ben Root Hi, I set the log scales for both axes. However, as you see in the image y-axis has only 4 minor ticks (8 expected) where as x-axis has none. I am using a couple days old mpl build. -- Gökhan -- 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-d2dcopy2___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Problem with tick locater
On Fri, Sep 23, 2011 at 2:28 PM, Gökhan Sever gokhanse...@gmail.com wrote: On Fri, Sep 23, 2011 at 1:22 PM, Benjamin Root ben.r...@ou.edu wrote: On Fri, Sep 23, 2011 at 2:07 PM, Gökhan Sever gokhanse...@gmail.comwrote: Hello, Considering this example plot: http://imageshack.us/photo/my-images/27/imagefki.png/ How can I get the minor ticks showing correctly? (ie., 9 minor ticks per decade likewise for the x-axis) For some reason axis.set_minor_locator(LogLocator(numdecs=9) is not producing the desired output. Any hints? Thanks. -- Gökhan By default, setting the scale to log (e.g., ax.set_yscale('log')) should automatically turn the minor ticks on for you. Note that depending on your version of mpl, there may be a slight error in the documentation for LogLocator. Ben Root Hi, I set the log scales for both axes. However, as you see in the image y-axis has only 4 minor ticks (8 expected) where as x-axis has none. I am using a couple days old mpl build. I guess I would have to see your code. The y-axis ticks works fine in the examples: http://matplotlib.sourceforge.net/examples/pylab_examples/log_demo.html Viewing the pdf or hires png shows 8 minor ticks. Now, as for the x-axis, there are no minor ticks. That might be an issue... Ben Root -- 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-d2dcopy2___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] pylab, twinx, and displayed coordinates
In the following example the coordinates of the mouse cursor displayed in the pylab window belong to the second y-axis. But I would prefer to have the coordinates of the first y-axis to be displayed. Is this possible? import pylab as mpl mpl.plot([1,3,2]) mpl.twinx() mpl.plot([400,50,100]) mpl.show() Ciao Andreas -- 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-d2dcopy2 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Problem with tick locater
Hi, Another question is, what sets the tick-location on a log scaled axis? (that 10^-5, 10^-3, 10^-1, 10^1) It seems as if the range is greater than certain value ticks are located this way. Also in a similar way, the location of minor ticks are decided. (If the range is big, no minor ticks, if the range is not too big, put 4 minor ticks --which is very inconvenient to eye, if range is small then nicely locate 9 minor ticks.) Hah, the next probably will be manually forcing the _ticks or ticklocator functions. Anyone else experiencing similar behavior in mpl? On Fri, Sep 23, 2011 at 1:07 PM, Gökhan Sever gokhanse...@gmail.com wrote: Hello, Considering this example plot: http://imageshack.us/photo/my-images/27/imagefki.png/ How can I get the minor ticks showing correctly? (ie., 9 minor ticks per decade likewise for the x-axis) For some reason axis.set_minor_locator(LogLocator(numdecs=9) is not producing the desired output. Any hints? Thanks. -- Gökhan -- Gökhan -- 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-d2dcopy2___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Problem with tick locater
OK, This fixes the minor locations on y-axis ax1.yaxis.set_minor_locator(ticker.LogLocator(subs=np.arange(2.0, 10.0))) Independent of the data-range. It seems like ticker.LogLocator is trying to adjust the minor locs internally. On Fri, Sep 23, 2011 at 7:18 PM, Gökhan Sever gokhanse...@gmail.com wrote: Hi, Another question is, what sets the tick-location on a log scaled axis? (that 10^-5, 10^-3, 10^-1, 10^1) It seems as if the range is greater than certain value ticks are located this way. Also in a similar way, the location of minor ticks are decided. (If the range is big, no minor ticks, if the range is not too big, put 4 minor ticks --which is very inconvenient to eye, if range is small then nicely locate 9 minor ticks.) Hah, the next probably will be manually forcing the _ticks or ticklocator functions. Anyone else experiencing similar behavior in mpl? On Fri, Sep 23, 2011 at 1:07 PM, Gökhan Sever gokhanse...@gmail.comwrote: Hello, Considering this example plot: http://imageshack.us/photo/my-images/27/imagefki.png/ How can I get the minor ticks showing correctly? (ie., 9 minor ticks per decade likewise for the x-axis) For some reason axis.set_minor_locator(LogLocator(numdecs=9) is not producing the desired output. Any hints? Thanks. -- Gökhan -- Gökhan -- Gökhan -- 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-d2dcopy2___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users