SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Mario F. <mar...@ao...> - 2011年12月24日 15:42:48
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
From: Mario F. <mar...@ao...> - 2012年01月03日 16:58:35
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 <mar...@ao...> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Tony Yu <ts...@gm...> - 2012年01月03日 22:07:16
On Tue, Jan 3, 2012 at 11:57 AM, Mario Fuest <mar...@ao...> wrote:
> 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 <mar...@ao...> 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
>
>
You can try
>>> ax.set_aspect('equal')
>>> ax.autoscale(tight=True)
The order doesn't seem to matter.
-Tony
From: Mario F. <mar...@ao...> - 2012年02月28日 21:52:33
Hi,
Sorry for the late reply.
Tony Yu <ts...@gm...> 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.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /