python - 带子图的 Matplotlib bbox_to_anchor

标签 python matplotlib

我有以下问题: 我正在尝试使用子图和两列图例在同一个图形上绘制一些数据,因为否则它会进入图形并且我看不到数据。

<小时/>

您可以在此处[或多或少]看到代码:

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/

相关文章:

python - 比较具有不同 x 轴值的直方图

python - 合并 Pandas 中不相交的列

python - 在 Selenium 中使用 urllib2 cookie

python - networkx 与 matplotlib 的交互

python - 时代问题的秒数

python - imshow.set_data() 不适用于 FuncAnimation

python - 无法在 MatPlotLib 3d 上使 Axis 右对齐

python - 自动机器学习 python 等效代码

python - 使用列表列表清理 python 中的马虎 "for"循环

当使用 Hook 到某些应用程序时,pythoncom 在 KeyDown 上崩溃