Search code examples
pythonfontslabelseabornrelplot

Maintain the font of the whole plot (x and y axis), but keeping the labels on top of the graph smaller so they dont overlap


Basically I am using different columns to plot my data using seaborn. I use sns.set_context("talk") so the font is big enough to be read properly. However, since the specifications of the parameters are quite long, the text on top of the graphs overlap. The quick solution is change the font sns.set_context("paper") or apply any scale to reduce the size. However, all the font gets reduced including the x and y axis. Making it very difficult to read. and I want to keep x and y axis at that font.

Do you know if I can change the size of the text that overlap, but keeping the x and y text at that font? Or tell seaborn relplot to make a line break on the labels on top?

I tried to reduce size, but everything get reduces. I tried a line break, but since I dont introduce the labels, I cant. I tried to individually increase the size of x and y font, but since I have 16 graphs, it makes it annoying and long.

sns.set_style("ticks") sns.set_context("talk") ax1=sns.relplot( data=df,x="Impeller speed (rpm)", style="Mineral content (g/g fibre)",y="Power draw (W)", palette=palette,ci=68,kind="line",markers=True,size="size (mm)",hue="Formulation", col="size (mm)",row="Mineral content (g/g fibre)") plt.show()

Formulation size (mm) Mineral content (g/g fibre) Imepeller speed (rpm) Power draw (W) Viscosity (Pas)
Water 1 0 200 20 0.00159
Water 1 0 300 21 0.00159
A 1 0 200 22 0.0018
A 1 0 300 25 0.0018
B 1 0 200 26 0.0059
B 1 0 300 29 0.0059
Water 4 0 200 22 0.00159
Water 4 1 300 32 0.00159
C 1 0 200 20 0.1059
C 1 0 300 25 0.1059

enter image description here


Solution

  • for ax in ax1.axes.flat: # Iterate over each axes object
        # Change the fontsize of each title 
        ax.set_title(ax.get_title(), fontsize='small')  #ax.get_title function returns the title text string.