|
36 | 36 | # Demonstrates similarities between `~.axes.Axes.pcolor`, |
37 | 37 | # `~.axes.Axes.pcolormesh`, `~.axes.Axes.imshow` and |
38 | 38 | # `~.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"``). |
39 | 41 |
|
40 | 42 | # make these smaller to increase the resolution |
41 | 43 | dx,dy=0.15,0.05 |
42 | 44 |
|
43 | 45 | # 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) |
47 | 48 | # x and y are bounds, so z should be the value *inside* those bounds. |
48 | 49 | # Therefore, remove the last value from the z array. |
49 | 50 | 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() |
51 | 52 |
|
52 | 53 | fig,axs=plt.subplots(2,2) |
53 | 54 |
|
|
64 | 65 | ax=axs[1,0] |
65 | 66 | c=ax.imshow(z,cmap='RdBu',vmin=z_min,vmax=z_max, |
66 | 67 | 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")') |
69 | 70 | fig.colorbar(c,ax=ax) |
70 | 71 |
|
71 | 72 | ax=axs[1,1] |
|
84 | 85 | # The following shows pcolor plots with a log scale. |
85 | 86 |
|
86 | 87 | 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)) |
88 | 89 |
|
89 | 90 | # A low hump with a spike coming out. |
90 | 91 | # Needs to have z/colour axis on a log scale so we see both hump and spike. |
|