# Map colors different from scale

**URL:** https://community.plotly.com/t/map-colors-different-from-scale/18117
**Category:** 📊 Plotly Python
**Created:** [January 15, 2019, 4:13am UTC](https://community.plotly.com/t/map-colors-different-from-scale/18117 "2019-01-15T04:13:21Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![keryums](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/keryums/32/5287_2.png) [@keryums](https://community.plotly.com/u/keryums)
#### Post date: [January 15, 2019, 4:13am UTC](https://community.plotly.com/t/map-colors-different-from-scale/18117/1 "2019-01-15T04:13:21Z")

</div>

![newplot%20(1)](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/e/e296899919bed8380f1c3296b3533b4267fa992b.png)

I can’t figure out why the colors on my map don’t reflect the color scale. Texas should be ~35M. Any tips? Code below

```
import plotly.plotly as py
import plotly 
plotly.tools.set_credentials_file(username='keryums', api_key='G5YsVJOebOZh0nhwk44q')

data = [ dict(type='choropleth',
              colorscale = 'Viridis',
              autocolorscale=True,
              locations=state_by_sex.state_code,
              z=state_by_sex.veterans,
              locationmode='USA-states'
             )
       ]

layout = dict(title = 'Map of Veteran Suicide Rates by State',
              geo = dict(scope='usa',
                        projection=dict(type ='albers usa'),
                        showlakes = True,
                        lakecolor = 'rgb(255,255,255)')
             )

fig = dict(data=data, layout=layout)
py.iplot(fig, filename = 'd3-choropleth-map')
```

---

<div class="post-metadata">

### Author: ![jmmease](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jmmease/32/3706_2.png) [@jmmease](https://community.plotly.com/u/jmmease)
#### Post date: [January 15, 2019, 11:10am UTC](https://community.plotly.com/t/map-colors-different-from-scale/18117/2 "2019-01-15T11:10:13Z")

</div>

Hi @keryums,

Does it change anything if you set `autocolorscale=False`? You generally don’t want to specify a colorscale (`'Viridis'` in this case) and set `autocolorscale` to `True`.

If that doesn’t help, could you add a link to your dataset? Or try to reproduce the problem with this dataset from [https://plot.ly/python/choropleth-maps/#united-states-choropleth-map](https://plot.ly/python/choropleth-maps/#united-states-choropleth-map).

-Jon

---

<div class="post-metadata">

### Author: ![keryums](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/keryums/32/5287_2.png) [@keryums](https://community.plotly.com/u/keryums)
#### Post date: [January 17, 2019, 11:56pm UTC](https://community.plotly.com/t/map-colors-different-from-scale/18117/3 "2019-01-17T23:56:50Z")

</div>

Hi Jon,

I can recreate the plot you linked to but for some reason its still not working on my dataset, which you can find [here](https://github.com/keryums/projects/blob/master/state_by_sex_wide_20190117_1620.csv). I checked syntax, data types, null values, etc, but can’t find where the issue is coming from. Thanks in advance for your help!

---

<div class="post-metadata">

### Author: ![keryums](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/keryums/32/5287_2.png) [@keryums](https://community.plotly.com/u/keryums)
#### Post date: [January 17, 2019, 11:58pm UTC](https://community.plotly.com/t/map-colors-different-from-scale/18117/4 "2019-01-17T23:58:22Z")

</div>

Also, it doesn’t change anything when I specify ‘Viridis’ and change autocolorscale to False.

---

<div class="post-metadata">

### Author: ![jmmease](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jmmease/32/3706_2.png) [@jmmease](https://community.plotly.com/u/jmmease)
#### Post date: [January 18, 2019, 11:16am UTC](https://community.plotly.com/t/map-colors-different-from-scale/18117/5 "2019-01-18T11:16:34Z")

</div>

Hi @keryums

Thanks for providing the dataset. I’m not sure why plotly.js is responding this way, but the problem seems to be that this DataFrame has two rows for each state (one for each sex) and plotly.js doesn’t know how to handle multiple observations per state.

So you’ll want to do some kind of aggregation in pandas before building the choropleth trace. Here’s a full example of computing the sum of veterans per state (across all values of the `sex` column). Also, I needed to remove `autocolorscale=True` in order for the Viridis scale to show up.

```python
import plotly.graph_objs as go
import pandas as pd
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode()

state_by_sex = pd.read_csv('https://raw.githubusercontent.com/keryums/projects/master/state_by_sex_wide_20190117_1620.csv')

state_veterans = state_by_sex.groupby('state_code', as_index=False).sum()

data = [ dict(type='choropleth',
              colorscale = 'Viridis',
              locations=state_veterans.state_code,
              z=state_veterans.veterans,
              locationmode='USA-states'
             )
       ]

layout = dict(title = 'Map of Veteran Population by State',
              geo = dict(scope='usa',
                        projection=dict(type ='albers usa'),
                        showlakes = True,
                        lakecolor = 'rgb(255,255,255)')
             )

fig = go.Figure(data=data, layout=layout)
iplot(fig)

```

 ![newplot-2](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/d/dff2c09cd456d14f23fa064eb70949f1fedfc55b.png)

Hope that helps!  
-Jon

---

<div class="post-metadata">

### Author: ![keryums](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/keryums/32/5287_2.png) [@keryums](https://community.plotly.com/u/keryums)
#### Post date: [January 18, 2019, 6:12pm UTC](https://community.plotly.com/t/map-colors-different-from-scale/18117/6 "2019-01-18T18:12:26Z")

</div>

Oh gosh, thank you so much! I totally forgot to consider that the dataset has state repeated.
