Skip to content

Commit b7e0d62

Browse files
committed
Added box option
1 parent 7929909 commit b7e0d62

File tree

3 files changed

+159
-24
lines changed

3 files changed

+159
-24
lines changed

DomainColoringToy/src/DomainColoringToy.jl

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ end
125125
grid = false,
126126
color = true,
127127
all = false,
128+
box = nothing,
128129
kwargs...
129130
)
130131
@@ -169,6 +170,10 @@ to ``\\frac{2\\pi}{3}``, cyan to ``\\pi``, blue to
169170
170171
- **`all`** is a shortcut for `abs = true` and `grid = true`.
171172
173+
- **`box`** if set to `(a, b, s)` shades the area where the the output
174+
is within the box `a` and `b` in the color `s`. Can also be a list of
175+
multiple boxes.
176+
172177
Remaining keyword arguments are passed to Makie.
173178
"""
174179
function domaincolor(
@@ -179,6 +184,7 @@ function domaincolor(
179184
grid = false,
180185
color = true,
181186
all = false,
187+
box = nothing,
182188
kwargs...
183189
)
184190

@@ -188,7 +194,7 @@ function domaincolor(
188194
end
189195

190196
interactiveshadedplot(
191-
f, w -> DC.domaincolorshader(w; abs, grid, color, all),
197+
f, w -> DC.domaincolorshader(w; abs, grid, color, all, box),
192198
limits, pixels; kwargs...)
193199
end
194200

@@ -197,6 +203,7 @@ end
197203
f :: "Complex -> Complex",
198204
limits = (-1, 1, -1, 1);
199205
pixels = (480, 480),
206+
box = nothing,
200207
kwargs...
201208
)
202209
@@ -222,16 +229,21 @@ to ``\\pi``, and black to ``\\frac{3\\pi}{2}``.
222229
for both if only one number is provided. If either is `:auto`, the
223230
viewport resolution is used.
224231
232+
- **`box`** if set to `(a, b, s)` shades the area where the the output
233+
is within the box `a` and `b` in the color `s`. Can also be a list of
234+
multiple boxes.
235+
225236
Remaining keyword arguments are passed to Makie.
226237
"""
227238
function pdphaseplot(
228239
f,
229240
limits = (-1, 1, -1, 1);
230241
pixels = (480, 480),
242+
box = nothing,
231243
kwargs...
232244
)
233245

234-
interactiveshadedplot(f, DC.pdphaseplotshader,
246+
interactiveshadedplot(f, w -> DC.pdphaseplotshader(w; box),
235247
limits, pixels; kwargs...)
236248
end
237249

@@ -240,6 +252,7 @@ end
240252
f :: "Complex -> Complex",
241253
limits = (-1, 1, -1, 1);
242254
pixels = (480, 480),
255+
box = nothing,
243256
kwargs...
244257
)
245258
@@ -265,16 +278,21 @@ Red corresponds to phase ``0``, white to ``\\frac{\\pi}{2}``, cyan to
265278
for both if only one number is provided. If either is `:auto`, the
266279
viewport resolution is used.
267280
281+
- **`box`** if set to `(a, b, s)` shades the area where the the output
282+
is within the box `a` and `b` in the color `s`. Can also be a list of
283+
multiple boxes.
284+
268285
Remaining keyword arguments are passed to Makie.
269286
"""
270287
function tphaseplot(
271288
f,
272289
limits = (-1, 1, -1, 1);
273290
pixels = (480, 480),
291+
box = nothing,
274292
kwargs...
275293
)
276294

277-
interactiveshadedplot(f, DC.tphaseplotshader,
295+
interactiveshadedplot(f, w -> DC.tphaseplotshader(w; box),
278296
limits, pixels; kwargs...)
279297
end
280298

@@ -289,6 +307,8 @@ end
289307
angle = false,
290308
abs = false,
291309
polar = false,
310+
box = nothing,
311+
hicontrast = false,
292312
kwargs...
293313
)
294314
@@ -329,6 +349,10 @@ Numbers can be provided instead of booleans to override the default rates.
329349
330350
- **`phase`** is a shortcut for `angle = true` and `abs = true`.
331351
352+
- **`box`** if set to `(a, b, s)` shades the area where the the output
353+
is within the box `a` and `b` in the color `s`. Can also be a list of
354+
multiple boxes.
355+
332356
- **`hicontrast`** uses black and white instead of the softer defaults.
333357
334358
Remaining keyword arguments are passed to Makie.
@@ -343,12 +367,13 @@ function checkerplot(
343367
angle = false,
344368
abs = false,
345369
polar = false,
370+
box = nothing,
346371
hicontrast = false,
347372
kwargs...
348373
)
349374

350375
interactiveshadedplot(f, w -> DC.checkerplotshader(
351-
w; real, imag, rect, angle, abs, polar, hicontrast
376+
w; real, imag, rect, angle, abs, polar, box, hicontrast
352377
), limits, pixels; kwargs...)
353378
end
354379

@@ -364,6 +389,7 @@ end
364389
abs = false,
365390
polar = false,
366391
color = false,
392+
box = nothing,
367393
kwargs...
368394
)
369395
@@ -406,6 +432,10 @@ Numbers can be provided instead of booleans to override the default rates.
406432
- **`color`** toggles coloring of the phase angle. Can also be set to
407433
either the name of, or a `ColorScheme`, or a function `θ -> Color`.
408434
435+
- **`box`** if set to `(a, b, s)` shades the area where the the output
436+
is within the box `a` and `b` in the color `s`. Can also be a list of
437+
multiple boxes.
438+
409439
Remaining keyword arguments are passed to Makie.
410440
"""
411441
function sawplot(
@@ -419,11 +449,12 @@ function sawplot(
419449
abs = false,
420450
polar = false,
421451
color = false,
452+
box = nothing,
422453
kwargs...
423454
)
424455

425456
interactiveshadedplot(f, w -> DC.sawplotshader(
426-
w; real, imag, rect, angle, abs, polar, color
457+
w; real, imag, rect, angle, abs, polar, color, box
427458
), limits, pixels; kwargs...)
428459
end
429460

docs/src/usage/general.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ All plots have a keyword argument `pixels` by which one can specify the
2222
number of samples in respectively the real and imaginary direction. If
2323
only one number is provided it is used for both.
2424

25+
Additionally there is also the option to fill in a box, or list of boxes
26+
in the output space using the option `box`, which is illustrated in the
27+
section on [`checkerplot`](@ref) and [`sawplot`](@ref).
28+
2529
Finally, any remaining keywords are passed to Makie. This, together with
2630
the modifying variants (`domaincolor!`, `checkerplot!`, etc.), makes the
2731
plotting routines in this library behave similarly to other Makie plot
@@ -151,7 +155,7 @@ discussed so far also accept numbers, modifying the rate of the stripes.
151155
For example, we get for magnitude:
152156
```@example
153157
using CairoMakie, DomainColoring # hide
154-
checkerplot(z -> z, 5, abs=5)
158+
sawplot(z -> z, 5, abs=5)
155159
resize!(current_figure(), 620, 600) #hide
156160
save("cpabs.png", current_figure()) # hide
157161
nothing # hide
@@ -162,7 +166,7 @@ and for phase:
162166

163167
```@example
164168
using CairoMakie, DomainColoring # hide
165-
sawplot(z -> z, 5, angle=10)
169+
checkerplot(z -> z, 5, angle=10)
166170
resize!(current_figure(), 620, 600) #hide
167171
save("cpangle.png", current_figure()) # hide
168172
nothing # hide
@@ -181,6 +185,17 @@ nothing # hide
181185
```
182186
![](cppolarsin.png)
183187

188+
As mentioned before regions of the output plane can be colored using the
189+
`box` option, for example:
190+
```@example
191+
using CairoMakie, DomainColoring # hide
192+
checkerplot(z -> z^2, 2, box=[(1,1im,:red), (-1-2im,-2-1im,:blue)])
193+
resize!(current_figure(), 620, 600) #hide
194+
save("cpboxes.png", current_figure()) # hide
195+
nothing # hide
196+
```
197+
![](cpboxes.png)
198+
184199
Finally, `hicontrast = true` can be used in [`checkerplot`](@ref) to
185200
plot in black and white instead of the slightly softer defaults, and
186201
`color = true` mixes phase coloring into a [`sawplot`](@ref) (further
@@ -195,7 +210,7 @@ and the rate of the grid. Additionally, we can pass named tuples to open
195210
up even more options.
196211

197212
For `grid` these options are identical to `checkerplot`, for example an
198-
analogous example to the final one of last section, is given by:
213+
analogous example to the penultimate one of last section, is given by:
199214
```@example
200215
using CairoMakie, DomainColoring # hide
201216
domaincolor(sin, (5, 2), grid=(polar=4,))

0 commit comments

Comments
 (0)