Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit65083e0

Browse files
committed
Cleanup pcolor_demo.
- Set up the x, y arrays in simpler (IMO) ways.- Make imshow() use aspect="auto" rather than the default aspect=1, to make it more comparable with the pcolor plots.
1 parent9c2ad59 commit65083e0

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

‎examples/images_contours_and_fields/pcolor_demo.py‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,19 @@
3636
# Demonstrates similarities between `~.axes.Axes.pcolor`,
3737
# `~.axes.Axes.pcolormesh`, `~.axes.Axes.imshow` and
3838
# `~.axes.Axes.pcolorfast` for drawing quadrilateral grids.
39+
# Note that we call ``imshow`` with ``aspect="auto"`` so that it doesn't force
40+
# the data pixels to be square (the default is ``aspect="equal"``).
3941

4042
# make these smaller to increase the resolution
4143
dx,dy=0.15,0.05
4244

4345
# generate 2 2d grids for the x & y bounds
44-
y,x=np.mgrid[slice(-3,3+dy,dy),
45-
slice(-3,3+dx,dx)]
46-
z= (1-x/2.+x**5+y**3)*np.exp(-x**2-y**2)
46+
y,x=np.mgrid[-3:3+dy:dy,-3:3+dx:dx]
47+
z= (1-x/2+x**5+y**3)*np.exp(-x**2-y**2)
4748
# x and y are bounds, so z should be the value *inside* those bounds.
4849
# Therefore, remove the last value from the z array.
4950
z=z[:-1, :-1]
50-
z_min,z_max=-np.abs(z).max(),np.abs(z).max()
51+
z_min,z_max=-abs(z).max(),abs(z).max()
5152

5253
fig,axs=plt.subplots(2,2)
5354

@@ -64,8 +65,8 @@
6465
ax=axs[1,0]
6566
c=ax.imshow(z,cmap='RdBu',vmin=z_min,vmax=z_max,
6667
extent=[x.min(),x.max(),y.min(),y.max()],
67-
interpolation='nearest',origin='lower')
68-
ax.set_title('image (nearest)')
68+
interpolation='nearest',origin='lower',aspect='auto')
69+
ax.set_title('image (nearest, aspect="auto")')
6970
fig.colorbar(c,ax=ax)
7071

7172
ax=axs[1,1]
@@ -84,7 +85,7 @@
8485
# The following shows pcolor plots with a log scale.
8586

8687
N=100
87-
X,Y=np.mgrid[-3:3:complex(0,N),-2:2:complex(0,N)]
88+
X,Y=np.meshgrid(np.linspace(-3,3,N),np.linspace(-2,2,N))
8889

8990
# A low hump with a spike coming out.
9091
# Needs to have z/colour axis on a log scale so we see both hump and spike.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp