微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

更改用 Yellowbrick 创建的分散图中的标题

如何解决更改用 Yellowbrick 创建的分散图中的标题

我想更改使用 Yellowbrick 创建的分散图的标题

我使用以下代码

wl = []
with open('my-text.txt','r',encoding='utf8') as f:
   wl = f.read().split()
   
topics = ['δὲ']
plt.figure(figsize=(16,.5))
visualizer = dispersionPlot(topics)
visualizer.fit([poll_wl])
visualizer.show()

创建的图的标题是“词法散布图”。我想使用自定义标题

解决方法

您可以从visalizer获取figure,然后像这样设置唯一的axes对象的标题文本:

visualizer.fig.get_axes()[0].title.set_text("My Title")

同样可以用 visualizer.set_title("My Title") 完成,尽管它似乎没有明确包含在 docs 中。

示例(来自the docs):

from yellowbrick.text import DispersionPlot
from yellowbrick.datasets import load_hobbies

corpus = load_hobbies()
text = [doc.split() for doc in corpus.data]
target_words = ['Game','player','score','oil','Man']
visualizer = DispersionPlot(target_words)
visualizer.fit(text)
visualizer.show()

visualizer.set_title("My Title")

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。