How to edit the plot outputed by the viz.show?

74 views
Skip to first unread message

ZHE WANG

unread,
Mar 5, 2020, 11:22:45 AM3/5/20
to Yellowbrick
Dear Shabhareesh,

I used Yellowbrick to analyze the data recently. The plot is good but I can not edit the font size, line and so on.
How can  I edit the plot?

Thanks!

Yours,
Zhe

Yellowbrick

unread,
Mar 5, 2020, 4:10:44 PM3/5/20
to Yellowbrick
Thanks for checking out Yellowbrick and glad you're enjoying it! It is possible to modify many attributes of the visualizers (some examples here), including the fontsize for some (like ConfusionMatrix). Which visualizer are you using?

ZHE WANG

unread,
Mar 6, 2020, 2:39:48 AM3/6/20
to Yellowbrick
Hi,

Thanks for your reply. I am using the Regression Visualizers to complete my ML model. But I do not find a way to adjust the output plot by
"visualizer.show () ", such as the font of the legend. So, I try to edit the plot by matplotlib and output the custom plot by "plt.savefig("peplot.pdf")". However, since I am a beginner in python, I can't draw a plot as beautiful as "visualizer.show () ".

Yours,
Zhe

在 2020年3月6日星期五 UTC+8上午5:10:44,Yellowbrick写道:

Benjamin Bengfort

unread,
Mar 10, 2020, 8:25:51 AM3/10/20
to Yellowbrick
Hello, 

The basic way to modify the plot is to get access to the axes object that the visualizer is drawing on using the `viz.ax` property; note however that some visualizers have multiple axes objects, for example the ResidualsPlot has an axes for the scatter plot and the histogram. Often, this is sufficient for basic changes or to plot additional data.

Changing the font of the legend is a bit tricker, however. Using the `viz.ax` property, you'd have to loop through the children of the axes and look for the legend(s), then set the front property as follows:

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

legends
= [c for c in viz.ax.get_children() if isinstance(c, mpl.legend.Legend)
for legend in legends:
    plt
.setp(legend.texts, family='monospace')

plt
.savefig("peplot.pdf")


A more complex method of modifying the matplotlib output is to use matplotlib rc params:

import yellowbrick
import matplotlib as mpl

mpl
.rc('font', family='Times New Roman')


Please note that yellowbrick is imported first, so yellowbrick's default settings are applied, then you can modify the settings to your custom settings. 

If you need to reset all styles and start over, you can use `yellowbrick.style.rcmod.reset_orig()` or `yellowbrick.style.rcmod.reset_defaults()` 

Hope this helps!

Message has been deleted

ZHE WANG

unread,
Mar 11, 2020, 11:47:21 AM3/11/20
to Yellowbrick
Thank you very much!

在 2020年3月10日星期二 UTC+8下午8:25:51,Benjamin Bengfort写道:
Reply all
Reply to author
Forward
0 new messages