Skip to content

Commit 7929909

Browse files
committed
Added saw plot
1 parent 3a16241 commit 7929909

File tree

7 files changed

+284
-62
lines changed

7 files changed

+284
-62
lines changed

DomainColoringToy/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name = "DomainColoringToy"
22
uuid = "7cf40ad8-af6a-4ede-b3c6-2a9df3bce851"
33
authors = ["Evert Provoost <evert@eprovst.net>"]
4-
version = "0.4.0"
4+
version = "0.5.0"
55

66
[deps]
77
DomainColoring = "c24f3079-adb7-4533-8329-9f66732e5e85"
88
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
99

1010
[compat]
11-
DomainColoring = "0.6"
11+
DomainColoring = "0.7"
1212
GLMakie = "0.8"
1313
julia = "1.6"

DomainColoringToy/src/DomainColoringToy.jl

Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module DomainColoringToy
1515
using GLMakie
1616
import DomainColoring as DC
1717

18-
export domaincolor, checkerplot, pdphaseplot, tphaseplot
18+
export domaincolor, checkerplot, sawplot, pdphaseplot, tphaseplot
1919

2020
"""
2121
DomainColoringToy.interactiveshadedplot(
@@ -121,9 +121,9 @@ end
121121
f :: "Complex -> Complex",
122122
limits = (-1, 1, -1, 1);
123123
pixels = (480, 480),
124-
angle = true,
125124
abs = false,
126125
grid = false,
126+
color = true,
127127
all = false,
128128
kwargs...
129129
)
@@ -150,9 +150,6 @@ to ``\\frac{2\\pi}{3}``, cyan to ``\\pi``, blue to
150150
for both if only one number is provided. If either is `:auto`, the
151151
viewport resolution is used.
152152
153-
- **`angle`** toggles coloring of the phase angle. Can also be set to
154-
either the name of, or a `ColorScheme`, or a function `θ -> Color`.
155-
156153
- **`abs`** toggles the plotting of the natural logarithm of the
157154
magnitude as lightness ramps between level curves. If set to a number,
158155
this will be used as base of the logarithm instead, if set to `Inf`,
@@ -167,6 +164,9 @@ to ``\\frac{2\\pi}{3}``, cyan to ``\\pi``, blue to
167164
dots. More complicated arguments can be passed as a named tuple in a
168165
similar fashion to [`checkerplot`](@ref).
169166
167+
- **`color`** toggles coloring of the phase angle. Can also be set to
168+
either the name of, or a `ColorScheme`, or a function `θ -> Color`.
169+
170170
- **`all`** is a shortcut for `abs = true` and `grid = true`.
171171
172172
Remaining keyword arguments are passed to Makie.
@@ -175,20 +175,20 @@ function domaincolor(
175175
f,
176176
limits = (-1, 1, -1, 1);
177177
pixels = (480, 480),
178-
angle = true,
179178
abs = false,
180179
grid = false,
180+
color = true,
181181
all = false,
182182
kwargs...
183183
)
184184

185185
# issue warning if everything is inactive
186-
if Base.all(b -> b isa Bool && !b, (angle, abs, grid, all))
186+
if Base.all(b -> b isa Bool && !b, (abs, grid, color, all))
187187
@warn "angle, abs, and grid are all false, domain coloring will be a constant color."
188188
end
189189

190190
interactiveshadedplot(
191-
f, w -> DC.domaincolorshader(w; angle, abs, grid, all),
191+
f, w -> DC.domaincolorshader(w; abs, grid, color, all),
192192
limits, pixels; kwargs...)
193193
end
194194

@@ -352,4 +352,79 @@ function checkerplot(
352352
), limits, pixels; kwargs...)
353353
end
354354

355+
"""
356+
sawplot(
357+
f :: "Complex -> Complex",
358+
limits = (-1, 1, -1, 1);
359+
pixels = (480, 480),
360+
real = false,
361+
imag = false,
362+
rect = false,
363+
angle = false,
364+
abs = false,
365+
polar = false,
366+
color = false,
367+
kwargs...
368+
)
369+
370+
Takes a complex function and produces a saw plot as a Makie plot.
371+
372+
# Arguments
373+
374+
- **`f`** is the complex function to plot.
375+
376+
- **`limits`** are the limits of the rectangle to plot, in the format
377+
`(minRe, maxRe, minIm, maxIm)`, if one or two numbers are provided
378+
instead they are take symmetric along the real and imaginary axis.
379+
380+
# Keyword Arguments
381+
382+
- **`pixels`** is the size of the output in pixels, respectively, the
383+
number of pixels along the real and imaginary axis, taking the same
384+
for both if only one number is provided. If either is `:auto`, the
385+
viewport resolution is used.
386+
387+
If none of the below options are set, the plot defaults to `rect = true`.
388+
Numbers can be provided instead of booleans to override the default rates.
389+
390+
- **`real`** plots black to white ramps orthogonal to the real axis at a
391+
rate of one ramp per unit.
392+
393+
- **`imag`** plots black to white ramps orthogonal to the imaginary axis
394+
at a rate of one ramp per unit.
395+
396+
- **`rect`** is a shortcut for `real = true` and `imag = true`.
397+
398+
- **`angle`** plots black to white ramps orthogonal to the phase angle
399+
at a rate of six ramps per full rotation.
400+
401+
- **`abs`** plots black to white ramps at a rate of one ramp per unit
402+
increase of the natural logarithm of the magnitude.
403+
404+
- **`phase`** is a shortcut for `angle = true` and `abs = true`.
405+
406+
- **`color`** toggles coloring of the phase angle. Can also be set to
407+
either the name of, or a `ColorScheme`, or a function `θ -> Color`.
408+
409+
Remaining keyword arguments are passed to Makie.
410+
"""
411+
function sawplot(
412+
f,
413+
limits = (-1, 1, -1, 1);
414+
pixels = (480, 480),
415+
real = false,
416+
imag = false,
417+
rect = false,
418+
angle = false,
419+
abs = false,
420+
polar = false,
421+
color = false,
422+
kwargs...
423+
)
424+
425+
interactiveshadedplot(f, w -> DC.sawplotshader(
426+
w; real, imag, rect, angle, abs, polar, color
427+
), limits, pixels; kwargs...)
428+
end
429+
355430
end

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DomainColoring"
22
uuid = "c24f3079-adb7-4533-8329-9f66732e5e85"
33
authors = ["Evert Provoost <evert@eprovst.net>"]
4-
version = "0.6.1"
4+
version = "0.7.0"
55

66
[deps]
77
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"

docs/src/usage/cvd.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ rendered unreadable.
1313
clearly readable to them, based on color maps developed by
1414
[Peter Kovesi](https://peterkovesi.com/papers/ColourMapsForColourBlindIAMG2017.pdf).
1515

16+
!!! note
17+
These color maps can also be used in the other plots as
18+
`:pd`/`:CBC1` and `:t`/`:CBTC1`, respectively. However do note that
19+
their use of black and white might interfere with other plotting
20+
elements.
21+
1622
## Phase plots for protanopia and deuteranopia
1723

1824
For these viewers it is difficult to distinguish red and green hues. The

docs/src/usage/general.md

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ nothing # hide
8585
![](dcsincall.png)
8686

8787
The argument interface contains many further options, but we will delay
88-
their discussion until after introducing the [`checkerplot`](@ref)
89-
function.
88+
their discussion until after introducing the [`checkerplot`](@ref) and
89+
[`sawplot`](@ref) functions.
9090

91-
## The [`checkerplot`](@ref) function
91+
## The [`checkerplot`](@ref) and [`sawplot`](@ref) functions
9292

9393
A checker plot shows limited information and is useful to detect
9494
patterns in certain contexts. By default a checker board pattern is used
@@ -103,12 +103,26 @@ nothing # hide
103103
```
104104
![](cprect.png)
105105

106+
A saw plot is similar but shows ramps instead of solid stripes, to get
107+
an idea of the direction of increase. Their interface is almost
108+
identical, so we'll use them interchangeably for most examples.
109+
110+
The previous example as a saw plot would be:
111+
```@example
112+
using CairoMakie, DomainColoring # hide
113+
sawplot(z -> z, 5)
114+
resize!(current_figure(), 620, 600) #hide
115+
save("sprect.png", current_figure()) # hide
116+
nothing # hide
117+
```
118+
![](sprect.png)
119+
106120
You can limit the stripes to only show increase in the real or imaginary
107121
part by setting `real = true` or `imag = true`, respectively. Again the
108122
previous example.
109123
```@example
110124
using CairoMakie, DomainColoring # hide
111-
checkerplot(z -> z, 5, real=true)
125+
sawplot(z -> z, 5, real=true)
112126
resize!(current_figure(), 620, 600) #hide
113127
save("cpreal.png", current_figure()) # hide
114128
nothing # hide
@@ -148,16 +162,16 @@ and for phase:
148162

149163
```@example
150164
using CairoMakie, DomainColoring # hide
151-
checkerplot(z -> z, 5, angle=10)
165+
sawplot(z -> z, 5, angle=10)
152166
resize!(current_figure(), 620, 600) #hide
153167
save("cpangle.png", current_figure()) # hide
154168
nothing # hide
155169
```
156170
![](cpangle.png)
157171

158-
Note, that for the latter we need to provide an even number. If we set
159-
`phase` to a number, this will be used for `abs` and a suitable integer
160-
rate will be chosen for `angle`, for instance:
172+
Note, that for a [`checkerplot`](@ref) the latter we needs to be an even
173+
number. If we set `phase` to a number, this will be used for `abs` and a
174+
suitable integer rate will be chosen for `angle`, for instance:
161175
```@example
162176
using CairoMakie, DomainColoring # hide
163177
checkerplot(sin, (5, 2), polar=4)
@@ -167,15 +181,18 @@ nothing # hide
167181
```
168182
![](cppolarsin.png)
169183

170-
Finally, `hicontrast = true` can be used to plot in black and white
171-
instead of the slightly softer defaults.
184+
Finally, `hicontrast = true` can be used in [`checkerplot`](@ref) to
185+
plot in black and white instead of the slightly softer defaults, and
186+
`color = true` mixes phase coloring into a [`sawplot`](@ref) (further
187+
possibilities of this option are identical to [`domaincolor`](@ref), as
188+
discussed at the end of the next section).
172189

173190
## The [`domaincolor`](@ref) function, revisited
174191

175-
Like [`checkerplot`](@ref), `abs` and `grid` also accept numbers.
176-
Respectively, changing the basis of the used logarithm and the rate of
177-
the grid. Additionally, we can pass named tuples to open up even more
178-
options.
192+
Like [`checkerplot`](@ref) and [`sawplot`](@ref), `abs` and `grid` also
193+
accept numbers. Respectively, changing the basis of the used logarithm
194+
and the rate of the grid. Additionally, we can pass named tuples to open
195+
up even more options.
179196

180197
For `grid` these options are identical to `checkerplot`, for example an
181198
analogous example to the final one of last section, is given by:
@@ -234,17 +251,17 @@ domaincolor(z -> exp(1/z), .1, abs=(sigma=0.001,))
234251
If one wants to change the coloring of the phase angle, they can pass a
235252
`ColorScheme` (as an object or by name, see [their
236253
documentation](https://juliagraphics.github.io/ColorSchemes.jl/stable/catalogue/))
237-
or a function `θ -> Color`, to `angle`. As an example of the latter, we
254+
or a function `θ -> Color`, to `color`. As an example of the latter, we
238255
can add a discretization effect:
239256
```@example
240257
using CairoMakie, DomainColoring # hide
241258
discrangle(θ) = DomainColoring.labsweep(π/10 * floor(10/π * θ))
242-
domaincolor(tan, angle=discrangle)
259+
domaincolor(tan, color=discrangle)
243260
resize!(current_figure(), 620, 600) #hide
244-
save("dscangle.png", current_figure()) # hide
261+
save("dsccolor.png", current_figure()) # hide
245262
nothing # hide
246263
```
247-
![](dscangle.png)
264+
![](dsccolor.png)
248265

249266
Finally, if no coloring of the phase is wanted, we can set
250-
`angle = false`.
267+
`color = false`.

docs/src/usage/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ As a final example, let us show off a few more capabilities of the
132132
This is a plot of ``f(z) = z^3i - 1`` with level curves of the logarithm
133133
of the magnitude and an integer grid. You can continue by reading the
134134
[General Overview](@ref) to learn more about these and other additional
135-
options, and the other provided plotting function [`checkerplot`](@ref).
135+
options, and the other provided plotting functions.
136136

137137
```@example
138138
using CairoMakie, DomainColoring # hide

0 commit comments

Comments
 (0)