# How to make a Logarithmic color scale in my Choropleth map

**URL:** <https://community.plotly.com/t/how-to-make-a-logarithmic-color-scale-in-my-choropleth-map/35010>\
**Category:** 📊 Plotly Python\
**Created:** [February 15, 2020, 11:20am UTC](https://community.plotly.com/t/how-to-make-a-logarithmic-color-scale-in-my-choropleth-map/35010 "2020-02-15T11:20:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahmoud](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@mahmoud](https://community.plotly.com/u/mahmoud)\
**Post date:** [February 15, 2020, 11:20am UTC](https://community.plotly.com/t/how-to-make-a-logarithmic-color-scale-in-my-choropleth-map/35010/1 "2020-02-15T11:20:03Z")

</div>

Hi i have a choropleth map for the world most of the countries in this map have similar values except  
China and the U.S.A so most of the countries have the same color  
how can i make a Logarithmic color scale to pass this problem

THIS IS MY CODE

```auto
fig = go.Figure()

fig.add_choropleth(locations=df['countery_name_iso'],
                   z=df['value'],
                   text=df['countery_name_iso'],
                   colorscale='cividis',
                   autocolorscale=False,
                   reversescale=False)
fig.show()

```

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

---

<div class="post-metadata">

**Author:** ![Emmanuelle](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/emmanuelle/32/7853_2.png) [@Emmanuelle](https://community.plotly.com/u/Emmanuelle)\
**Post date:** [February 15, 2020, 9:10pm UTC](https://community.plotly.com/t/how-to-make-a-logarithmic-color-scale-in-my-choropleth-map/35010/2 "2020-02-15T21:10:19Z")

</div>

Hi @mahmoud you can put `z=np.log10(df['value'])` (importing numpy) to plot the log10 of your values. If you would like the colorbar to display the original values you can use `tickprefix` as in [https://plot.ly/python/datashader/#exploring-correlations-of-a-large-dataset](https://plot.ly/python/datashader/#exploring-correlations-of-a-large-dataset).

---

<div class="post-metadata">

**Author:** ![eric\_overflow](https://avatars.discourse-cdn.com/v4/letter/e/22d042/32.png) [@eric\_overflow](https://community.plotly.com/u/eric_overflow)\
**Post date:** [March 21, 2020, 3:15am UTC](https://community.plotly.com/t/how-to-make-a-logarithmic-color-scale-in-my-choropleth-map/35010/3 "2020-03-21T03:15:13Z")

</div>

@Emmanuelle: this sort of works, but when you hover over the region, it now shows things like 2 (for 100). This is ok as far as it goes, but most people aren’t very good at converting from the log of n back to n. I wonder if there is a way show the color scale logarithmically, but when we hover (and the colorbar) it shows the actual numbers? This is how it works, for instance, when you change the y-axis to log in a scatter/line plot. It seems much more natural and intuitive.

One thing I did was to just add the data using text:  
`text = df['value']`

This works great. The only thing is it would be nice if the colorbar matched it.

---

<div class="post-metadata">

**Author:** ![eric\_overflow](https://avatars.discourse-cdn.com/v4/letter/e/22d042/32.png) [@eric\_overflow](https://community.plotly.com/u/eric_overflow)\
**Post date:** [March 21, 2020, 9:22pm UTC](https://community.plotly.com/t/how-to-make-a-logarithmic-color-scale-in-my-choropleth-map/35010/4 "2020-03-21T21:22:02Z")

</div>

To get the colorbar to match it I just adjusted the colorbar properties (customize as you see fit):

```auto
    colorbar=dict(len=0.75,
                  title='#Cases', 
                  x=0.9,
                  tickvals = [0, 1, 2, 3, 3.699, 4],
                  ticktext = ['1', '10', '100', '1000', '5000','10000'])

```

---

<div class="post-metadata">

**Author:** ![mahmoud](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@mahmoud](https://community.plotly.com/u/mahmoud)\
**Post date:** [March 21, 2020, 10:34pm UTC](https://community.plotly.com/t/how-to-make-a-logarithmic-color-scale-in-my-choropleth-map/35010/5 "2020-03-21T22:34:23Z")

</div>

thank you very much .

---

<div class="post-metadata">

**Author:** ![vvv](https://avatars.discourse-cdn.com/v4/letter/v/41988e/32.png) [@vvv](https://community.plotly.com/u/vvv)\
**Post date:** [March 29, 2020, 1:03am UTC](https://community.plotly.com/t/how-to-make-a-logarithmic-color-scale-in-my-choropleth-map/35010/6 "2020-03-29T01:03:35Z")

</div>

I agree your workaround work passing by canvas, but don’t understand why there is no simpler option on Histogram2dContour just change the color scale to take logarithmic scale boundaries. Looks for me more elegant and proper solution.

---

<div class="post-metadata">

**Author:** ![Emmanuelle](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/emmanuelle/32/7853_2.png) [@Emmanuelle](https://community.plotly.com/u/Emmanuelle)\
**Post date:** [March 29, 2020, 7:28am UTC](https://community.plotly.com/t/how-to-make-a-logarithmic-color-scale-in-my-choropleth-map/35010/7 "2020-03-29T07:28:09Z")

</div>

Hi @eric_overflow welcome to the forum! You can in fact pass other numerical data to the `customdata` argument of `go.Choropleth` and modify the hovertemplate to use the original data (eg 100, 1000) instead of their log10 which is used for `z`. See for example [https://plotly.com/python/hover-text-and-formatting/#adding-other-data-to-the-hover-with-customdata-and-a-hovertemplate](https://plotly.com/python/hover-text-and-formatting/#adding-other-data-to-the-hover-with-customdata-and-a-hovertemplate) for using customdata in a hovertemplate.
