Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
508 views
in Technique[技术] by (71.8m points)

matplotlib - sns.catplot - how can i make my legend bigger?

I have this code:

ax = sns.catplot(x='account_name', y='cnt', hue='threat_campaigns',data=df_mitigation,kind='bar', height=15, aspect=3.1, palette='coolwarm' )
ax.fig.suptitle("Accounts' violations disribuation over the last week", fontsize=40)
plt.yscale("log")


plt.xlabel('Account', fontsize=40)
plt.ylabel('Number of requests', fontsize=40)
plt.setp(ax._legend.get_title(), fontsize=40)

plt.show()

see what i get as in screenshot - everything is very small - how can i make it bigger.enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can update the rcParams dictionary using an example like with sns.plotting_context(rc={"legend.fontsize":24, "legend.title_fontsize":24}):.

Reproducible example.

df = sns.load_dataset('flights')
with sns.plotting_context(rc={"legend.fontsize":24, "legend.title_fontsize":24}):
    ax = sns.catplot(x='year', y='passengers', hue='month', data=df, kind='bar', height=15, aspect=3.1, palette='coolwarm')
    plt.show()

Before:

enter image description here

After:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...