我想绘制图像(使用matplotlib.imshow
)和同一图内的散点图。尝试此操作时,图像看起来比散点图小。小例子代码如下所示:使用matplotlib imshow获取相同的副图大小和分散
import matplotlib.pyplot as plt
import numpy as np
image = np.random.randint(100,200,(200,200))
x = np.arange(0,10,0.1)
y = np.sin(x)
fig, (ax1, ax2) = plt.subplots(1,2)
ax1.imshow(image)
ax2.scatter(x,y)
plt.show()
其中给出如下图所示:
我怎样才能获得两个sublpots具有相同的高度? (和宽度我想)
fig=plt.figure()
gs=GridSpec(1,2)
ax1=fig.add_subplot(gs[0,0])
ax2=fig.add_subplot(gs[0,1])
ax1.imshow(image)
ax2.scatter(x,y)
但这给出相同的结果。我也试图调整插曲手动尺寸使用:
fig = plt.figure()
ax1 = plt.axes([0.05,0.05,0.45,0.9])
ax2 = plt.axes([0.55,0.19,0.45,0.62])
ax1.imshow(image)
ax2.scatter(x,y)
通过试验和错误,我可以得到两个次要情节,以正确的尺寸,虽然在整体数字大小的任何变化将意味着次要情节会不更长的是相同的大小。
有没有办法让imshow
和scatter
图在图中显示为相同的尺寸,而无需手动更改轴尺寸?
我使用Python 2.7和matplotlib 2.0.0
理想的结果是,这两个小区的大小完全相同,并在调整大小时保持这种方式。无论如何,'aspect ='auto''做了诀窍,谢谢。 – DavidG