我有以下问题: 我正在尝试使用子图和两列图例在同一个图形上绘制一些数据,因为否则它会进入图形并且我看不到数据。
<小时/>您可以在此处[或多或少]看到代码:
for i in range(no_of_cust_clusters):
ax[i] = plt.subplot(gs[i],)
df[i].plot(ax=ax[i])
ax[i].legend(bbox_to_anchor=(0, 0, 1, 1),
bbox_transform=plt.gcf().transFigure,ncol=2)
<小时/>
我也尝试过:
bbox_to_anchor=(0, 0, 1, i/no_of_cust_clusters)
bbox_to_anchor=(0, 0, 1, i)
Also note that gs is gridspec in order to customize the location.
尽管如此,当我绘制数据时,所有图例都位于图形的右上角(正如我所说,我有一个带有多个子图的图形,由 gridspec 指定)。我怎么解决这个问题? 谢谢!
最佳答案
尝试将变换设置为当前轴,以将图例放在不同的子图上
bbox_transform=ax[i].transAxes
关于python - 带子图的 Matplotlib bbox_to_anchor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30849424/