# How Do I Add a Colorbar to a Choropleth Map?

**URL:** <https://discourse.julialang.org/t/how-do-i-add-a-colorbar-to-a-choropleth-map/57814>\
**Category:** General Usage\
**Tags:** plotting, data, shapes, shapefile\
**Created:** [March 23, 2021, 6:31pm UTC](https://discourse.julialang.org/t/how-do-i-add-a-colorbar-to-a-choropleth-map/57814 "2021-03-23T18:31:40Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![daschw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daschw/32/2926_2.png) [@daschw](https://discourse.julialang.org/u/daschw)\
**Post date:** [March 24, 2021, 12:46pm UTC](https://discourse.julialang.org/t/how-do-i-add-a-colorbar-to-a-choropleth-map/57814/5 "2021-03-24T12:46:44Z")

</div>

I’ll crosspost my response in the Plots issue ([[BUG] Colorbar Is Missing When Plotting Geometries · Issue #3368 · JuliaPlots/Plots.jl · GitHub](https://github.com/JuliaPlots/Plots.jl/issues/3368)). The intended way to do this is `fill_z` instead of `fillcolor`.

```julia
using DataFrames
using Plots
using Shapefile

states = Shapefile.Table("cb_2018_us_state_5m.shp") |> DataFrame
skip = ["02", "15", "60", "66", "69", "72", "78"]
filter!(row -> !(row[:STATEFP] in skip), states)
sort!(states, [:GEOID])

n = size(states, 1)
plot(states.geometry, fill_z=rand(1, n), title="My title", cbar=true, color=:seismic)

```

![shapes](https://global.discourse-cdn.com/julialang/original/3X/d/1/d181060a36da416c7d7ee2ec355294abd4750128.png)  
Colors are chosen automatically based on the corresponding `fill_z` values from the provided color gradient ([ColorSchemes · Plots](http://docs.juliaplots.org/latest/generated/colorschemes/#ColorGradient)) - in this case `:seismic`, the default is `:inferno` as in @lungd’s example. If you only provide colors as `fillcolor` without corresponding “z” values, Plots can not know how to arrange these colors in a colorbar.

---

_[View the full topic](https://discourse.julialang.org/t/how-do-i-add-a-colorbar-to-a-choropleth-map/57814)._
