[Python] How to have a line break in math mode in plotly?

Discussão em 'Python' iniciado por Stack, Julho 4, 2025.

  1. Stack

    Stack Membro Participativo

    Suppose you would like to have a line break in the math mode text in plotly. The following solutions have been tried, but none of them is working in different reasons:

    import plotly.graph_objects as go

    fig = go.Figure()
    fig.add_trace(go.Box(y=[10, 14]))

    fig.update_layout(xaxis_title="$\alpha \\ \beta$") # causes to_image error
    # fig.update_layout(xaxis_title=r"$\alpha \\ \beta$") # no breaks between math shape of alpha and beta
    # fig.update_layout(xaxis_title="$\\alpha$<br>$\\beta$") # only shows math shape of alpha and no beta at all!
    # fig.update_layout(xaxis_title="$\\alpha \\\\ \\beta$") # # no breaks between math shape of alpha and beta
    # fig.update_layout(xaxis_title="$$\\alpha \\\\ \\beta$$") # no breaks between math shape of alpha and beta
    # fig.update_layout(xaxis_title="$$\\alpha$$ <br> $$\\beta$$") # # only shows math shape of alpha and no beta at all!

    fig.show()
    fig.write_image("this_image.pdf")


    So, the question is how to set a line break in a math mode text?

    Continue reading...

Compartilhe esta Página