这是我用来产生以下输出的代码:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
xedges = [27.5, 35, 42.5, 50, 57.5, 65, 72.5, 80, 87.5, 95, 102.5, 110, 117.5, 125, 132.5, 140, 147.5, 155, 162.5]
yedges = [0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320, 340, 360, 380]
H = pd.read_stata ('R:/data.dta')
fig = plt.figure()
plt.imshow(H, cmap="nipy_spectral", interpolation='bilinear', origin='low',extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]])
图形上的x轴看起来非常压缩。我希望能够产生相同的图形,但x轴更宽,我该怎么做?
我怀疑它与'extent'参数有关,但是我不确定该怎么做。
答案 0 :(得分:1)
我刚刚弄清楚了。解决方案是在代码中将长宽比设置为“自动”,如下所示:
plt.imshow(H, cmap="nipy_spectral", interpolation='bilinear', origin='low',aspect = 'auto', extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]])