Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
jk/color cycler 2 (#741)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrumbiegel authored May 16, 2021
1 parent 185de01 commit 2fffa97
Show file tree
Hide file tree
Showing 24 changed files with 307 additions and 105 deletions.
2 changes: 1 addition & 1 deletion docs/src/plotting_functions/barplot.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ barplot(tbl.x, tbl.height,

```@example bar
let
colors = AbstractPlotting.wong_colors
colors = AbstractPlotting.wong_colors()
# Figure and Axis
fig = Figure()
Expand Down
4 changes: 3 additions & 1 deletion docs/src/plotting_functions/errorbars.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ ys = 0.5 .* sin.(xs)
lowerrors = fill(0.1, length(xs))
higherrors = LinRange(0.1, 0.4, length(xs))
errorbars!(xs, ys, lowerrors, higherrors, color = LinRange(0, 1, length(xs)))
errorbars!(xs, ys, lowerrors, higherrors,
color = range(0, 1, length = length(xs)),
whiskerwidth = 10)
# plot position scatters so low and high errors can be discriminated
scatter!(xs, ys, markersize = 3, color = :black)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/plotting_functions/rangebars.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ lows = zeros(length(vals))
highs = LinRange(0.1, 0.4, length(vals))
rangebars!(vals, lows, highs, color = LinRange(0, 1, length(vals)),
whiskerwidth = 3, direction = :x)
whiskerwidth = 10, direction = :x)
f
```
Expand Down
78 changes: 75 additions & 3 deletions docs/src/theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ You can also reset your changes by calling `set_theme!()` without arguments.
Let's create a plot with the default theme:

```@example 1
using GLMakie
using CairoMakie
CairoMakie.activate!() # hide
AbstractPlotting.inline!(true) # hide
function example_plot()
f = Figure()
for i in 1:2, j in 1:2
lines(f[i, j], cumsum(randn(1000)))
lines(f[i, j], cumsum(randn(50)))
end
f
end
Expand Down Expand Up @@ -53,6 +55,21 @@ with_theme(fontsize_theme, fontsize = 25) do
end
```

## Theming plot objects

You can theme plot objects by using their uppercase type names as a key in your theme.

```@example 1
lines_theme = Theme(
Lines = (
linewidth = 4,
linestyle = :dash,
)
)
with_theme(example_plot, lines_theme)
```

## Theming layoutable objects

Every Layoutable such as `Axis`, `Legend`, `Colorbar`, etc. can be themed by using its type name as a key in your theme.
Expand All @@ -75,6 +92,61 @@ ggplot_theme = Theme(
with_theme(example_plot, ggplot_theme)
```

### Special attributes
## Cycles

Makie supports a variety of options for cycling plot attributes automatically.
For a plot object to use cycling, either its default theme or the currently active theme must have the `cycle` attribute set.

There are multiple ways to specify this attribute:

```julia
# You can either make a list of symbols
cycle = [:color, :marker]
# or map specific plot attributes to palette attributes
cycle = [:linecolor => :color, :marker]
# you can also map multiple attributes that should receive
# the same cycle attribute
cycle = [[:linecolor, :markercolor] => :color, :marker]
```

```@example
using CairoMakie
CairoMakie.activate!() # hide
AbstractPlotting.inline!(true) # hide
set_theme!() # hide
f = Figure(resolution = (800, 800))
Axis(f[1, 1], title = "Default cycle palette")
for i in 1:6
density!(randn(50) .+ 2i)
end
Axis(f[2, 1],
title = "Custom cycle palette",
palette = (patchcolor = [:red, :green, :blue, :yellow, :orange, :pink],))
for i in 1:6
density!(randn(50) .+ 2i)
end
set_theme!(Density = (cycle = [],))
Axis(f[3, 1], title = "No cycle")
for i in 1:6
density!(randn(50) .+ 2i)
end
set_theme!() # hide
f
```



## Special attributes

You can use the keys `rowgap` and `colgap` to change the default grid layout gaps.
2 changes: 1 addition & 1 deletion src/basic_recipes/arrows.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ $(ATTRIBUTES)
align = :origin,
normalize = false,
lengthscale = 1f0,
colormap = :viridis,
colormap = theme(scene, :colormap),
quality = 32,
inspectable = theme(scene, :inspectable)
)
Expand Down
1 change: 0 additions & 1 deletion src/basic_recipes/band.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ $(ATTRIBUTES)
Attributes(;
default_theme(scene, Mesh)...,
colorrange = automatic,
color = RGBAf0(0,0,0,0.2)
)
end

Expand Down
9 changes: 5 additions & 4 deletions src/basic_recipes/barplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $(ATTRIBUTES)
@recipe(BarPlot, x, y) do scene
Attributes(;
fillto = automatic,
color = theme(scene, :color),
color = theme(scene, :patchcolor),
colormap = theme(scene, :colormap),
colorrange = automatic,
dodge = automatic,
Expand All @@ -18,12 +18,13 @@ $(ATTRIBUTES)
dodge_gap = 0.03,
marker = Rect,
stack = automatic,
strokewidth = 0,
strokecolor = :white,
strokewidth = theme(scene, :patchstrokewidth),
strokecolor = theme(scene, :patchstrokecolor),
width = automatic,
direction = :y,
visible = theme(scene, :visible),
inspectable = theme(scene, :inspectable)
inspectable = theme(scene, :inspectable),
cycle = [:color => :patchcolor],
)
end

Expand Down
2 changes: 1 addition & 1 deletion src/basic_recipes/contourf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $(ATTRIBUTES)
Theme(
levels = 10,
mode = :normal,
colormap = :viridis,
colormap = theme(scene, :colormap),
extendlow = nothing,
extendhigh = nothing,
inspectable = theme(scene, :inspectable)
Expand Down
2 changes: 1 addition & 1 deletion src/basic_recipes/contours.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $(ATTRIBUTES)
"""
@recipe(Contour) do scene
default = default_theme(scene)
pop!(default, :color)
# pop!(default, :color)
Attributes(;
default...,
color = nothing,
Expand Down
16 changes: 8 additions & 8 deletions src/basic_recipes/error_and_rangebars.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ $(ATTRIBUTES)
"""
@recipe(Errorbars) do scene
Theme(
whiskerwidth = 10,
color = :black,
linewidth = 1,
whiskerwidth = 0,
color = theme(scene, :linecolor),
linewidth = theme(scene, :linewidth),
direction = :y,
visible = theme(scene, :visible),
colormap = :viridis,
colormap = theme(scene, :colormap),
inspectable = theme(scene, :inspectable)
)
end
Expand All @@ -45,12 +45,12 @@ $(ATTRIBUTES)
"""
@recipe(Rangebars) do scene
Theme(
whiskerwidth = 10,
color = :black,
linewidth = 1,
whiskerwidth = 0,
color = theme(scene, :linecolor),
linewidth = theme(scene, :linewidth),
direction = :y,
visible = theme(scene, :visible),
colormap = :viridis,
colormap = theme(scene, :colormap),
inspectable = theme(scene, :inspectable)
)
end
Expand Down
7 changes: 4 additions & 3 deletions src/basic_recipes/poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ $(ATTRIBUTES)
"""
@recipe(Poly) do scene
Attributes(;
color = theme(scene, :color),
color = theme(scene, :patchcolor),
visible = theme(scene, :visible),
strokecolor = RGBAf0(0,0,0,0),
strokecolor = theme(scene, :patchstrokecolor),
colormap = theme(scene, :colormap),
colorrange = automatic,
strokewidth = 1.0,
strokewidth = theme(scene, :patchstrokewidth),
shading = false,
# we turn this false for now, since otherwise shapes look transparent
# since we use meshes, which are drawn into a different framebuffer because of fxaa
Expand All @@ -35,6 +35,7 @@ $(ATTRIBUTES)
linestyle = nothing,
overdraw = false,
transparency = false,
cycle = [:color => :patchcolor],
inspectable = theme(scene, :inspectable)
)
end
Expand Down
25 changes: 13 additions & 12 deletions src/basic_recipes/stem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,27 @@ $(ATTRIBUTES)
"""
@recipe(Stem) do scene
Attributes(
stemcolor = :black,
stemcolormap = :viridis,
stemcolor = theme(scene, :linecolor),
stemcolormap = theme(scene, :colormap),
stemcolorrange = automatic,
stemwidth = 1,
stemwidth = theme(scene, :linewidth),
stemlinestyle = nothing,
trunkwidth = 1,
trunkwidth = theme(scene, :linewidth),
trunklinestyle = nothing,
trunkcolor = :black,
trunkcolormap = :viridis,
trunkcolor = theme(scene, :linecolor),
trunkcolormap = theme(scene, :colormap),
trunkcolorrange = automatic,
offset = 0,
marker = :circle,
markersize = 10,
color = :gray65,
colormap = :viridis,
markersize = theme(scene, :markersize),
color = theme(scene, :markercolor),
colormap = theme(scene, :colormap),
colorrange = automatic,
strokecolor = :black,
strokewidth = 1,
strokecolor = theme(scene, :markerstrokecolor),
strokewidth = theme(scene, :markerstrokewidth),
visible = true,
inspectable = theme(scene, :inspectable)
inspectable = theme(scene, :inspectable),
cycle = [[:stemcolor, :color, :trunkcolor] => :color],
)
end

Expand Down
Loading

0 comments on commit 2fffa97

Please sign in to comment.