# How to specify color legend labels in mapbox plot?

**URL:** <https://community.plotly.com/t/how-to-specify-color-legend-labels-in-mapbox-plot/75405>\
**Category:** 📊 Plotly Python\
**Created:** [May 19, 2023, 10:50am UTC](https://community.plotly.com/t/how-to-specify-color-legend-labels-in-mapbox-plot/75405 "2023-05-19T10:50:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterho](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@peterho](https://community.plotly.com/u/peterho)\
**Post date:** [May 19, 2023, 10:50am UTC](https://community.plotly.com/t/how-to-specify-color-legend-labels-in-mapbox-plot/75405/1 "2023-05-19T10:50:31Z")

</div>

Maybe this us a beginner’s question…  
I am trying to plot a mapbox scatter of timestamped values. To get a nice continuous color range, I map the timestamps to integers. However, in the end I want to see the original timestamps again in the color scale legend, not the integers. How do I do that?

Picture attached. The labels below “color” should display the timestamps.

```auto
df_nonan = df.dropna(subset=['Counts_DC_#cm3'])
date_to_val = df_nonan['DateTime'].map(pd.Series(data=np.arange(len(df_nonan)), index=df_nonan['DateTime'].values).to_dict())

fig_map = go.Figure()
fig_map = px.scatter_mapbox(df_nonan, lat="Lat", lon="Lon", color=date_to_val, size="Counts_DC_#cm3", 
                            color_continuous_scale=px.colors.sequential.Inferno, size_max=25, zoom=15, height=800,
                            )
fig_map.update_traces(
     patch=dict(mode='text+markers', text=df_nonan['DateTime'], marker_opacity=0.2),
     selector=dict(type='scattermapbox'))
fig_map.show()

```

 ![Screenshot 2023-05-19 at 12.48.29](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/7/2/72409a31b6d9e9992764937e223666336912baad.jpeg)

---

<div class="post-metadata">

**Author:** ![Skiks](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/skiks/32/26561_2.png) [@Skiks](https://community.plotly.com/u/Skiks)\
**Post date:** [May 19, 2023, 1:07pm UTC](https://community.plotly.com/t/how-to-specify-color-legend-labels-in-mapbox-plot/75405/2 "2023-05-19T13:07:51Z")

</div>

Hi @peterho!  
I have never had the occasion to use `px.scatter_mapbox`, but you should be able to map the coloraxis tick labels to anything you want, like:

```python
import plotly.express as px
df = px.data.tips()
fig = px.scatter(df, x="total_bill", y="tip", color="size",
                 title="Numeric 'size' values mean continuous color")
fig.update_coloraxes(
    colorbar_tickvals=[1, 2, 3, 4, 5, 6],
    colorbar_ticktext=['One', 'Two', 'Three', 'Four', 'Five', 'Six'],
)

```

![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/2/6/26df9908336b69d094c7ff306dafa631c891b468.png) ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/9/8/989a121072fcb7fe003b80b104a124d257479f60.png)

---

<div class="post-metadata">

**Author:** ![Skiks](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/skiks/32/26561_2.png) [@Skiks](https://community.plotly.com/u/Skiks)\
**Post date:** [May 19, 2023, 1:42pm UTC](https://community.plotly.com/t/how-to-specify-color-legend-labels-in-mapbox-plot/75405/3 "2023-05-19T13:42:50Z")

</div>

Here we go, to find the lists for tickvals/ticktext, try:

```python
n_ticks = 6
step = (date_to_val.max() - date_to_val.min()) / (n_ticks-1)
tickvals = [date_to_val.min() + step * i for i in range(n_ticks)]

df['DateTime'] = pd.to_datetime(df['DateTime'])
step = (df['DateTime'].max() - df['DateTime'].min()) / (n_ticks-1)
ticktext = [df['DateTime'].min() + step * i for i in range(n_ticks)]

fig.update_coloraxes(
    colorbar_tickvals=tickvals,
    colorbar_ticktext=ticktext,
)

```
