Search code examples
pythongraphplotlyline

Finding graph style in Plotly


What is this type of graph(just a single line with one point on the line selected/highlighted) called and how can I graph it in plotly? I'm sure it's something absurdly simple, but I haven't been able to figure it out. See below:

Example

Went through various different plotly pages to try to find another example of this graph, but couldn't find anything.


Solution

  • I don't think plotly has this particular type of chart, but you can achieve this by adding two go.Scatter traces: the first trace with the argument mode='markers+text' to add the marker and the text inside, and the second trace with mode='lines' to add the line segment on the xaxis. Then to make the plot prettier, you can hide the yaxis and the ticks on the xaxis.

    For example:

    import plotly.graph_objects as go
    
    fig = go.Figure()
    
    fig.add_trace(go.Scatter(
        x=[0,96],
        y=[0,0],
        mode='lines',
        line=dict(
            color='blue',
            width=4,
        ),
        showlegend=False
    ))
    
    fig.add_trace(go.Scatter(
        x=[96],
        y=[0],
        text="96",
        textposition="middle center",
        mode='markers+text',
        marker=dict(
            color='black',
            size=30,
            line=dict(
                color='white',
                width=1
            )
        ),
        textfont=dict(
            size=12,
            color="white"
        ),
        showlegend=False
    ))
    
    fig.update_xaxes(showgrid=False, showticklabels=False)
    fig.update_layout(height=300, xaxis_range=[0,100], plot_bgcolor='black')
    fig.update_yaxes(visible=False)
    fig.show()
    

    enter image description here