Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a function to julia Gadfly Theme parameter

Tags:

julia

gadfly

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

ScatterPlot

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.

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?

like image 413
Skeppet Avatar asked Nov 18 '14 13:11

Skeppet


1 Answers

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

Scatterplot

To find the correct argument, I first typed

code_lowered( Theme, () )

which gives the list of arguments, and then

less( Gadfly.default_discrete_highlight_color )

which shows how the default value is defined.

like image 76
Vincent Zoonekynd Avatar answered Nov 07 '22 19:11

Vincent Zoonekynd