Black Lives Matter. Please consider donating to Black Girls Code today.

Error bars from .csv file

How can I display error bars from a .csv file, i.e. error_y should take the values as specified in “10 Min Std Dev”? Thanks a lot for your help!


import plotly.graph_objects as go
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/wind_speed_laurel_nebraska.csv')

fig = go.Figure([
    go.Scatter(
        name='Measurement',
        x=df['Time'],
        y=df['10 Min Sampled Avg'],
        mode='markers',
        marker=dict(color='red', size=5),
        
                    
        error_y=dict(
            type='data', # value of error bar given in data coordinates
            array=[1, 2, 3],
            visible=True, color='blue', width=5, thickness=0.1)
    )
 ])

fig.update_layout(template='simple_white',
    yaxis_title='Wind speed (m/s)',
    title='Continuous, variable value error bars',
    hovermode="x"
)
    
fig.show()

Hi @windrose,

Welcome to the community!

I am not sure what you intended to to with array=[1, 2, 3], the error_y data should be the same length as x and y, that’s why it is not working. Here is the way it can be done using plotly express:

hope it helps, Alex-

import plotly.express as px

fig = px.scatter(df, x='Time', y='10 Min Sampled Avg', error_y='10 Min Std Dev')

fig.update_traces(
    error_y=dict(color='blue', width=5, thickness=0.1),
    marker=dict(color='red', size=5)
)

fig.update_layout(template='simple_white',
    yaxis_title='Wind speed (m/s)',
    title='Continuous, variable value error bars',
    hovermode="x"
)
    
fig.show()

1 Like

Great, thanks a lot!