pythonlatexplotlyyaxis

Latex in y-axis title in plotly not working


Can you please tell me why fig.update_yaxes(title=dict(text="$\text{This is a test:} \sqrt{2^4}$") does not work in the following code

import plotly.express as px
fig = px.bar(df, x=["Apples", "Oranges"], y=[10,20], color=["Here", "There"],
    labels=dict(x="Fruit", y="Amount", color="Place")
)

fig.update_yaxes(title=dict(text="$\text{This is a test:} \sqrt{2^4}$", font_size=16)
                )

fig.show()

gives

enter image description here


Solution

  • To know for sure why it's not working on your end I would have to know:

    1. your plotly version, and
    2. how you're displaying your figure (JupyterLab?), and
    3. whether or not there's enough space for your title where you're outputting your figure.

    Because it works fine on my end:

    enter image description here

    I'm running Plotly '4.14.3' in JupyterLab.

    Same code as yours:

    import plotly.express as px
    fig = px.bar(df, x=["Apples", "Oranges"], y=[10,20], color=["Here", "There"],
        labels=dict(x="Fruit", y="Amount", color="Place")
    )
    
    fig.update_yaxes(title=dict(text="$\text{This is a test:} \sqrt{2^4}$", font_size=16)
                    )
    
    fig.show()
    

    Edit 1: Google Chrome

    It turns out that this issue might be related to the browser your running. I'm running Microsoft Edge at the moment. But here's the same code and figure using Chrome wiht no title:

    enter image description here