Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 239
hans Avatar asked Oct 17 '25 02:10

hans


2 Answers

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

like image 124
vestland Avatar answered Oct 19 '25 18:10

vestland


Installing jupyter-server-mathjax worked for me

like image 22
Luiz Silva Lima Avatar answered Oct 19 '25 18:10

Luiz Silva Lima



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!