【发布时间】:2021-06-09 07:46:24
【问题描述】:
我正在并排绘制线图和图像。这是我的代码和当前输出:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
#creating some random data
np.random.seed(1234)
df = pd.DataFrame(
{'px_last': 100 + np.random.randn(1000).cumsum()},
index=pd.date_range('2010-01-01', periods=1000, freq='B'),
)
fig, ax = plt.subplots(1,2)
ax[0].plot(df.index, df['px_last'])
#reading the image
url = 'https://raw.githubusercontent.com/kornelski/pngquant/master/test/img/test.png'
im = plt.imread(url)
implot = ax[1].imshow(im)
图像按比例缩小,线图在 y 轴上放大。我希望两个图形在垂直方向(y 轴)上具有相同的大小 - 我希望将线图的垂直高度减小为具有相同的图像大小。
我尝试更改子图的图形大小并编辑here 中提到的 gridspec 参数,但这只会更改图像的宽度,而不是高度。任何帮助表示赞赏!
【问题讨论】:
标签: python pandas matplotlib