【发布时间】:2020-07-18 14:15:09
【问题描述】:
我正在努力调整情节,我一直在努力。 我面临两个问题:
- 绘图应该是相邻的,并且 wspace 和 hspace 为 0。我将这两个值都设置为零,但图之间仍然有一些空格。
- 我想为所有子图设置一个颜色条(它们的范围都相同)。现在,代码在最后一个子图中添加了一个颜色条,因为我知道它需要 hist2D 的第三个返回值。
到目前为止,这是我的代码:
def plot_panel(pannel_plot):
fig, ax = plt.subplots(3, 2, figsize=(7, 7), gridspec_kw={'hspace': 0.0, 'wspace': 0.0}, sharex=True, sharey=True)
fig.subplots_adjust(wspace=0.0)
ax = ax.flatten()
xmin = 0
ymin = 0
xmax = 0.19
ymax = 0.19
hist2_num = 0
h =[]
for i, j in zip(pannel_plot['x'].values(), pannel_plot['y'].values()):
h = ax[hist2_num].hist2d(i, j, bins=50, norm=LogNorm(vmin=1, vmax=5000), range=[[xmin, xmax], [ymin, ymax]])
ax[hist2_num].set_aspect('equal', 'box')
ax[hist2_num].tick_params(axis='both', top=False, bottom=True, left=True, right=False,
labelsize=10, direction='in')
ax[hist2_num].set_xticks(np.arange(xmin, xmax, 0.07))
ax[hist2_num].set_yticks(np.arange(ymin, ymax, 0.07))
hist2_num += 1
fig.colorbar(h[3], orientation='vertical', fraction=.1)
plt.show()
以及相应的结果:
如果我错过了任何提醒,我会很高兴!
【问题讨论】:
标签: python-3.x matplotlib histogram subplot colorbar