# Create colour gradient for lines in Scattermapbox (Python)

**URL:** <https://community.plotly.com/t/create-colour-gradient-for-lines-in-scattermapbox-python/57110>\
**Category:** 📊 Plotly Python\
**Created:** [September 29, 2021, 1:55pm UTC](https://community.plotly.com/t/create-colour-gradient-for-lines-in-scattermapbox-python/57110 "2021-09-29T13:55:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lizard](https://avatars.discourse-cdn.com/v4/letter/l/dfb087/32.png) [@lizard](https://community.plotly.com/u/lizard)\
**Post date:** [September 29, 2021, 1:55pm UTC](https://community.plotly.com/t/create-colour-gradient-for-lines-in-scattermapbox-python/57110/1 "2021-09-29T13:55:03Z")

</div>

I’m mapping lines in `plotly.graph_objects.Scattermapbox` with `fig.add_trace`. Ideally, I would like to change the colour of the lines, such that it corresponds to an attribute in another column. For example:

| Line | Attribute |
| --- | --- |
| LINE01 | 45 |
| LINE02 | 60 |
| LINE03 | 270 |

I can’t figure out how to do this. When I create my plot, each line appears as a legend entry (`LINE01` appears as `trace 0`, etc.) This is my code:

```auto
import plotly.graph_objects as go
fig = go.Figure()

for i in range(len(df)):
    fig.add_trace(go.Scattermapbox(
        mode = "lines",
        lon = [df['lon.start'][i], df['lon.end'][i]],
        lat = [df['lat.start'][i], df['lat.end'][i]],
        line = dict(width = 3)
        )
    )

```

How can I change it such that my legend is grouped by the `Attribute` column to create a discrete colour scale?

I’ve tried tweaking my code to add the following, but it doesn’t work

```auto
u_attribute = np.unique(df['Attribute'].values)
d = dict(zip(u_attribute, np.arange(len(u_attribute))))

line_color = [d[s] for s in df['Attribute']

```
