简体   繁体   English

pyplot子图中的固定轴范围

[英]Fixing axes ranges in pyplot subplots

I am trying to plot data sets U(x,t) and V(x,t) using Python's matplotlib.pyplot subplots. 我正在尝试使用Python的matplotlib.pyplot子图来绘制数据集U(x,t)和V(x,t)。 I want to manually set the axes of the first subplot, while the second subplot can choose its own axis: 我想手动设置第一个子图的轴,而第二个子图可以选择自己的轴:

import matplotlib.pyplot as plt

plt.subplot(121)
plt.pcolor(xx,tt,U)
plt.colorbar()
plt.axes([0,600,0,100])
plt.subplot(122)
plt.pcolor(xx,tt,V)
plt.colorbar()
plt.show()

However, this seems to have no effect on changing the axes of the first subplot. 但是,这似乎对更改第一个子图的轴没有影响。 Also, after the plot generates, I get an extensive error: 另外,在生成情节之后,我得到了一个广泛的错误:

Exception in Tkinter callback
...
...
raise LinAlgError('Singular matrix')
numpy.linalg.linalg.LinAlgError: Singular matrix

When I remove the above plotting commands from my code, however, the error disappears. 但是,当我从代码中删除上述绘图命令时,错误消失了。 Any thoughts? 有什么想法吗?

Instead of trying to set the axes itself, you can try adjusting the xlim and ylim properties instead: 您可以尝试调整xlim和ylim属性,而不是尝试自行设置轴:

import matplotlib.pyplot as plt
from numpy import *
xx = arange(0,700,30)
tt = arange(0,100,5)
U = outer(xx,tt)
V = outer(xx**(1/2),tt/4)
plt.subplot(121)
plt.pcolor(tt,xx,U)
plt.colorbar()
#plt.axes([0,600,0,100])

plt.xlim(0,100)
plt.ylim(0,600)

plt.subplot(122)
plt.pcolor(tt,xx,V)
plt.colorbar()

plt.show()

脚本输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM