- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(10)
fig = plt.figure()
ax = plt.subplot(111)
for i in xrange(5):
ax.plot(x, i * x, label='$y = %ix$' % i)
ax.legend(bbox_to_anchor=(1.1, 1.05))
plt.show()
在上面的代码中,我遇到了将图例置于任意位置的函数 bbox_to_anchor。我无法理解该函数的前两个论点,所有文献都说是归一化轴参数。任何机构都可以解释它们是什么以及如何操纵它们吗?
最佳答案
它不是一个函数,而是一个关键字参数。
总结:您使用 loc
来指定图例的一个角,并且可以选择使用 bbox_to_anchor
来指定该角的位置。默认情况下,图例的指定角将放置在轴的同一角上。
例如 loc='upper right'
只会将图例的右上角放在轴的右上角:
ax.legend(loc='upper right')
但是如果您希望图例的右上角位于坐标轴的左中,您可以使用 bbox_to_anchor=(0, 0.5)
:
ax.legend(loc='upper right', bbox_to_anchor=(0, 0.5))
关于python - bbox_to_anchor() 函数的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40908983/
import matplotlib.pyplot as plt import numpy as np x = np.arange(10) fig = plt.figure() ax = plt.sub
我有以下问题:我正在尝试使用子图和两列图例在同一个图形上绘制一些数据,因为否则它会进入图形并且我看不到数据。 您可以在此处[或多或少]看到代码: for i in range(no_of_cust_c
我遇到了 matplotlib 代码,它使用关键字 loc 和 bbox_to_anchor 自定义图例位置。例如: fig.legend([line1, line2], ['series1', 's
在 "Legend location"在 matplotlib 网站的“Legend guide”部分,有一个小脚本,其中第 9 行是 plt.legend(bbox_to_anchor=(0., 1
我是一名优秀的程序员,十分优秀!