首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gadfly,新颜色/层

Gadfly,新颜色/层
EN

Stack Overflow用户
提问于 2016-11-12 22:43:44
回答 1查看 173关注 0票数 1

当我将新图层推送到现有绘图时,它保持相同的颜色。有没有办法在将新图层推到绘图时自动更改颜色,或者至少有一种方法可以使用随机数来设置颜色(我不知道提前会有多少个图层)?

代码语言:javascript
复制
y=[3, 7, 5, 1]
x=[1, 2, 3, 4]
xmin1 = x .- 0.1
xmax1 = x .+ 0.1

xmin2 = x .- 0.5
xmax2 = x .- 0.3

y=[3, 7, 5, 1]
x=[1, 2, 3, 4]
xmin1 = x .- 0.1
xmax1 = x .+ 0.1

xmin2 = x .- 0.5
xmax2 = x .- 0.3

p = plot(xmin=xmin1, xmax=xmax1, y=[3, 7, 5, 1], Geom.bar)

# The following creates a new layer that keeps the same color
push!(p, layer(xmin=xmin2, xmax=xmax2, y=[3, 7, 5, 1], Geom.bar )) 

# I do not want to use this because I don't know how many layers I will have
# push!(p, layer(xmin=xmin2, xmax=xmax2, y=[3, 7, 5, 1], Geom.bar, 
#    Theme(default_color=colorant"green") ))
EN

回答 1

Stack Overflow用户

发布于 2016-11-13 00:05:01

一种可能的解决方案是:

代码语言:javascript
复制
Using Colors
function gen_colors(n)
  cs = distinguishable_colors(n,
      [colorant"#FE4365", colorant"#eca25c"], # seed colors
      lchoices=Float64[58, 45, 72.5, 90],     # lightness choices
      transform=c -> deuteranopic(c, 0.1),    # color transform
      cchoices=Float64[20,40],                # chroma choices
      hchoices=[75,51,35,120,180,210,270,310] # hue choices
  )
end

mycolors = gen_colors(n)

在运行时,使用要添加到绘图中的层数调用此函数,然后使用返回数组的元素作为default_color的参数。也就是说,对于第i层使用

代码语言:javascript
复制
Theme(default_color=mycolors[i])
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40563981

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档