Merge pull request #2010 from daschw/polar
Avoid filtering data in polar plots (fix #2009)
This commit is contained in:
commit
1a4f411b8f
@ -171,7 +171,7 @@ function pgf_series(sp::Subplot, series::Series)
|
|||||||
elseif st == :shape
|
elseif st == :shape
|
||||||
shape_data(series)
|
shape_data(series)
|
||||||
elseif ispolar(sp)
|
elseif ispolar(sp)
|
||||||
theta, r = filter_radial_data(plotattributes[:x], plotattributes[:y], axis_limits(sp[:yaxis]))
|
theta, r = plotattributes[:x], plotattributes[:y]
|
||||||
rad2deg.(theta), r
|
rad2deg.(theta), r
|
||||||
else
|
else
|
||||||
plotattributes[:x], plotattributes[:y]
|
plotattributes[:x], plotattributes[:y]
|
||||||
|
|||||||
@ -774,7 +774,7 @@ end
|
|||||||
function plotly_polar!(plotattributes_out::KW, series::Series)
|
function plotly_polar!(plotattributes_out::KW, series::Series)
|
||||||
# convert polar plots x/y to theta/radius
|
# convert polar plots x/y to theta/radius
|
||||||
if ispolar(series[:subplot])
|
if ispolar(series[:subplot])
|
||||||
theta, r = filter_radial_data(pop!(plotattributes_out, :x), pop!(plotattributes_out, :y), axis_limits(series[:subplot][:yaxis]))
|
theta, r = pop!(plotattributes_out, :x), pop!(plotattributes_out, :y)
|
||||||
plotattributes_out[:t] = rad2deg.(theta)
|
plotattributes_out[:t] = rad2deg.(theta)
|
||||||
plotattributes_out[:r] = r
|
plotattributes_out[:r] = r
|
||||||
end
|
end
|
||||||
|
|||||||
@ -376,6 +376,18 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
elseif st == :shape
|
elseif st == :shape
|
||||||
x, y = shape_data(series)
|
x, y = shape_data(series)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if ispolar(series)
|
||||||
|
# make negative radii positive and flip the angle
|
||||||
|
# (PyPlot ignores negative radii)
|
||||||
|
for i in eachindex(y)
|
||||||
|
if y[i] < 0
|
||||||
|
y[i] = -y[i]
|
||||||
|
x[i] -= π
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
xyargs = (st in _3dTypes ? (x,y,z) : (x,y))
|
xyargs = (st in _3dTypes ? (x,y,z) : (x,y))
|
||||||
|
|
||||||
# handle zcolor and get c/cmap
|
# handle zcolor and get c/cmap
|
||||||
|
|||||||
26
src/utils.jl
26
src/utils.jl
@ -373,38 +373,14 @@ function heatmap_edges(v::AVec, scale::Symbol = :identity)
|
|||||||
map(invf, _heatmap_edges(map(f,v)))
|
map(invf, _heatmap_edges(map(f,v)))
|
||||||
end
|
end
|
||||||
|
|
||||||
function calc_r_extrema(x, y)
|
function convert_to_polar(theta, r, r_extrema = ignorenan_extrema(r))
|
||||||
xmin, xmax = ignorenan_extrema(x)
|
|
||||||
ymin, ymax = ignorenan_extrema(y)
|
|
||||||
r = 0.5 * NaNMath.min(xmax - xmin, ymax - ymin)
|
|
||||||
ignorenan_extrema(r)
|
|
||||||
end
|
|
||||||
|
|
||||||
function convert_to_polar(x, y, r_extrema = calc_r_extrema(x, y))
|
|
||||||
rmin, rmax = r_extrema
|
rmin, rmax = r_extrema
|
||||||
theta, r = filter_radial_data(x, y, r_extrema)
|
|
||||||
r = (r .- rmin) ./ (rmax .- rmin)
|
r = (r .- rmin) ./ (rmax .- rmin)
|
||||||
x = r.*cos.(theta)
|
x = r.*cos.(theta)
|
||||||
y = r.*sin.(theta)
|
y = r.*sin.(theta)
|
||||||
x, y
|
x, y
|
||||||
end
|
end
|
||||||
|
|
||||||
# Filters radial data for points within the axis limits
|
|
||||||
function filter_radial_data(theta, r, r_extrema::Tuple{Real, Real})
|
|
||||||
n = max(length(theta), length(r))
|
|
||||||
rmin, rmax = r_extrema
|
|
||||||
x, y = zeros(n), zeros(n)
|
|
||||||
for i in 1:n
|
|
||||||
x[i] = _cycle(theta, i)
|
|
||||||
y[i] = _cycle(r, i)
|
|
||||||
end
|
|
||||||
points = map((a, b) -> (a, b), x, y)
|
|
||||||
filter!(a -> a[2] >= rmin && a[2] <= rmax, points)
|
|
||||||
x = map(a -> a[1], points)
|
|
||||||
y = map(a -> a[2], points)
|
|
||||||
x, y
|
|
||||||
end
|
|
||||||
|
|
||||||
function fakedata(sz...)
|
function fakedata(sz...)
|
||||||
y = zeros(sz...)
|
y = zeros(sz...)
|
||||||
for r in 2:size(y,1)
|
for r in 2:size(y,1)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user