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

Commit 2fffa97

Browse files
authored
jk/color cycler 2 (#741)
1 parent 185de01 commit 2fffa97

File tree

24 files changed

+307
-105
lines changed

24 files changed

+307
-105
lines changed

docs/src/plotting_functions/barplot.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ barplot(tbl.x, tbl.height,
7777

7878
```@example bar
7979
let
80-
colors = AbstractPlotting.wong_colors
80+
colors = AbstractPlotting.wong_colors()
8181
8282
# Figure and Axis
8383
fig = Figure()

docs/src/plotting_functions/errorbars.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ ys = 0.5 .* sin.(xs)
4343
lowerrors = fill(0.1, length(xs))
4444
higherrors = LinRange(0.1, 0.4, length(xs))
4545
46-
errorbars!(xs, ys, lowerrors, higherrors, color = LinRange(0, 1, length(xs)))
46+
errorbars!(xs, ys, lowerrors, higherrors,
47+
color = range(0, 1, length = length(xs)),
48+
whiskerwidth = 10)
4749
4850
# plot position scatters so low and high errors can be discriminated
4951
scatter!(xs, ys, markersize = 3, color = :black)

docs/src/plotting_functions/rangebars.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ lows = zeros(length(vals))
3737
highs = LinRange(0.1, 0.4, length(vals))
3838
3939
rangebars!(vals, lows, highs, color = LinRange(0, 1, length(vals)),
40-
whiskerwidth = 3, direction = :x)
40+
whiskerwidth = 10, direction = :x)
4141
4242
f
4343
```

docs/src/theming.md

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ You can also reset your changes by calling `set_theme!()` without arguments.
99
Let's create a plot with the default theme:
1010

1111
```@example 1
12-
using GLMakie
12+
using CairoMakie
13+
CairoMakie.activate!() # hide
14+
AbstractPlotting.inline!(true) # hide
1315
1416
function example_plot()
1517
f = Figure()
1618
for i in 1:2, j in 1:2
17-
lines(f[i, j], cumsum(randn(1000)))
19+
lines(f[i, j], cumsum(randn(50)))
1820
end
1921
f
2022
end
@@ -53,6 +55,21 @@ with_theme(fontsize_theme, fontsize = 25) do
5355
end
5456
```
5557

58+
## Theming plot objects
59+
60+
You can theme plot objects by using their uppercase type names as a key in your theme.
61+
62+
```@example 1
63+
lines_theme = Theme(
64+
Lines = (
65+
linewidth = 4,
66+
linestyle = :dash,
67+
)
68+
)
69+
70+
with_theme(example_plot, lines_theme)
71+
```
72+
5673
## Theming layoutable objects
5774

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

78-
### Special attributes
95+
## Cycles
96+
97+
Makie supports a variety of options for cycling plot attributes automatically.
98+
For a plot object to use cycling, either its default theme or the currently active theme must have the `cycle` attribute set.
99+
100+
There are multiple ways to specify this attribute:
101+
102+
```julia
103+
# You can either make a list of symbols
104+
cycle = [:color, :marker]
105+
# or map specific plot attributes to palette attributes
106+
cycle = [:linecolor => :color, :marker]
107+
# you can also map multiple attributes that should receive
108+
# the same cycle attribute
109+
cycle = [[:linecolor, :markercolor] => :color, :marker]
110+
```
111+
112+
```@example
113+
using CairoMakie
114+
CairoMakie.activate!() # hide
115+
AbstractPlotting.inline!(true) # hide
116+
117+
set_theme!() # hide
118+
119+
f = Figure(resolution = (800, 800))
120+
121+
Axis(f[1, 1], title = "Default cycle palette")
122+
123+
for i in 1:6
124+
density!(randn(50) .+ 2i)
125+
end
126+
127+
Axis(f[2, 1],
128+
title = "Custom cycle palette",
129+
palette = (patchcolor = [:red, :green, :blue, :yellow, :orange, :pink],))
130+
131+
for i in 1:6
132+
density!(randn(50) .+ 2i)
133+
end
134+
135+
set_theme!(Density = (cycle = [],))
136+
137+
Axis(f[3, 1], title = "No cycle")
138+
139+
for i in 1:6
140+
density!(randn(50) .+ 2i)
141+
end
142+
143+
set_theme!() # hide
144+
145+
f
146+
```
147+
148+
149+
150+
## Special attributes
79151

80152
You can use the keys `rowgap` and `colgap` to change the default grid layout gaps.

src/basic_recipes/arrows.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ $(ATTRIBUTES)
3434
align = :origin,
3535
normalize = false,
3636
lengthscale = 1f0,
37-
colormap = :viridis,
37+
colormap = theme(scene, :colormap),
3838
quality = 32,
3939
inspectable = theme(scene, :inspectable)
4040
)

src/basic_recipes/band.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ $(ATTRIBUTES)
1212
Attributes(;
1313
default_theme(scene, Mesh)...,
1414
colorrange = automatic,
15-
color = RGBAf0(0,0,0,0.2)
1615
)
1716
end
1817

src/basic_recipes/barplot.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $(ATTRIBUTES)
99
@recipe(BarPlot, x, y) do scene
1010
Attributes(;
1111
fillto = automatic,
12-
color = theme(scene, :color),
12+
color = theme(scene, :patchcolor),
1313
colormap = theme(scene, :colormap),
1414
colorrange = automatic,
1515
dodge = automatic,
@@ -18,12 +18,13 @@ $(ATTRIBUTES)
1818
dodge_gap = 0.03,
1919
marker = Rect,
2020
stack = automatic,
21-
strokewidth = 0,
22-
strokecolor = :white,
21+
strokewidth = theme(scene, :patchstrokewidth),
22+
strokecolor = theme(scene, :patchstrokecolor),
2323
width = automatic,
2424
direction = :y,
2525
visible = theme(scene, :visible),
26-
inspectable = theme(scene, :inspectable)
26+
inspectable = theme(scene, :inspectable),
27+
cycle = [:color => :patchcolor],
2728
)
2829
end
2930

src/basic_recipes/contourf.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ $(ATTRIBUTES)
2222
Theme(
2323
levels = 10,
2424
mode = :normal,
25-
colormap = :viridis,
25+
colormap = theme(scene, :colormap),
2626
extendlow = nothing,
2727
extendhigh = nothing,
2828
inspectable = theme(scene, :inspectable)

src/basic_recipes/contours.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $(ATTRIBUTES)
99
"""
1010
@recipe(Contour) do scene
1111
default = default_theme(scene)
12-
pop!(default, :color)
12+
# pop!(default, :color)
1313
Attributes(;
1414
default...,
1515
color = nothing,

src/basic_recipes/error_and_rangebars.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ $(ATTRIBUTES)
1919
"""
2020
@recipe(Errorbars) do scene
2121
Theme(
22-
whiskerwidth = 10,
23-
color = :black,
24-
linewidth = 1,
22+
whiskerwidth = 0,
23+
color = theme(scene, :linecolor),
24+
linewidth = theme(scene, :linewidth),
2525
direction = :y,
2626
visible = theme(scene, :visible),
27-
colormap = :viridis,
27+
colormap = theme(scene, :colormap),
2828
inspectable = theme(scene, :inspectable)
2929
)
3030
end
@@ -45,12 +45,12 @@ $(ATTRIBUTES)
4545
"""
4646
@recipe(Rangebars) do scene
4747
Theme(
48-
whiskerwidth = 10,
49-
color = :black,
50-
linewidth = 1,
48+
whiskerwidth = 0,
49+
color = theme(scene, :linecolor),
50+
linewidth = theme(scene, :linewidth),
5151
direction = :y,
5252
visible = theme(scene, :visible),
53-
colormap = :viridis,
53+
colormap = theme(scene, :colormap),
5454
inspectable = theme(scene, :inspectable)
5555
)
5656
end

0 commit comments

Comments
 (0)