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

Fig.add_vline not working?

I’m currently using google colab. And fig.add_vline seems to be not working.

fig = go.Figure()
plot_names = ['nan', 'Private', 'Funded Start-up', 'Other', 'Public', 'Early Start-up', 'NGO']

for types, names in zip_longest(unique_companies, plot_names):
    try:
        if types == 'Pvt Ltd':
            fig.add_trace(go.Scatter(
                y = company_type_cdi['{}'.format(types)].values,
                x = company_type_cdi['{}'.format(types)].index,
                mode = 'lines+markers',
                marker_color = colors[0],
                name = names
            ))
        else:
            fig.add_trace(go.Scatter(
                y = company_type_cdi['{}'.format(types)].values,
                x = company_type_cdi['{}'.format(types)].index,
                mode = 'lines',
                marker_color = 'gray',
                name = names
            ))
    except:
        pass

fig.add_vline(x=0.86, line_width=3, line_dash="dash", line_color="yellow")

fig.update_traces(line_width = 0.5, marker_size = 3)
fig.update_yaxes(visible = False)
fig.update_layout(title = 'Company Type and City Development Index')

fig.show()

the error is :
AttributeError: ‘Figure’ object has no attribute ‘add_vline’

Was it changed recently?

Perhaps you could work with shapes?

Set your layout before adding shapes (vline)

@biscuit
I suspect that google colab provides an old Plotly version.

type in a colab cell:

import plotly
print(plotly.__version__)

add_vline was introduced in plotly 4.12.0

2 Likes

I get the same error using the first example in Horizontal Vertical Shapes.

My current version is Plotly 5.3.1