2011-03-24 57 views
2

我在pyplot中使用contourf來繪製一些標量數據,但是當我的域是非正方形時,我覺得數據被歪曲,因爲它總是繪製在一個正方形中儘管座標軸的值在一側會增加得更快)。我如何強制軸縮放比例相等,這樣,如果我的域在x方向上長了兩倍,則圖像實際上會繪製在具有此屬性的矩形中?如何使一個非正方形contourf-plot

我在做這樣的事情:

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() 

回答

5

使用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() 

產量

enter image description here

同時改變ax.set_aspect('equal')

ax.axis('equal') 

收率

enter image description here

相關問題