0

I am attempting to change some of the properties of a trace I've added to each facet of a plotly scatterplot.

Essentially what I'm trying to do is add a reference y=x line to each of these plots, and from what I've seen it appears using fig.add_trace is the best way to do this.

However, there are some properties of these traces I have not been able to change. In particular, I would like to be able to:

  1. Change the trace color (they should all be the same color)
  2. Remove the points at the ends of the trace (to create just a reference line)
  3. Change the linestyle (ie, dashed)

So far, my code looks something like this

g = px.scatter(data_frame = df,
               color='color_field',
               facet_col='facet_field',
               x='field1',
               y='field2')
line = (5,15)
g.add_trace(go.Scatter(x=line, y=line),
            row='all',
            col='all',
            exclude_empty_subplots=True)
g.update_traces(showlegend=False)
g.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1]))
g.show()

This works reasonably well, and produces an output that looks like this.

enter image description here

However the traces I've added all come up as different colors and have a point. I'd like to be able to set both the color and linestyle for these traces, as well as remove the points themselves, but haven't found a way to do this yet.

1 Answers1

0

You would have to declare the color, the dash type, and marker style.

g = px.scatter(data_frame = df,
               color='color_field',
               facet_col='facet_field',
               x='field1',
               y='field2')
line = (5,15)
g.add_trace(go.Scatter(x=line, 
                       y=line,
                       mode='lines',
                       line=dict(color='blue',
                                 dash='dash')
                      ),
            row='all',
            col='all',
            exclude_empty_subplots=True)
g.update_traces(showlegend=False)
g.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1]))
g.show()
amance
  • 883
  • 4
  • 14