如何将函数传递给julia Gadfly Theme参数

时间:2014-11-18 13:30:51

标签: julia gadfly

我制作了这样的情节:

plot(
  layer(x=sort(randn(1000),1), y=sort(randn(1000),1), Geom.point),
  layer(x=[-4,4], y=[-4,4], Geom.line(), Theme(default_color=color("black"))))

ScatterPlot

如您所见,点周围的白色圆圈使得图中的高密度部分几乎为白色。

我想将点的外圆颜色更改为黑色(或蓝色),以更好地显示这些点确实存在。

the Gadfly documentation开始,似乎highlight_color的{​​{1}}参数可能会这样做,但它需要一个函数作为参数。

我不明白这是怎么回事。有什么想法吗?

2 个答案:

答案 0 :(得分:7)

参数名称为discrete_highlight_color ...

它应该是一个修改用于绘图的颜色的函数, 通常通过使其更亮(“浅色”)或更暗(“阴影”)。 在我们的例子中,我们可以忽略当前的颜色并返回黑色。

using Color
using Gadfly
plot(
  layer(
    x = sort(randn(1000),1), 
    y = sort(randn(1000),1), 
    Geom.point,
    # Theme(highlight_width=0.0mm) # To remove the border
    Theme( discrete_highlight_color = u -> LCHab(0,0,0) )
  ),
  layer(
    x = [-4,4], 
    y = [-4,4], 
    Geom.line(), 
    Theme(default_color=color("black"))
  )
)

Scatterplot

要找到正确的参数,我先输入

code_lowered( Theme, () )

给出了参数列表, 然后

less( Gadfly.default_discrete_highlight_color )

显示如何定义默认值。

答案 1 :(得分:0)

对于像我这样的人最近试图解决这个问题,我发现摆脱那个讨厌的白色戒指的最佳方法是通过主题设置highlight_width=0pt

例如

plot(x=rand(10),y=rand(10),Theme(highlight_width=0pt))

我在下面的图片an example I did

中有一些额外的主题