Skip to content

Commit

Permalink
Merge 2873015 into dffca7a
Browse files Browse the repository at this point in the history
  • Loading branch information
April-Hannah-Lena committed May 12, 2021
2 parents dffca7a + 2873015 commit bca04ef
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.1.0"
[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
10 changes: 7 additions & 3 deletions src/ComplexPortraits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
module ComplexPortraits

using Colors
using Colors, RecipesBase

"""macro for importing the *huge* set of symbols."""
macro import_huge()
Expand All @@ -21,7 +21,8 @@ macro import_huge()
cs_gridReIm, cs_gridReIm_logabs, cs_gridReIm_abs,
cs_stripes, cs_angle_abs_stripes,
cs_useImage,
portrait
portrait,
phaseplot, phaseplot!, PhasePlot
)
end

Expand All @@ -36,7 +37,8 @@ macro import_normal()
cs_gridReIm, cs_gridReIm_logabs, cs_gridReIm_abs,
cs_stripes, cs_angle_abs_stripes,
cs_useImage,
portrait
portrait,
phaseplot, phaseplot!, PhasePlot
)
end

Expand Down Expand Up @@ -68,6 +70,8 @@ function portrait(z_upperleft, z_lowerright, f;
x in LinRange(real(z_upperleft), real(z_lowerright), no_pixels[2])]
end

include("./plotrecipes.jl")

end

# vim:syn=julia:cc=79:fdm=indent:sw=2:ts=2:
61 changes: 61 additions & 0 deletions src/plotrecipes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
@userplot PhasePlot
# args: z_upperleft::Complex, z_lowerright::Complex, f::Function
@recipe function plot_portrait(P::PhasePlot;
no_pixels=(600,600), point_color=cs_j(),
no_ticks=7, ticks_sigdigits=2)
length(no_ticks) == 1 && (no_ticks = (no_ticks, no_ticks))
z_upperleft, z_lowerright, f = P.args[1:3]
img = portrait(z_upperleft, z_lowerright, f;
no_pixels=no_pixels, point_color=point_color);

seriestype := :heatmap
xticks := (LinRange(0, no_pixels[1], no_ticks[1]),
round.(LinRange(imag(z_lowerright), imag(z_upperleft), no_ticks[1]), sigdigits=ticks_sigdigits))
yticks := (LinRange(0, no_pixels[2], no_ticks[2]),
round.(LinRange(real(z_upperleft), real(z_lowerright), no_ticks[2]), sigdigits=ticks_sigdigits))

img
end

"""
```
phaseplot(z_upperleft, z_lowerright, f)
```
Convinience function, automatically adds ticks and creates a `Plot` object.
Can be used in layouts. Examples:
```
using Plots, ComplexPortraits
@ComplexPortraits.import_huge
phaseplot(-2.0 + 2.0im, 2.0 - 2.0im, z -> z^2)
phaseplot(-2.0 + 2.0im, 2.0 - 2.0im, z -> z^2;
no_pixels=(600, 600),
point_color=cs_j(),
no_ticks=(7, 7),
ticks_sigdigits=2)
```
Todo: hack colorbar plotattribute to show colorwheel.
"""
phaseplot;

"""
tests:
function crop_to_circle!(A:Array; radius=0, background_color=RGB{Float64}(1.0,1.0,1.0))
m, n = size(A)
max_radius = min(m, n) / 2
center = [m/2, n/2]
(radius < 0 || radius > max_radius) && cv_error("plot image size too small. ",
"Maximum radius = ", max_radius)
radius == 0 && (radius = max_radius)
for i in Base.OneTo(m), j in Base.OneTo(n)
sum(([i, j] .- center).^2) * π > radius && (A[i, j] = background_color)
end
return A
end
"""

0 comments on commit bca04ef

Please sign in to comment.