Yellowbrick:在 Yellowbrick 生成的图表上增加字体大小 [英] Yellowbrick: Increasing font size on Yellowbrick generated charts

查看:42
本文介绍了Yellowbrick:在 Yellowbrick 生成的图表上增加字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法增加 Yellowbrick 生成的图表上的字体大小?我觉得阅读课文很困难.我在文档中找不到任何内容.

Is there a way to increase the font size on Yellowbrick generated charts? I find it difficult to read the text. I wasn't able to find anything on it in the documentation.

我在Jupyter Notebook中使用Python 3.6,Yellowbrick 0.5.

I'm using Python 3.6, Yellowbrick 0.5 in a Jupyter Notebook.

推荐答案

更新:yellowbrick API 现在使用 viz.show 而不是 viz.poof.

Update: The yellowbrick API now uses viz.show instead of viz.poof.

Yellowbrick 包装 matplotlib 以生成可视化效果,因此您可以通过直接调用 matplotlib 来影响图形的所有视觉设置.我发现最简单的方法是访问 Visualizer.ax 属性并直接在其中设置内容,当然,您当然可以直接使用 plt 进行管理全球数字.

Yellowbrick wraps matplotlib in order to produce visualizations, so you can influence all the visual settings for the figure by making calls directly to matplotlib. I find that the easiest way to do that is by getting access to the Visualizer.ax property and setting things directly there, though of course, you can use plt directly to manage the global figure.

以下是一些代码,它们产生的示例与您的示例类似:

Here's some code that produces an example similar to yours:

import pandas as pd 

from yellowbrick.classifier import ConfusionMatrix 
from sklearn.ensemble import AdaBoostClassifier
from sklearn.model_selection import train_test_split as tts

data = pd.read_csv('examples/data/occupancy/occupancy.csv') 

features = ["temperature", "relative humidity", "light", "C02", "humidity"]

# Extract the numpy arrays from the data frame 
X = data[features].as_matrix()
y = data.occupancy.as_matrix()

X_train, X_test, y_train, y_test = tts(X, y, test_size=0.2)

clf = AdaBoostClassifier()
viz = ConfusionMatrix(clf)

viz.fit(X_train, y_train)
viz.score(X_test, y_test)
viz.show()

这导致生成以下图像:

您可以在得分之后和 show 之前开始管理图形,如下所示:

You can start to manage the figure right after score and before show as follows:

viz.fit(X_train, y_train)
viz.score(X_test, y_test)

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

viz.show()

这将产生以下图像,其内部带有稍大的字体:

This produces the following image, with slightly larger fonts on the inside:

这里发生的是,我正在直接访问包含绘图的所有元素的可视化器上的matplotlib Axes对象.网格中间的标签是Text对象,因此我遍历所有将其大小设置为12pt的文本对象.如果需要,此技术可用于在显示之前修改任何视觉元素(通常我使用它在可视化上添加注释).

What's happening here is that I'm directly accessing the matplotlib Axes object on the visualizer that contains all the elements of the drawing. The labels in the middle of the grid are Text objects, so I loop through all the text objects setting their size to 12pt. This technique can be used to modify any visual element before display if required (typically I use it to put annotations on the visualization).

但是请注意, show 调用了 finalize 函数,因此在调用 show ,或者通过调用 finalizeplt.show() 来短路 show.

Note, however, that show calls a finalize function, so some things like the title, axis labels, etc. should be modified after calling show, or by short-circuiting show by calling finalize then plt.show().

此特定代码仅适用于 ConfusionMatrix ,但我添加了issue 在 Yellowbrick 库中,希望在将来使这更容易或至少更易读.

This particular code only works with the ConfusionMatrix, but I've added an issue in the Yellowbrick library to hopefully make this easier or at least more readable in the future.

这篇关于Yellowbrick:在 Yellowbrick 生成的图表上增加字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆