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

Cannot assign colors to individual bars #442

Closed
itsdfish opened this issue Apr 27, 2021 · 3 comments · Fixed by JuliaPlots/Plots.jl#3751
Closed

Cannot assign colors to individual bars #442

itsdfish opened this issue Apr 27, 2021 · 3 comments · Fixed by JuliaPlots/Plots.jl#3751
Assignees

Comments

@itsdfish
Copy link

itsdfish commented Apr 27, 2021

The ability to assign colors to different bars appears to be broken. I believe a breaking change occurred Plots somewhere between the current version and v1.10.6. The following works with row vectors:

using  StatsPlots
bar(["a"  "b"], [1  2], color=[:red :blue])

However, this does not work with dataframes because it uses columns:

using DataFrames, StatsPlots
df = DataFrame(a = ["a","b"], b = [1,2])
@df df bar(:a, :b, color=[:red, :blue])

which produces the following warning:

┌ Info: Data contains NaNs or missing values, and indices of `fillcolor` vector do not match data indices.
│ If you intend elements of `fillcolor` to apply to individual NaN-separated segements in the data,
│ pass each segment in a separate vector instead, and use a row vector for `fillcolor`. Legend entries 
│ may be suppressed by passing an empty label.
│ For example,
└     plot([1:2,1:3], [[4,5],[3,4,5]], label=["y" ""], fillcolor=[1 2])
┌ Warning: Indices Base.OneTo(2) of attribute `markercolor` does not match data indices 1:11.
└ @ Plots ~/.julia/packages/Plots/kyYZF/src/utils.jl:102
┌ Info: Data contains NaNs or missing values, and indices of `markercolor` vector do not match data indices.
│ If you intend elements of `markercolor` to apply to individual NaN-separated segements in the data,
│ pass each segment in a separate vector instead, and use a row vector for `markercolor`. Legend entries 
│ may be suppressed by passing an empty label.
│ For example,
└     plot([1:2,1:3], [[4,5],[3,4,5]], label=["y" ""], markercolor=[1 2])

The advice in the warning does not appear to be applicable in this case.

Version

versioninfo()
Julia Version 1.6.1
Commit 6aaedecc44 (2021-04-23 05:59 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, haswell)
Environment:
  JULIA_CMDSTAN_HOME = /home/dfish/cmdstan-2.19.1
  JULIA_NUM_THREADS = 4
  JULIA_EDITOR = code
[91a5bcdd] Plots v1.12.0
[f3b207a7] StatsPlots v0.14.19
@ElectricCoffee
Copy link

I too am having this issue

@dav2017
Copy link

dav2017 commented Aug 2, 2021

The problem is still there, and also for Dictionaries. Once this used to work:
data= Dict("Item 1" => 30, "Item 2" => 35, "Item 3" => 25)
bar(data, legend=false, c=[:red3, :salmon, :skyblue]
Now a workaround is:
bar([[i] for i in keys(data)], [[i] for i in values(data)], legend=false, c=[:red3 :salmon :skyblue])
Not so convenient, and gaps between bars become greater than usual bar plots.

@daschw daschw assigned yha and daschw Aug 2, 2021
@yha
Copy link
Member

yha commented Aug 9, 2021

I will look at it later this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants