开发者

How to make a non-square contourf-plot

I'm using contourf in pyplot to plot some scalar data开发者_Python百科, but when my domain is non-square i feel like the data is misrepresented because it always plots it in a square (though the axis values will increase faster on one side.) How can i force the axis scaling to be equal, such that if my domain is twice as long in the x-direction the image is actually plotted in a rectangle with this property?

I'm doing something like this:

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
contour = ax.contourf(X,Y,Z)
fig.colorbar(contour)
fig.canvas.draw()


Using ax.set_aspect:

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111)
x=np.r_[-10:10:100j]
y=np.r_[-20:20:100j]
z= np.add.outer(x*x, y*y)
contour=ax.contour(x,y,z)
fig.colorbar(contour)
ax.set_aspect('equal')
# ax.axis('equal')
plt.show()

yields

How to make a non-square contourf-plot

while changing ax.set_aspect('equal') to

ax.axis('equal')

yields

How to make a non-square contourf-plot


This might help:

ax = fig.add_subplot(111, aspect="equal")


You need to change the axis setting:

axis('equal')

See all of the axis settings here:

http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.axis

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜