是否有一种简单的方法可以修改此代码,使绘图更大而不改变轴上的比例?
import numpy as np
import matplotlib.pyplot as plt
import math
%matplotlib inline
a, c = -10, 10
x = np.linspace(a,c,100)
x = np.array(x)
def y(x): return np.arctan(x)
h = 0.0000001
def grad(x,h): return (y(x+h)-y(x))/h
m = grad(x,h)
plt.figure(1)
plt.subplot(121)
plt.plot(x, y(x), 'b')
plt.xlim([a,c])
plt.ylim([min(y(x)),max(y(x))])
plt.gca().set_aspect('equal', adjustable='box')
plt.subplot(122)
plt.plot(x,m,'b')
plt.xlim([a,c])
plt.ylim([min(m),max(m)])
plt.gca().set_aspect('equal', adjustable='box')
plt.subplots_adjust(wspace = 0.5)
plt.show()
如果我去掉plt.gca().set_aspect('equal', adjustable='box')
,这些图的大小是合适的,但它们不能缩放。
子块缩小,以便它们的外观相等。这似乎是人们所期望的;因此,还不清楚“更大”指的是什么。
你仍然可以把这个数字放大,例如
然后使用
plt.subplots_adjust
调整边距和间距您也可以让轴缩放,只设置与数据相等的方面
最后,在彼此下方绘制子块也会使它们变大。所以你可以用
plt.subplot(211)
和plt.subplot(212)
.相关问题 更多 >
编程相关推荐