Skip to content

Commit 07c9309

Browse files
authored
Merge pull request #76 from TrueLearnAI/fix-74
fix: Title wrap to prevent offscreen topic labels
2 parents 14b3942 + 592a03a commit 07c9309

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed
65 KB
Loading
160 Bytes
Loading
519 Bytes
Loading

truelearn/tests/test_utils_visualisations.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,30 @@ def test_top_n(self, resources):
308308
plotter.plot(resources[0], top_n=3)
309309
return plotter
310310

311+
def test_bubble_word_overflow(self, resources):
312+
plotter = visualisations.BubblePlotter()
313+
plotter.plot(
314+
resources[0],
315+
topics=[
316+
"Posterior probability",
317+
"Algorithm",
318+
"Machine learning",
319+
"Variance",
320+
"Exponential family",
321+
"Factor graph",
322+
"Rejection sampling",
323+
"Probability",
324+
"Topic model",
325+
"Expected value",
326+
"Bayesian inference",
327+
"Markov chain",
328+
"Importance sampling",
329+
"Normalizing constant",
330+
"Hyperplane",
331+
],
332+
)
333+
return plotter
334+
311335

312336
@file_comparison(plotter_type="plotly")
313337
class TestDotPlotter:

truelearn/utils/visualisations/_bubble_plotter.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing_extensions import Self
33

44
import circlify
5-
from matplotlib import cm, colors, patches
5+
from matplotlib import cm, colors, colormaps, patches
66
import matplotlib.pyplot as plt
77

88
from truelearn.models import Knowledge
@@ -85,7 +85,7 @@ def plot(
8585
plt.xlim(-lim, lim)
8686
plt.ylim(-lim, lim)
8787

88-
cmap = cm.get_cmap("Greens_r")
88+
cmap = colormaps["Greens_r"]
8989

9090
# Normalize data range to colormap range
9191
norm = colors.Normalize(vmin=min(variances) - 0.05, vmax=max(variances) + 0.05)
@@ -104,7 +104,10 @@ def plot(
104104
)
105105
)
106106
plt.annotate(
107-
titles[len(titles) - 1 - i], (x, y), va="center", ha="center"
107+
titles[len(titles) - 1 - i].replace(" ", "\n"),
108+
(x, y),
109+
va="center",
110+
ha="center",
108111
)
109112

110113
# set up the colorbar on the right

0 commit comments

Comments
 (0)