[Matplotlib-users] Fixed width - axis equal *and* tight
Hi there, I want to examine a vector field and therefore i used "quiver" to visualize said field: > import numpy as np > import matplotlib.pyplot as plt > > # points > x, y = np.meshgrid(np.arange(0, 2*np.pi, 0.1), >np.arange(0, 1*np.pi, 0.1)) > # derivatives > dx = -2*np.sin(x)*np.cos(y) > dy =np.cos(x)*np.sin(y) > > # plot > plt.figure() > plt.quiver(dx, dy, color='b') > > # beautiful axis > a = plt.gca() > x_a, y_a = a.get_xaxis(), a.get_yaxis() > a.axis('tight') > # TODO: We should not multiply with 10 here. > x_a.set_ticks(np.arange(0, 2*np.pi*10+1, np.pi*10/4)) > y_a.set_ticks(np.arange(0, 1*np.pi*10+1, np.pi*10/4)) > labels = [ > r'$0$', > r'$\frac{1}{4}\pi$', > r'$\frac{1}{2}\pi$', > r'$\frac{3}{4}\pi$', > r'$\pi$', > r'$\frac{5}{4}\pi$', > r'$\frac{3}{2}\pi$', > r'$\frac{7}{4}\pi$', > r'$2 \pi$'] > a.set_xticklabels(labels) > a.set_yticklabels(labels[:5]) > > # show > plt.show() (The plot looks like a double swirl, if anyone is interested in that information) At first I do not know why I have to multiply with 10 at the ticks, but thats not the point. It is much more important that I would like to set the image to a certain width before saving. It should be both "tight" and "equal", so after setting the width the height could be calculated automatically. As a workaround I use the images and strech them vertically, but then the x/y axis tick labels look strange. So: How to set a certain width? Thanks and a merry Christmas, Keba -- Write once. Port to many. Get the SDK and tools to simplify cross-platform app development. Create new or port existing apps to sell to consumers worldwide. Explore the Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join http://p.sf.net/sfu/intel-appdev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Fixed width - axis equal *and* tight
Hi, Maybe a bad idea to ask a question on x-mas. Well, I hope it’s not that unpolite to push one‘s questions. :) Basically I just want to set a fixed width/height on my figure. That should be possible? Mario Fuest schrieb am Sat, 24. Dec 16:42: > Hi there, > > I want to examine a vector field and therefore i used "quiver" to > visualize said field: > > > import numpy as np > > import matplotlib.pyplot as plt > > > > # points > > x, y = np.meshgrid(np.arange(0, 2*np.pi, 0.1), > >np.arange(0, 1*np.pi, 0.1)) > > # derivatives > > dx = -2*np.sin(x)*np.cos(y) > > dy =np.cos(x)*np.sin(y) > > > > # plot > > plt.figure() > > plt.quiver(dx, dy, color='b') > > > > # beautiful axis > > a = plt.gca() > > x_a, y_a = a.get_xaxis(), a.get_yaxis() > > a.axis('tight') > > # TODO: We should not multiply with 10 here. > > x_a.set_ticks(np.arange(0, 2*np.pi*10+1, np.pi*10/4)) > > y_a.set_ticks(np.arange(0, 1*np.pi*10+1, np.pi*10/4)) > > labels = [ > > r'$0$', > > r'$\frac{1}{4}\pi$', > > r'$\frac{1}{2}\pi$', > > r'$\frac{3}{4}\pi$', > > r'$\pi$', > > r'$\frac{5}{4}\pi$', > > r'$\frac{3}{2}\pi$', > > r'$\frac{7}{4}\pi$', > > r'$2 \pi$'] > > a.set_xticklabels(labels) > > a.set_yticklabels(labels[:5]) > > > > # show > > plt.show() > > (The plot looks like a double swirl, if anyone is interested in that > information) > > At first I do not know why I have to multiply with 10 at the ticks, but > thats not the point. > > It is much more important that I would like to set the image to a > certain width before saving. It should be both "tight" and "equal", so > after setting the width the height could be calculated automatically. > > As a workaround I use the images and strech them vertically, but then > the x/y axis tick labels look strange. > > So: How to set a certain width? > > Thanks and a merry Christmas, > Keba > > -- > Write once. Port to many. > Get the SDK and tools to simplify cross-platform app development. Create > new or port existing apps to sell to consumers worldwide. Explore the > Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join > http://p.sf.net/sfu/intel-appdev > ___ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Write once. Port to many. Get the SDK and tools to simplify cross-platform app development. Create new or port existing apps to sell to consumers worldwide. Explore the Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join http://p.sf.net/sfu/intel-appdev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Set width before saving
Hi there, Currently i use these commands to layout and save my figures: > figure > ... > gca.set_aspect('equal') > gca.autoscale(tight=True) > ... > plt.savefig('fpp.png', bbox_inches='tight', pad_inches=0) I would like to set the width of this png file, how to do that? If savefig() does not support setting the width, maybe I can set the width of my xaxis? Thanks in advance, Keba -- Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Fixed width - axis equal *and* tight
Hi, Sorry for the late reply. Tony Yu schrieb am Tue, 03. Jan 17:07: > You can try > > >>> ax.set_aspect('equal') > >>> ax.autoscale(tight=True) > > The order doesn't seem to matter. That works well, thank you! :) Kind regars, Keba. -- Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Set width before saving
Hi there, John Hunter schrieb am Wed, 29. Feb 07:04: > On Feb 28, 2012, at 4:03 PM, Benjamin Root wrote: > > The size of the PNG will be based on the size of your figure object. When > > you create your figure, you can pass a figsize kwarg which takes a tuple of > > width, height in inches (defaults to 8 x 6, I think). > > > > fig = plt.figure(figsize=(10.0, 6.0)) > > With an existing Figure instance, you can also call > > fig.set_figwidth(width_inches) > > before saving (or set_figheight or set_size_inches) > > http://matplotlib.sourceforge.net/api/figure_api.html#matplotlib.figure.Figure That helps, thanks a lot! :) Regards, Keba -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users