# Add legend to the plotly express

**URL:** <https://community.plotly.com/t/add-legend-to-the-plotly-express/55014>\
**Category:** 📊 Plotly Python\
**Created:** [July 25, 2021, 2:24pm UTC](https://community.plotly.com/t/add-legend-to-the-plotly-express/55014 "2021-07-25T14:24:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anastasia\_l](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@anastasia\_l](https://community.plotly.com/u/anastasia_l)\
**Post date:** [July 25, 2021, 2:24pm UTC](https://community.plotly.com/t/add-legend-to-the-plotly-express/55014/1 "2021-07-25T14:24:51Z")

</div>

Hi!

I’m following this tutorial: [PCA Visualization | Python | Plotly](https://plotly.com/python/pca-visualization/)  
I use the following code:

```auto
pca = PCA(n_components=2)
components = pca.fit_transform(X)

colorsIdx = {'0': 'blue', '1': 'yellow'}
fig = px.scatter(components, x=0, y=1, color=df_stimuli['is_500_days'],
                labels={'0': 'PC 1', '1': 'PC 2'})
fig.update_layout(title_text=f'{brain_area}', title_x=0.5)
fig.show()

```

But instead of a legend with 2 classes (in my case the column df\_stimuli[‘is\_500\_days’] contains only 0’s and 1’s) it creates a colorbar.

If I add

```auto
fig.update(layout_coloraxis_showscale=False)
fig.update(layout_showlegend=True)

```

It removes the colorbar, but no legend is shown.
