如何将函数传递给 julia Gadfly Theme 参数 [英] How to pass a function to julia Gadfly Theme parameter

查看:18
本文介绍了如何将函数传递给 julia Gadfly Theme 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个这样的情节:

I make a plot like this:

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

如您所见,点周围的白色圆圈使绘图的高密度部分几乎是白色的.

As you can see, the white circle around the points makes the high density parts of the plot almost white.

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

I would like to change the outer circle color of the points to black (or blue) to better show that the points are really there.

Gadfly 文档看来,highlight_color 的参数是 >Theme() 可能会这样做,但它需要一个函数作为参数.

From the Gadfly documentation it seems like the highlight_color argument of Theme() might do that, but it takes a function as argument.

我不明白这应该如何工作.有什么想法吗?

I don't understand how that is supposed to work. Any ideas?

推荐答案

参数名原来是discrete_highlight_color...

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

It should be a function that modifies the colour used for the plot, typically by making it lighter (a "tint") or darker (a "shade"). In our case, we can just ignore the current colour and return black.

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

为了找到正确的论点,我首先输入了

To find the correct argument, I first typed

code_lowered( Theme, () )

给出参数列表,然后

less( Gadfly.default_discrete_highlight_color )

显示默认值是如何定义的.

which shows how the default value is defined.

这篇关于如何将函数传递给 julia Gadfly Theme 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆