python - matplotlib中quiverkey的背景颜色

标签 python matplotlib

如何定义 quiverkey 的背景颜色添加到 matplotlib 中的颤动图? 在下面的示例中,如何将其设置为白色以使其更具可读性(即使它覆盖了图形的一部分)?

import matplotlib.pyplot as plt
import numpy.random

numpy.random.seed(2)
x,y = numpy.meshgrid(range(11), range(11))
u,v = numpy.random.randn(101), numpy.random.randn(101)

qv = plt.quiver(x,y,u,v)
plt.quiverkey(qv, .5, 0.8, 5, 'Where is my background?', coordinates='axes',
              fontproperties={'weight': 'bold'}, color='r', labelcolor='g')

enter image description here

最佳答案

您可以使用 set_backgroundcolor 函数更改 quiverkey 文本属性中的背景颜色。一个完整的例子,

import matplotlib.pyplot as plt
import numpy.random

numpy.random.seed(2)
x,y = numpy.meshgrid(range(11), range(11))
u,v = numpy.random.randn(101), numpy.random.randn(101)

qv = plt.quiver(x,y,u,v)
qk = plt.quiverkey(qv, .5, 0.8, 5, 'Here is my background', coordinates='axes',
              fontproperties={'weight': 'bold'}, color='r', labelcolor='g')
t = qk.text.set_backgroundcolor('w')
plt.show()

enter image description here

关于python - matplotlib中quiverkey的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30864449/

相关文章:

Python 多处理 : executing a function with randomness multiple times and getting identical results

python - Python图中的上标

python - 尽管使用 pyplot.show(),但如何使用 matplotlib 保持图形大小不变?

python - 停止 matplotlib 使用 Arial 字体

python - Cartopy 正交投影中的 0 - 360 经度标签

python - 如何拆分数组,然后在 0 和第 N 个值之间追加数组,然后在下一组中重复相同的步骤?

python - 如何给python翻译函数一些特定的符号

python - 类型提示 lambda 函数作为函数参数

python - 为什么 MYSQL DB 在对 Django models.DateTimeField 进行平均时返回损坏的值?

python - matplotlibaxesgrid-附加颜色条?