Sandy
Sandy

Reputation: 359

How to change the font size in axis in Seaborn

I don't know why I tried so many times and still failed in changing the font size on either the x-axis or the y-axis in the plot.

enter image description here

Also, there is a small title in the legend showing Gender Code(which is super small).

I tried

sns.set(font_scale=4)

Or

plt.rcParams["axes.labelsize"] = 20

But it doesn't make any sense. Is that because I used them in the wrong position?

Upvotes: 2

Views: 7602

Answers (2)

bglbrt
bglbrt

Reputation: 2098

As for the font size on the x-and-axes of your plot, and if you're plotting your seaborn graph on a matplotlib axis (which you should be doing), you can do (with axes being the name of the axis):

for tick in axes.xaxis.get_major_ticks():
    tick.label.set_fontsize(10)

for tick in axes.yaxis.get_major_ticks():
    tick.label.set_fontsize(10)

For the font of the legend, you can try:

axes.legend(prop=dict(size=10))

Please tell if this does not solve your problem!


EDIT

With what you're giving as code, I guess you could do:

fig, axes = plt.subplots(figsize=(12, 9))

sns.boxplot(x="Benefits", y="Years In Job", hue="Gender Code", data = wk[(wk.Status=="A")], palette="Set3", ax=axes)

plt.title("Boxplot for Years In Job of Active Employees Under Different Benefit Types ", size=20, loc='right')

plt.xlabel("Benefit Type")

for tick in axes.xaxis.get_major_ticks():
    tick.label.set_fontsize(10)

for tick in axes.yaxis.get_major_ticks():
    tick.label.set_fontsize(10)

axes.legend(prop=dict(size=10))

Upvotes: 5

Infinite
Infinite

Reputation: 764

Add the below line to your code and it should increase the legend size

ax.legend(loc='upper left', fontsize=30)

Hope that helps

Upvotes: 0

Related Questions