Skip to content

Commit

Permalink
Added saw plot
Browse files Browse the repository at this point in the history
  • Loading branch information
eprovst committed Sep 6, 2023
1 parent 3a16241 commit 7929909
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 62 deletions.
4 changes: 2 additions & 2 deletions DomainColoringToy/Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name = "DomainColoringToy"
uuid = "7cf40ad8-af6a-4ede-b3c6-2a9df3bce851"
authors = ["Evert Provoost <evert@eprovst.net>"]
version = "0.4.0"
version = "0.5.0"

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

[compat]
DomainColoring = "0.6"
DomainColoring = "0.7"
GLMakie = "0.8"
julia = "1.6"
91 changes: 83 additions & 8 deletions DomainColoringToy/src/DomainColoringToy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module DomainColoringToy
using GLMakie
import DomainColoring as DC

export domaincolor, checkerplot, pdphaseplot, tphaseplot
export domaincolor, checkerplot, sawplot, pdphaseplot, tphaseplot

"""
DomainColoringToy.interactiveshadedplot(
Expand Down Expand Up @@ -121,9 +121,9 @@ end
f :: "Complex -> Complex",
limits = (-1, 1, -1, 1);
pixels = (480, 480),
angle = true,
abs = false,
grid = false,
color = true,
all = false,
kwargs...
)
Expand All @@ -150,9 +150,6 @@ to ``\\frac{2\\pi}{3}``, cyan to ``\\pi``, blue to
for both if only one number is provided. If either is `:auto`, the
viewport resolution is used.
- **`angle`** toggles coloring of the phase angle. Can also be set to
either the name of, or a `ColorScheme`, or a function `θ -> Color`.
- **`abs`** toggles the plotting of the natural logarithm of the
magnitude as lightness ramps between level curves. If set to a number,
this will be used as base of the logarithm instead, if set to `Inf`,
Expand All @@ -167,6 +164,9 @@ to ``\\frac{2\\pi}{3}``, cyan to ``\\pi``, blue to
dots. More complicated arguments can be passed as a named tuple in a
similar fashion to [`checkerplot`](@ref).
- **`color`** toggles coloring of the phase angle. Can also be set to
either the name of, or a `ColorScheme`, or a function `θ -> Color`.
- **`all`** is a shortcut for `abs = true` and `grid = true`.
Remaining keyword arguments are passed to Makie.
Expand All @@ -175,20 +175,20 @@ function domaincolor(
f,
limits = (-1, 1, -1, 1);
pixels = (480, 480),
angle = true,
abs = false,
grid = false,
color = true,
all = false,
kwargs...
)

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

interactiveshadedplot(
f, w -> DC.domaincolorshader(w; angle, abs, grid, all),
f, w -> DC.domaincolorshader(w; abs, grid, color, all),
limits, pixels; kwargs...)
end

Expand Down Expand Up @@ -352,4 +352,79 @@ function checkerplot(
), limits, pixels; kwargs...)
end

"""
sawplot(
f :: "Complex -> Complex",
limits = (-1, 1, -1, 1);
pixels = (480, 480),
real = false,
imag = false,
rect = false,
angle = false,
abs = false,
polar = false,
color = false,
kwargs...
)
Takes a complex function and produces a saw plot as a Makie plot.
# Arguments
- **`f`** is the complex function to plot.
- **`limits`** are the limits of the rectangle to plot, in the format
`(minRe, maxRe, minIm, maxIm)`, if one or two numbers are provided
instead they are take symmetric along the real and imaginary axis.
# Keyword Arguments
- **`pixels`** is the size of the output in pixels, respectively, the
number of pixels along the real and imaginary axis, taking the same
for both if only one number is provided. If either is `:auto`, the
viewport resolution is used.
If none of the below options are set, the plot defaults to `rect = true`.
Numbers can be provided instead of booleans to override the default rates.
- **`real`** plots black to white ramps orthogonal to the real axis at a
rate of one ramp per unit.
- **`imag`** plots black to white ramps orthogonal to the imaginary axis
at a rate of one ramp per unit.
- **`rect`** is a shortcut for `real = true` and `imag = true`.
- **`angle`** plots black to white ramps orthogonal to the phase angle
at a rate of six ramps per full rotation.
- **`abs`** plots black to white ramps at a rate of one ramp per unit
increase of the natural logarithm of the magnitude.
- **`phase`** is a shortcut for `angle = true` and `abs = true`.
- **`color`** toggles coloring of the phase angle. Can also be set to
either the name of, or a `ColorScheme`, or a function `θ -> Color`.
Remaining keyword arguments are passed to Makie.
"""
function sawplot(
f,
limits = (-1, 1, -1, 1);
pixels = (480, 480),
real = false,
imag = false,
rect = false,
angle = false,
abs = false,
polar = false,
color = false,
kwargs...
)

interactiveshadedplot(f, w -> DC.sawplotshader(
w; real, imag, rect, angle, abs, polar, color
), limits, pixels; kwargs...)
end

end
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DomainColoring"
uuid = "c24f3079-adb7-4533-8329-9f66732e5e85"
authors = ["Evert Provoost <evert@eprovst.net>"]
version = "0.6.1"
version = "0.7.0"

[deps]
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Expand Down
6 changes: 6 additions & 0 deletions docs/src/usage/cvd.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ rendered unreadable.
clearly readable to them, based on color maps developed by
[Peter Kovesi](https://peterkovesi.com/papers/ColourMapsForColourBlindIAMG2017.pdf).

!!! note
These color maps can also be used in the other plots as
`:pd`/`:CBC1` and `:t`/`:CBTC1`, respectively. However do note that
their use of black and white might interfere with other plotting
elements.

## Phase plots for protanopia and deuteranopia

For these viewers it is difficult to distinguish red and green hues. The
Expand Down
55 changes: 36 additions & 19 deletions docs/src/usage/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ nothing # hide
![](dcsincall.png)

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

## The [`checkerplot`](@ref) function
## The [`checkerplot`](@ref) and [`sawplot`](@ref) functions

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

A saw plot is similar but shows ramps instead of solid stripes, to get
an idea of the direction of increase. Their interface is almost
identical, so we'll use them interchangeably for most examples.

The previous example as a saw plot would be:
```@example
using CairoMakie, DomainColoring # hide
sawplot(z -> z, 5)
resize!(current_figure(), 620, 600) #hide
save("sprect.png", current_figure()) # hide
nothing # hide
```
![](sprect.png)

You can limit the stripes to only show increase in the real or imaginary
part by setting `real = true` or `imag = true`, respectively. Again the
previous example.
```@example
using CairoMakie, DomainColoring # hide
checkerplot(z -> z, 5, real=true)
sawplot(z -> z, 5, real=true)
resize!(current_figure(), 620, 600) #hide
save("cpreal.png", current_figure()) # hide
nothing # hide
Expand Down Expand Up @@ -148,16 +162,16 @@ and for phase:

```@example
using CairoMakie, DomainColoring # hide
checkerplot(z -> z, 5, angle=10)
sawplot(z -> z, 5, angle=10)
resize!(current_figure(), 620, 600) #hide
save("cpangle.png", current_figure()) # hide
nothing # hide
```
![](cpangle.png)

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

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

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

Like [`checkerplot`](@ref), `abs` and `grid` also accept numbers.
Respectively, changing the basis of the used logarithm and the rate of
the grid. Additionally, we can pass named tuples to open up even more
options.
Like [`checkerplot`](@ref) and [`sawplot`](@ref), `abs` and `grid` also
accept numbers. Respectively, changing the basis of the used logarithm
and the rate of the grid. Additionally, we can pass named tuples to open
up even more options.

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

Finally, if no coloring of the phase is wanted, we can set
`angle = false`.
`color = false`.
2 changes: 1 addition & 1 deletion docs/src/usage/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ As a final example, let us show off a few more capabilities of the
This is a plot of ``f(z) = z^3i - 1`` with level curves of the logarithm
of the magnitude and an integer grid. You can continue by reading the
[General Overview](@ref) to learn more about these and other additional
options, and the other provided plotting function [`checkerplot`](@ref).
options, and the other provided plotting functions.

```@example
using CairoMakie, DomainColoring # hide
Expand Down
Loading

0 comments on commit 7929909

Please sign in to comment.