I’d like to put the value of the x-axis with “months” in this figure. Nevertheless, the x value at the top seems to be impossible to modify. Any ideas?
import plotly.express as px
import pandas as pd
import numpy as np
# Generate random data
np.random.seed(42)
num_points = 100
time_values = np.linspace(0, 12, num_points)
survival_prob_values = np.random.uniform(0, 1, num_points)
tumor_grade_values = np.random.choice(['Grade 1', 'Grade 2', 'Grade 3'], num_points)
df_km = pd.DataFrame({
'time': time_values,
'survival_prob': survival_prob_values,
'tumor_grade': tumor_grade_values
})
hovertemplate = '%{y:.2f}%'
fig = px.line(df_km, x='time', y='survival_prob', color=column_factor)
fig.update_xaxes(spikemode='across', spikesnap='hovered data', spikethickness=1)
fig.update_layout(
xaxis_title='Time (months)', yaxis_title=f'{name_target} probability',
legend=dict(title='Tumor grade'),
hovermode="x unified",
hoverlabel=dict(bgcolor="black", font_family="Rockwell"))
fig.update_traces(mode="markers+lines", marker=dict(size=3), hovertemplate=hovertemplate)
Thanks!