0

I'm using a Parallel Coordinates plot, and I wish to increase the font size of the Axis Labels, Legend and Title, can someone help me out? Here's what I have:

from sklearn import datasets
from yellowbrick.features import ParallelCoordinates

iris = datasets.load_iris()
X = iris.data[:, :] 
y = iris.target

features = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width']
classes = ['Iris-setosa', 'Iris-versicolor', 'Iris-virginica']
title = "Plot over Iris Data"

# Instantiate the visualizer
visualizer = ParallelCoordinates(
    classes=classes, features=features, fast=False, alpha=.40, title=title)

# Fit the visualizer and display it
visualizer.fit_transform(X, y)
visualizer.show()

I saw another post here where they did this:

for label in viz.ax.texts:
    label.set_size(12)

But this does not change anything for me, and I can't seem to find an alternative that would work for the labels, title and legend.

Plewis
  • 119
  • 10
  • 1
    Could you create a standalone example including the imports? Could you add a link to "the other post"? – JohanC May 12 '22 at 14:08
  • I've added reproducible example :) I will try your suggestion now. – Plewis May 12 '22 at 14:16
  • Your suggestion is great for the axis values, any suggestion for the labels and the title as well? Thank you. – Plewis May 12 '22 at 14:17

1 Answers1

1

As explained in the linked post, the matplotlib ax elements can be accessed directly to change their properties (color, fontsize, ...). That post also suggests replacing visualizer.show() by visualizer.finalize() (which adds a.o. the title and the legend), so the elements can be updated before showing the plot.

from sklearn import datasets
from yellowbrick.features import ParallelCoordinates

iris = datasets.load_iris()
X = iris.data[:, :]
y = iris.target

features = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width']
classes = ['Iris-setosa', 'Iris-versicolor', 'Iris-virginica']
title = "Plot over Iris Data"

# Instantiate the visualizer
visualizer = ParallelCoordinates(
    classes=classes, features=features, fast=False, alpha=.40, title=title)

# Fit the visualizer and display it
visualizer.fit_transform(X, y)
visualizer.finalize()  # creates title, legend, etc.

visualizer.ax.tick_params(labelsize=22)  # change size of tick labels
visualizer.ax.title.set_fontsize(30)  # change size of title

for text in visualizer.ax.legend_.texts:  # change size of legend texts
     text.set_fontsize(20)

visualizer.fig.tight_layout()  # fit all texts nicely into the surrounding figure
visualizer.fig.show()

increasing font sizes for yellowbrick parallel coordinates

JohanC
  • 71,591
  • 8
  • 33
  • 66