diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index da527f9a..43c15eab 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -221,7 +221,8 @@ function pgf_series(sp::Subplot, series::Series) # See "Scatter Plots" in PGFPlots documentation d[:x], d[:y], d[:marker_z] elseif ispolar(sp) - rad2deg.(d[:x]), d[:y] + theta, r = filter_radial_data(d[:x], d[:y], axis_limits(sp[:yaxis])) + rad2deg.(theta), r else d[:x], d[:y] end diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 9ada51f7..e9a662cc 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -717,8 +717,9 @@ end function plotly_polar!(d_out::KW, series::Series) # convert polar plots x/y to theta/radius if ispolar(series[:subplot]) - d_out[:t] = rad2deg.(pop!(d_out, :x)) - d_out[:r] = pop!(d_out, :y) + theta, r = filter_radial_data(pop!(d_out, :x), pop!(d_out, :y), axis_limits(series[:subplot][:yaxis])) + d_out[:t] = rad2deg.(theta) + d_out[:r] = r end end diff --git a/src/utils.jl b/src/utils.jl index 81cd3571..d19a2acb 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -363,15 +363,26 @@ end function convert_to_polar(x, y, r_extrema = calc_r_extrema(x, y)) rmin, rmax = r_extrema - phi, r = x, y + theta, r = filter_radial_data(x, y, r_extrema) r = (r - rmin) / (rmax - rmin) - n = max(length(phi), length(r)) - x = zeros(n) - y = zeros(n) + x = r.*cos.(theta) + y = r.*sin.(theta) + x, y +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(r,i) * cos.(_cycle(phi,i)) - y[i] = _cycle(r,i) * sin.(_cycle(phi,i)) + 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