添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hi, I am plotting a grid with pcolor. Below I’ve got a 1000x1000 grid.

xi=linspace(-0.1,x[-1]+2,1000)
yi=linspace(-0.1,maxfreq+10,1000)
print ‘Calling griddata…’
zi=griddata(x,y,z,xi,yi,interp=‘nn’)
plt.pcolor(xi,yi,zi,cmap=plt.cm.hot)

I am able to plot this on my computer, but it’s very slow and monitoring ‘top’ while python is running shows it using up quite a bit of memory. This data set that I’m currently using is only about 1/10 of what I eventually want to plot. While I may be able to drop the resolution to some degree, I’d like to be able to speed this up if possible. Google searches reveal different people talking about imshow and pcolormesh being faster than pcolor. Is this true? How could I modify my above data (which is in xi,yi,and zi) to work with imshow (which seems to take 1 argument for data).

Thanks for the help.

Brad Malone, on 2011-12-19 23:44, wrote:

Hi, I am plotting a grid with pcolor. Below I've got a 1000x1000 grid.

xi=linspace(-0.1,x[-1]+2,1000)
> yi=linspace(-0.1,maxfreq+10,1000)
> print 'Calling griddata...'
> zi=griddata(x,y,z,xi,yi,interp='nn')
> plt.pcolor(xi,yi,zi,cmap=plt.cm.hot)

How could I modify my above data (which is in xi,yi,and zi) to
work with imshow (which seems to take 1 argument for data).

Try either:

plt.matshow(zi,cmap=plt.cm.hot)

plt.imshow(zi,cmap=plt.cm.hot)

The first should be the quickest - it doesn't do any
fancy interpolation, and actually just passes some arguments to
the second. Using imshow directly, however, allows you to set a
different type of interpolation, should you desire it. If
you want xi and yi to be accurately reflect in the plot, you
might have to play around with changing the axis formatters
(though there might be an easier way of doing that, which escapes
me right now)

best,

Paul Ivanov
314 address only used for lists, off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7

HI Paul,

Thanks. I didn’t realize it was that simple (appears that doing this essentially plots everything against integers in x and y). This will be a good backup plan if I can’t get pcolor to work, although as you say, I’ll have to fiddle around some with the axis formatters and such I suppose to get a good final plot out of this.

Best,

On Tue, Dec 20, 2011 at 12:12 AM, Paul Ivanov <pivanov314@…287…> wrote:

Hey again, Brad,

Brad Malone, on 2011-12-19 23:44, wrote:

Hi, I am plotting a grid with pcolor. Below I’ve got a 1000x1000 grid.

xi=linspace(-0.1,x[-1]+2,1000)

yi=linspace(-0.1,maxfreq+10,1000)

plt.imshow(zi,cmap=plt.cm.hot)

The first should be the quickest - it doesn’t do any

fancy interpolation, and actually just passes some arguments to

the second. Using imshow directly, however, allows you to set a

different type of interpolation, should you desire it. If

you want xi and yi to be accurately reflect in the plot, you

might have to play around with changing the axis formatters

(though there might be an easier way of doing that, which escapes

me right now)

best,

Paul Ivanov

314 address only used for lists, off-list direct email at:

http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7

-----BEGIN PGP SIGNATURE-----

Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAk7wQ30ACgkQe+cmRQ8+KPdN8gCfY3SlI7F5zoXVrDL86VRyq3pC

SwwAn2bc6MBQjasKVxVzrvVRxaPJKiUP

=NmWr

-----END PGP SIGNATURE-----

You may also want to try:

plt.pcolormesh(xi,yi,zi,cmap=plt.cm.hot)

If I remember correctly, pcolormesh is faster but a bit more restrictive. (I think it’s slower than matshow and imshow).

-Tony

P.S. I never knew about matshow; thanks Paul!

On Tue, Dec 20, 2011 at 9:22 AM, Brad Malone <brad.malone@…287…> wrote:

HI Paul,

Thanks. I didn’t realize it was that simple (appears that doing this essentially plots everything against integers in x and y). This will be a good backup plan if I can’t get pcolor to work, although as you say, I’ll have to fiddle around some with the axis formatters and such I suppose to get a good final plot out of this.

Best,

On Tue, Dec 20, 2011 at 12:12 AM, Paul Ivanov <pivanov314@…287…> wrote:

Hey again, Brad,

Brad Malone, on 2011-12-19 23:44, wrote:

Hi, I am plotting a grid with pcolor. Below I’ve got a 1000x1000 grid.

xi=linspace(-0.1,x[-1]+2,1000)

yi=linspace(-0.1,maxfreq+10,1000)

plt.imshow(zi,cmap=plt.cm.hot)

The first should be the quickest - it doesn’t do any

fancy interpolation, and actually just passes some arguments to

the second. Using imshow directly, however, allows you to set a

different type of interpolation, should you desire it. If

you want xi and yi to be accurately reflect in the plot, you

might have to play around with changing the axis formatters

(though there might be an easier way of doing that, which escapes

me right now)

best,

Paul Ivanov

Tony,

Thanks for the pcolormesh suggestion! It is quite a bit faster than pcolor for me (maybe 50-100x faster)!

Best,

On Tue, Dec 20, 2011 at 10:10 AM, Tony Yu <tsyu80@…287…> wrote:

On Tue, Dec 20, 2011 at 9:22 AM, Brad Malone <brad.malone@…287…> wrote:

HI Paul,

Thanks. I didn’t realize it was that simple (appears that doing this essentially plots everything against integers in x and y). This will be a good backup plan if I can’t get pcolor to work, although as you say, I’ll have to fiddle around some with the axis formatters and such I suppose to get a good final plot out of this.

plt.imshow(zi,cmap=plt.cm.hot)

The first should be the quickest - it doesn’t do any

fancy interpolation, and actually just passes some arguments to

the second. Using imshow directly, however, allows you to set a

different type of interpolation, should you desire it. If

you want xi and yi to be accurately reflect in the plot, you

might have to play around with changing the axis formatters

(though there might be an easier way of doing that, which escapes

me right now)

best,

Paul Ivanov

You may also want to try:

plt.pcolormesh(xi,yi,zi,cmap=plt.cm.hot)

If I remember correctly, pcolormesh is faster but a bit more restrictive. (I think it’s slower than matshow and imshow).

-Tony

P.S. I never knew about matshow; thanks Paul!

Tony,

Thanks for the pcolormesh suggestion! It is quite a bit faster than
pcolor for me (maybe 50-100x faster)!

There is also the Axes.pcolorfast() method. It has no pylab wrapper, and it is fussier than the others about its input arguments, but it uses the fastest method that the input grid permits. In your case it would be the speed of imshow, which is faster than pcolormesh.

http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.pcolorfast

Note that like pcolor and pcolormesh its grid is based on the specification of the boundaries, not the centers, but unlike pcolormesh and pcolor it will not automatically chop off a row and a column of the 2-D color array to be plotted if you give it a grid with the same dimensions as the color array.

On 12/20/2011 10:48 AM, Brad Malone wrote:

Best,

On Tue, Dec 20, 2011 at 10:10 AM, Tony Yu < [email protected] ... > <mailto:tsyu80@…287…>> wrote:

On Tue, Dec 20, 2011 at 9:22 AM, Brad Malone < [email protected] ... > <mailto:brad.malone@…287…>> wrote:

HI Paul,

Thanks. I didn't realize it was that simple (appears that doing
this essentially plots everything against integers in x and y).
This will be a good backup plan if I can't get pcolor to work,
although as you say, I'll have to fiddle around some with the
axis formatters and such I suppose to get a good final plot out
of this.

Best,

On Tue, Dec 20, 2011 at 12:12 AM, Paul Ivanov > < [email protected] ... <mailto:pivanov314@…287…>> wrote:

Hey again, Brad,

Brad Malone, on 2011-12-19 23:44, wrote:
> Hi, I am plotting a grid with pcolor. Below I've got a
1000x1000 grid.
> xi=linspace(-0.1,x[-1]+2,1000)
> > yi=linspace(-0.1,maxfreq+10,1000)
> > print 'Calling griddata...'
> > zi=griddata(x,y,z,xi,yi,interp='nn')
> > plt.pcolor(xi,yi,zi,cmap=plt.cm.hot)
> How could I modify my above data (which is in xi,yi,and
zi) to
> work with imshow (which seems to take 1 argument for data).

Try either:

plt.matshow(zi,cmap=plt.cm.hot)

plt.imshow(zi,cmap=plt.cm.hot)

The first should be the quickest - it doesn't do any
fancy interpolation, and actually just passes some arguments to
the second. Using imshow directly, however, allows you to set a
different type of interpolation, should you desire it. If
you want xi and yi to be accurately reflect in the plot, you
might have to play around with changing the axis formatters
(though there might be an easier way of doing that, which
escapes
me right now)

best,
Paul Ivanov

You may also want to try:

plt.pcolormesh(xi,yi,zi,cmap=plt.cm.hot)

If I remember correctly, pcolormesh is faster but a bit more
restrictive. (I think it's slower than matshow and imshow).

-Tony

P.S. I never knew about matshow; thanks Paul!

------------------------------------------------------------------------------
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
[email protected]
matplotlib-users List Signup and Options