Matplotlib文本透明 [英] Matplotlib text transparency

查看:70
本文介绍了Matplotlib文本透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在Matplotlib中更改文本的透明度.set_alpha 不起作用,在文档中我找不到任何相关内容.可能有任何解决方法吗?

I was wondering if it is possible to change the transparency of a text in Matplotlib. set_alpha does not function and in the documentation I couldn't find anything relevant. Are there may be any workarounds?

我想将它连接到一个pick_event.

I want to connect it to a pick_event.

我实际上是在尝试更改图例文本的透明度.虽然我试图用 set_alpha 解决这个问题,但我已经看到我试图修改列表的透明度,因此我无法成功.总而言之,从答案中可以看出,可以使用 set_alpha

I was actually trying to change the transparency of a legend-text. Although I tried to solve the issue with set_alpha, I have overseen that I was trying to modify the transparency of a list and hence I couldn't succeed. To sum up, as can be seen from answers, the transparency can be modified with set_alpha

推荐答案

使用注释将文本添加到图形中时,可以设置alpha.

You can set alpha when using annotate to add the text to your figure.

之前:

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)

ax.annotate("TESTING", xy=(.5, .5), xytext=(.5, .5))

plt.show()

之后:

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)

text = ax.annotate("TESTING", xy=(.5, .5), xytext=(.5, .5))

text.set_alpha(.4)

plt.show()

这篇关于Matplotlib文本透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆