0
votes

Plotly allows a user to specify a color of a marker scatter plot based on an integer value e.g.:

go.Scatter(x=x,
           y=y,
           mode='markers',
           marker=dict(color=i))

where i is an integer. However, if I want to specify the color of a line, neither of the following work:

go.Scatter(x=x,
           y=y,
           mode='lines',
           marker=dict(color=i))

go.Scatter(x=x,
           y=y,
           mode='lines',
           line=dict(color=i))

How do I specify the color of a Plotly line using an integer?

1

1 Answers

0
votes

In your case the color must be an array of numbers, not a number.

According to Plotly documentation:

Sets themarkercolor. It accepts either a specific color or an array of numbers that are mapped to the colorscale relative to the max and min values of the array or relative to marker.cmin and marker.cmax if set.

Example:

import plotly.graph_objects as go

fig = go.Figure(data=go.Scatter(
    x=[1, 2, 3, 4],
    y=[10, 11, 12, 13],
    mode='markers',
    marker=dict(size=[40, 60, 80, 100],
                color=[0, 1, 2, 3])
))

fig.show()