Hi all, I’m furiously trying to create a line plot with several scatter traces added via add_scatter. Traces should be in “lines” mode. I want them to have a color based on value from numerical list (normalised_PDs
), as in continuous color scale. I failed, even though I think it must be very simple. Could you please help me spot the problem here?
import plotly.express as px
PDs = [float(x) for x in"29.7498790938959 29.7498790938959 31.9080006487244 31.9080006487244 35.0832590944697 35.0832590944697 36.397623567387 53.904098545397 53.904098545397 55.6447697872446 55.6447697872446".split(" ")]
normalised_PDs = [(x - min(PDs)) / (max(PDs) - min(PDs)) for x in PDs]
fig_data2 = px.line(
height=800,
width=1600,
title="Compiled HCT116 standard experiments in nano"
)
fig_data2 = fig_data2.update_layout(
xaxis_title="Time, hours",
yaxis_title="Heat flow, W"
)
fig_data2 = fig_data2.update_traces(line=dict(width=2))
# Create a dictionary to map each number of cells to a color
color_map = {}
for experiment, ID, count, pd in zip(data_list, filtered_experiments, cell_numbers, normalised_PDs):
fig_data2 = fig_data2.add_scatter(
x=experiment.iloc[:, 1],
y=experiment.iloc[:, 2],
mode='lines',
line=dict(width=4, color=color),
name=str(int(count/1000)) + "k " + ID,
marker_color=pd
)
fig_data2 = fig_data2.update_xaxes(
linewidth=2,
linecolor='black',
mirror=True,
ticks='inside',
showline=True,
gridcolor="white",
zerolinecolor="darkgray",
title_font=dict(size=40),
tickfont=dict(size=30),
ticklen=20,
tickwidth=4
)
fig_data2 = fig_data2.update_yaxes(
linewidth=2,
linecolor='black',
mirror=True,
ticks='inside',
showline=True,
gridcolor="white",
zerolinecolor="darkgray",
title_font=dict(size=40),
tickfont=dict(size=30),
ticklen=20,
tickwidth=4
)
fig_data2 = fig_data2.update_layout(
overwrite=True,
plot_bgcolor="rgba(0, 0, 0, 0)",
legend=dict(itemsizing='constant'),
legend_font=dict(size=30),
title_font=dict(size=50),
)
fig_data2.show()