简体   繁体   English

增加 Yellowbrick 平行坐标图的标题、标签和图例的字体大小

[英]Increase font size of title, labels and legend for Yellowbrick Parallel Coordinates Plot

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.但这对我来说没有任何改变,而且我似乎找不到适用于标签、标题和图例的替代方案。

As explained in the linked post , the matplotlib ax elements can be accessed directly to change their properties (color, fontsize, ...).链接帖子中所述,可以直接访问 matplotlib ax元素以更改其属性(颜色、字体大小……)。 That post also suggests replacing visualizer.show() by visualizer.finalize() (which adds ao the title and the legend), so the elements can be updated before showing the plot.那篇文章还建议用visualizer.show()替换 Visualizer.show( visualizer.finalize() (添加标题和图例),因此可以在显示绘图之前更新元素。

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

增加黄砖平行坐标的字体大小

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM