限制 Matplotlib 图例最佳位置选项
在 Matplotlib 中,图例有一个参数 loc ,它允许指定图例的位置。
用户可以强制图例位于 9 个不同的位置,或者让 matplotlib 决定图例的最佳位置。
来自 文档:
字符串“左上”、“右上”、“左下”、“右下” 将图例放在轴/图形的相应角上。
字符串“上中心”、“下中心”、“左中心”、“中心” right' 将图例放在相应边缘的中心 轴/图。
字符串“center”将图例放置在图例的中心 轴/图。
字符串“best”将图例放置在九个位置中的位置 到目前为止定义的位置,与其他绘制的重叠最小 艺术家。
现在,我想强制图例位于图的右侧部分,但根据数据,最佳位置可能是“右上”或“右下”。
我不希望图例放置在左侧或中心,但我仍然希望计算“右上”或“右下”之间的最佳位置。
根据文档,最佳位置是通过计算与其他绘制的艺术家的最小重叠
来计算的。
是否有一种方法可以限制最佳
选项仅考虑某些选项而不考虑九个地点中?或者手动调用仅使用所需选项计算此重叠的函数?
In Matplotlib, the legend has a parameter loc
that allows to specify the location of the legend.
The user can force the legend to be in 9 different locations or let matplotlib decide where is the best location for the Legend.
From the documentation:
The strings 'upper left', 'upper right', 'lower left', 'lower right'
place the legend at the corresponding corner of the axes/figure.The strings 'upper center', 'lower center', 'center left', 'center
right' place the legend at the center of the corresponding edge of the
axes/figure.The string 'center' places the legend at the center of the
axes/figure.The string 'best' places the legend at the location, among the nine
locations defined so far, with the minimum overlap with other drawn
artists.
Now, I want to force the legend to be on the right part of the plot, but depending on the data, the best location could be 'upper right' or 'lower right'.
I don't want the legend to be placed on the left or on the center, but I still want the best location between 'upper right' or 'lower right' to be calculated.
According to the documentation the Best location is calculated by calculating the minimum overlap with other drawn artists
Is there a way of limiting the best
option to take only certain options in account and not among the nine locations? Or to manually call the function that calculates this overlap with only the desired options?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以限制 matplotlib 考虑的 计算的区域最佳位置通过使用
bbox_to_anchor
关键字:示例输出:
You can restrict the area that matplotlib considers for the calculation of the best position by using the
bbox_to_anchor
keyword:Sample output: