Matplotlib:如何相对于轴移动图形?

时间:2018-09-20 07:01:04

标签: python matplotlib

在matplotlib中,是否可以相对于轴移动图形?

我正在尝试创建一个合并的图形,其中两个子图使用一个共享的y轴。我越来越近了,但是当我绘制第二个图形时,这会使第一个图形中的数据相对于y轴移动(请注意左下角:多维数据集应与刻度标签对齐)。

我需要找到一种方法来抵消第一张图中的数据/图形以对此进行纠正。

这是我到目前为止尝试过的:

# Set up the matplotlib figure
f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)

#Left side: heatmap
g = sns.heatmap(corr_abs, mask=mask, cmap=cmap, vmax=.9, linewidths=.2,ax=ax1,
                cbar=False)
g.set_yticklabels(g.get_yticklabels(), rotation =0)
g.set_xticklabels(g.get_xticklabels(), rotation =90)

#Right side: bar chart, using the previous y-axis
g2 = kj.plot.barh(x='Feature',color=my_colors,ax=ax2,linewidth=None)
g2.invert_xaxis(); g2.yaxis.tick_right()
bb = ax2.get_position(); 
ll, bb, ww, hh = bb.bounds
ax2.set_position([ll-0.32,bb,ww,hh])
ax2.legend(bbox_to_anchor=(0.25, 0.65, 0.57, .102))
ax2.spines['left'].set_visible(False)
ax2.spines['bottom'].set_visible(False)
ax2.xaxis.set_ticks_position('top')
ax2.patch.set_alpha(0.0)

这是我的身材:

image

0 个答案:

没有答案