0

I would like to change the title of the dispersion plot created using yellowbrick:

I use the following code:

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()

The plot created has the title "Lexical Dispersion Plot". I would like to use a customized title.

1 Answers1

1

You can get the figure from visalizer and then set the title text of the only axes object like this:

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

The same can be done with visualizer.set_title("My Title") although it appears to not be explicitely included in the docs.

Example (from 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

Stef
  • 28,728
  • 2
  • 24
  • 52