Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

Add dashed line to scatter plot

I have a plotly go.scatter plot and I’d like to add dashed line to annotate market equilibrium.

Here’s an example:

eb38b8c5e4ea4242bc242cc628127c62314a6f32

Code:

@app.callback(Output('price-graph', 'figure'),
              [
                 Input('submarket-select', 'value')
              ]
             )
def update_price(val):

    if val:

        fig1 = go.Figure(

            data=[go.Scatter(

                            x=dff['Count'],
                            y=dff['Price'],
                            mode='markers'

                            )
                  ],

            layout=go.Layout(

                xaxis=dict(
                    title='Number',
                    tickfont=dict(family='Rockwell', color='crimson', size=14)
                ),

                yaxis=dict(
                    title='Price ($ SF/Ft.)',
                    showticklabels=True
                ),

            )
        )

        return fig1

    else:

        return (no_update)

How do I add a dashed line connecting x and y axis?

you can use:

spikemode
Parent: layout.xaxis
Type: flaglist string. Any combination of "toaxis" , "across" , "marker" joined with a "+"
Examples: "toaxis" , "across" , "toaxis+across" , "toaxis+across+marker"
Default: "toaxis"

Determines the drawing mode for the spike line If “toaxis”, the line is drawn from the data point to the axis the series is plotted on. If “across”, the line is drawn across the entire plot area, and supercedes “toaxis”. If “marker”, then a marker dot is drawn on the axis the series is plotted on

Thanks. This is helpful, however, only draws dashed when you hover over the markers.

Is there a way to pass [x,y] datapoint to draw the spikelines? I’d like to fix the spikelines and always display them.

in that case is better if you add a trace with markers. Then hide the legend of that trace and if you want, use the legendgroup property in the trace so you will have the main trace and the dashed line in one legend label