我在python中使用matplotlib.pyplot来绘制我的数据.问题是它生成的图像似乎是自动调整的.如何将其关闭以便当我在(0,0)处绘制某些内容时,它将被固定在中心?
你想要的autoscale
功能:
from matplotlib import pyplot as plt
# Set the limits of the plot
plt.xlim(-1, 1)
plt.ylim(-1, 1)
# Don't mess with the limits!
plt.autoscale(False)
# Plot anything you want
plt.plot([0, 1])
Run Code Online (Sandbox Code Playgroud)
您可以使用xlim()
和ylim()
来设置限制。如果您知道您的数据从 X 上的 -10 到 20,Y 上的 -50 到 30,您可以执行以下操作:
plt.xlim((-20, 20))
plt.ylim((-50, 50))
Run Code Online (Sandbox Code Playgroud)
使 0,0 居中。
如果您的数据是动态的,您可以首先尝试允许自动缩放,然后将限制设置为包含:
xlim = plt.xlim()
max_xlim = max(map(abs, xlim))
plt.xlim((-max_xlim, max_xlim))
ylim = plt.ylim()
max_ylim = max(map(abs, ylim))
plt.ylim((-max_ylim, max_ylim))
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7530 次 |
最近记录: |