I’ve been trying to save the output into .html files but it seems that it doesn’t read the characters in the axis labels, only prints the equation as I give in the Latex form. Is there a way to work around that?
Hi @Tas
welcome to the Plotly community.
can you please share an example code/data with us so we can replicate the same error on our computer and try to solve it.
Hi @adamschroeder! The code is below:
import plotly.express as px
import plotly.graph_objects as go
fig = px.scatter(df_kynbb, x='Radius', y='Spin',
color='Edd_Rat', color_continuous_scale='hot_r',
hover_data=['Obs_ID','Edd_Rat', 'Accretion Rate', 'Temperature (keV)', 'Disk Fraction'])
fig.add_trace(go.Scatter(x=[1.61,1.61], y=[0.,1.5], mode="lines",
line=dict(color='darkslategray',
width=2,
dash='dash'),
name='a=0.98'))
fig.add_trace(go.Scatter(x=[3.39,3.39], y=[0.,1.5],
mode="lines",
line=dict(color='cyan',
width=2,
dash='dash'),
name='a=0.7'))
fig.add_trace(go.Scatter(x=[6,6], y=[0.,1.5],
mode="lines",
line=dict(color='skyblue',
width=2, dash='dash'),
name='a=0'))
fig.add_trace(go.Scatter(x=[9.09579989455154,9.09579989455154], y=[0.,1.5], mode="lines",
line=dict(color='red',
width=2,
dash='dash'),
name='Mean'))
fig.update_traces(marker_size=20)
fig.update_xaxes(range=[0.1, 25.],
showgrid=True, zeroline=False, linewidth=1, linecolor='black', ticks="inside")
fig.update_yaxes(range=[0., 1.1],
showgrid=True, zeroline=False,linewidth=1, linecolor='black', ticks="inside")
fig.update_layout({'plot_bgcolor': 'rgba(0, 0, 0, 0)', 'paper_bgcolor': 'rgba(0, 0, 0, 0)'},
coloraxis_colorbar_y=-0.25, coloraxis_colorbar=dict(orientation="h"),
xaxis_title=r'$\mathrm{R_\mathrm{inner}}$', yaxis_title="Spin",
title={'text': "LMC X-3", 'y':0.95, 'x':0.5, 'xanchor': 'center', 'yanchor': 'top'},
legend_title="ISCO")
fig.data = (fig.data[4],fig.data[3],fig.data[2],fig.data[1],fig.data[0])
fig.show()
fig.write_html("r_spin.html")
Here’s also a screenshot of the output from the file.
Thanks a lot!
thanks @Tas
where is the df_kynbb
? can you share your data or a sample of it please. I can’t run the code without the data.
Apologies @adamschroeder… Here’s a subset of the data:
data = {'Radius': [20.7423, 16.43, 9.4723, 10., 15., 19., 20.], 'Spin':[0.5, 0.4, 0.4, 0.8, 0.7, 0.8, 0.3],
'Obs_ID':[166,168,169,170,175,176,178],
'Edd_Rat':[0.4887, 0.3362, 0.2136451, 0.2325632, 0.28437324, 0.467283, 0.32627312],
'Accretion Rate': [0.00028943, 0.00003478, 0.000743287, 0.00025757, 0.000758943, 0.0006534786, 0.000327846],
'Temperature (keV)':[0.1, 0.4, 0.9, 0.4, 0.5, 0.7, 0.6],
'Disk Fraction': [0.1, 0.3, 0.3, 0.6, 0.999, 0.892, 0.76]}
df_kynbb= pd.DataFrame(data)
@Tas To get LaTeX formula displayed in the saved html file, just save it as:
fig.write_html("r_spin.html", include_mathjax='cdn')
@adamschroeder to give a solution related to xaxis_title you don’t need data:
import plotly.graph_objects as go
fig = go.Figure()
fig.update_layout(width=400, height=400,
xaxis_title='$\mathrm{R_\mathrm{inner}}$', yaxis_title="Spin")
fig.show()
fig.write_html("r_spin.html", include_mathjax='cdn')
@empet That worked, thanks a lot!