Latex and Plotly: font sizes on x- and y-labels

I’m trying to change font size in global x-axis label and y-axis label in multiple subplot, and that is proving impossible.
I know that pyplot is treating global x-label and y-label as annotations, and when I try to enlarge font it works if there is no latex in text of x_title and y_title in fig. make_subplots(). If there is latex, text stays very small. For scientific plots, this is critical failure, can someone tell me if there is workaround or something I missed?

This is code:

zmax=np.max([np.max(median_1),np.max(median_1_all),np.max(median_1_group),np.max(median_1_cluster)])
contours=dict(start=0, end=zmax)

figc=make_subplots(rows=2, cols=2, subplot_titles=('plot1','plot2','plot3','plot4r'), x_title=r'$\rm{12+\log{Z_g}}$', y_title=r'$\rm{Merger \ rate \ [Gyr^{-1}]}$')
figc.add_trace(go.Contour(z=z1, contours=contours, coloraxis='coloraxis'), row=1, col=1)
figc.add_trace(go.Contour(z=z2, contours=contours, coloraxis='coloraxis'), row=1, col=2)
figc.add_trace(go.Contour(z=z3, contours=contours, coloraxis='coloraxis'), row=2, col=1)
figc.add_trace(go.Contour(z=z4, contours=contours, coloraxis='coloraxis'), row=2, col=2)
figc.update_layout(height=1000, width=1200, coloraxis=dict(colorscale='Viridis'), showlegend=False, title_text='Title', font=dict(size=24))
for i in figc['layout']['annotations']:
    i['font'] = dict(size=25) #this is the place where I change font size, but doesn't work for latex
figc.show()

Hi @elizevin,

As in LaTeX, when you defined \documentclass[12pt]{article}, you can increase font size, not setting it explicitly, but using the font size modifiers,\large{}, \Large{}, \huge{}, \Huge{}, for the LaTeX string to be displayed with a bigger fontsize than the default one, i.e. \normalsize{}.

Hence the only change, you have to perform in your code, is to set:

 x_title=r'$\large{\rm{12+\log{Z_g}}}$', y_title=r'$\large{\rm{Merger \ rate \ [Gyr^{-1}]}}$'

or \Large{}, depending on your preferrence, and to remove the annotation updates for font size…

To use the same font family for the entire plot , i.e. for x_title, y_title, as well as subplot titles and subplot ticklabels, I suggest to set font_family='Open Sans' in your figc.layout.

2 Likes

Thank you, this works very well!

(Though it would be real nice to have the option to explicitly change font size, so I hope for that in some future iteration of Plotly :slight_smile: )