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

查看:85
本文介绍了如何将函数传递给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"))))

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

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文档中,看来Theme()highlight_color参数可以做到这一点,但是它需要一个函数作为参数.

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 ...

The argument name turns out to be 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主题参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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