我有两个子地块,第一个子地块的比例是固定的。下面的子图我不关心比例,但宽度应该与上面的子图对齐。你知道吗
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(211, aspect='equal', autoscale_on=False, xlim=(0, 80), ylim=(0, 40))
ax.plot([0,10,20,40,60,70], [1,4,3,2,6,5], 'bo')
ax1 = fig.add_subplot(212, xlim=(0, 8000), ylim=(-200, 0))
ax1.plot([0,8000],[-200,0], '-')
plt.show()
如何使两个子地块具有相同的宽度?你知道吗
更新:
我成功了!你知道吗
import matplotlib.pyplot as plt
import numpy as np
gkw = {'height_ratios':[1, 2] }
fig, (ax1, ax2) = plt.subplots(2, 1, gridspec_kw = gkw )
ax1.set_aspect('equal')
ax1.set_autoscale_on(False)
ax1.set_xlim(left=0, right=80)
ax1.set_ylim(bottom=0, top=40)
ax1.plot([0,10,20,40,60,70], [1,4,3,2,6,5], 'bo')
ax2.set_xlim(left=0, right=8000)
ax2.set_ylim(bottom=-200, top=0)
ya = np.diff(np.array(ax2.get_ylim()))[0]
xa = np.diff(np.array(ax2.get_xlim()))[0]
wa = gkw['height_ratios'][0]/float(gkw['height_ratios'][1])
ia = 40/80
ax2.set_aspect(float(1/wa*ia/(ya/xa)))
ax2.plot([0,8000],[-200,0], '-')
plt.show()
这就是你要找的吗? 两个子地块的宽度相同
相关问题 更多 >
编程相关推荐