Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Colorbar Is Missing When Plotting Geometries #3368

Closed
TheCedarPrince opened this issue Mar 24, 2021 · 7 comments
Closed

[BUG] Colorbar Is Missing When Plotting Geometries #3368

TheCedarPrince opened this issue Mar 24, 2021 · 7 comments
Labels

Comments

@TheCedarPrince
Copy link

Details

When plotting geometries, the colorbar does not show up even with colorbar=true explicitly.I was chatting with @mkborregaard today about what I thought was just a gripe (:grapes:) about this being an implementation quirk. Instead, it was actually a bug I discovered and he wanted me to open the issue!

Here is the code to reproduce the error

using DataFrames
using Plots
using Shapefile
using ColorSchemes

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])

rand_vals = [rand() for _ in 1:length(states.geometry)]

c_values = ColorSchemes.get(ColorSchemes.colorschemes[:seismic], rand_vals)

choropleth = plot(states.geometry, axis = ([], false), title = "Random Plot"; fillcolor = permutedims(c_values), colorbar = true)

The associated shapefile is located in this zip here: https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_state_5m.zip

Please let me know if you want me to test anything here - thanks for the great package and great work so far! 😄

Backends

This bug occurs on ( insert x below )

Backend yes no untested
gr (default) X
pyplot X
plotly X
plotlyjs X
pgfplotsx X
inspectdr X

Versions

Plots.jl version: v1.11.0
Backend version (]st -m): [d2c73de3] GR_jll v0.53.0+0
Output of versioninfo():

Julia Version 1.6.0-rc3
Commit 23267f0d46 (2021-03-16 17:04 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = nvim
@daschw
Copy link
Member

daschw commented Mar 24, 2021

I would use fill_z for this:

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

@mkborregaard
Copy link
Member

ahh, I didn't realize the code said fillcolor not fill_z :-D

@TheCedarPrince
Copy link
Author

Perfect @mkborregaard and @daschw ! Since I hadn't really seen this documented anywhere in the ecosystem, could I add a docs PR somewhere with this as an example?

@daschw
Copy link
Member

daschw commented Mar 24, 2021

Sure, that would be great. I'd say either somewhere at http://docs.juliaplots.org/latest/colors/ or at http://docs.juliaplots.org/latest/attributes/ would be the right place.

@TheCedarPrince
Copy link
Author

Hey @daschw - before I create this PR, what is fill_z exactly doing? I was a bit confused about fill_z versus fillcolor.

@mkborregaard
Copy link
Member

automatically reinterprets a vector of numbers on a color scale and adds a colorbar for the mapping

@daschw
Copy link
Member

daschw commented Mar 25, 2021

marker_z and line_z does the same thing for marker color and line color.

@t-bltg t-bltg added question and removed bug labels Nov 29, 2022
@t-bltg t-bltg closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants