Skip to content

Commit

Permalink
add 3dquiver to pgfplotsx (JuliaPlots#3146)
Browse files Browse the repository at this point in the history
* add 3dquiver to pgfplotsx

* fix 3d quiver

* remove skip from examples
  • Loading branch information
BeastyBlacksmith authored Nov 13, 2020
1 parent 5861b1f commit a955ded
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
27 changes: 20 additions & 7 deletions src/backends/pgfplotsx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
)
extra_series, extra_series_opt = pgfx_split_extra_opts(series[:extra_kwargs])
series_opt = merge(series_opt, PGFPlotsX.Options(extra_series_opt...))
if RecipesPipeline.is3d(series) || st in (:heatmap, :contour)
if RecipesPipeline.is3d(series) || st in (:heatmap, :contour) || (st == :quiver && opt[:z] !== nothing)
series_func = PGFPlotsX.Plot3
else
series_func = PGFPlotsX.Plot
Expand Down Expand Up @@ -587,12 +587,25 @@ function pgfx_add_series!(::Val{:quiver}, axis, series_opt, series, series_func,
)
x = opt[:x]
y = opt[:y]
table = PGFPlotsX.Table([
:x => x,
:y => y,
:u => opt[:quiver][1],
:v => opt[:quiver][2],
])
z = opt[:z]
if z !== nothing
push!(series_opt["quiver"], "w" => "\\thisrow{w}")
table = PGFPlotsX.Table([
:x => x,
:y => y,
:z => z,
:u => opt[:quiver][1],
:v => opt[:quiver][2],
:w => opt[:quiver][3],
])
else
table = PGFPlotsX.Table([
:x => x,
:y => y,
:u => opt[:quiver][1],
:v => opt[:quiver][2],
])
end
end
series_plot = series_func(series_opt, table)
push!(axis, series_plot)
Expand Down
13 changes: 6 additions & 7 deletions src/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1055,10 +1055,10 @@ const _examples = PlotExample[
f(x,a) = 1/x + a*x^2
xs = collect(0.1:0.05:2.0);
as = collect(0.2:0.1:2.0);

x_grid = [x for x in xs for y in as];
a_grid = [y for x in xs for y in as];

plot(x_grid, a_grid, f.(x_grid,a_grid),
st = :surface,
xlabel = "longer xlabel",
Expand All @@ -1074,7 +1074,7 @@ const _examples = PlotExample[
using Plots
using TestImages
img = testimage("lighthouse")

# plot the image reversing the first dimension and setting yflip = false
plot([-π, π], [-1, 1], reverse(img, dims=1), yflip=false, aspect_ratio=:none)
# plot other data
Expand All @@ -1090,15 +1090,15 @@ const _examples = PlotExample[
ϕs = range(-π, π, length=50)
θs = range(0, π, length=25)
θqs = range(1, π-1, length=25)

x = vec([sin(θ) * cos(ϕ) for (ϕ, θ) in Iterators.product(ϕs, θs)])
y = vec([sin(θ) * sin(ϕ) for (ϕ, θ) in Iterators.product(ϕs, θs)])
z = vec([cos(θ) for (ϕ, θ) in Iterators.product(ϕs, θs)])

u = 0.1 * vec([sin(θ) * cos(ϕ) for (ϕ, θ) in Iterators.product(ϕs, θqs)])
v = 0.1 * vec([sin(θ) * sin(ϕ) for (ϕ, θ) in Iterators.product(ϕs, θqs)])
w = 0.1 * vec([cos(θ) for (ϕ, θ) in Iterators.product(ϕs, θqs)])

quiver(x,y,z, quiver=(u,v,w))
end]
),
Expand All @@ -1120,7 +1120,6 @@ _backend_skips = Dict(
32, # spy
49, # polar heatmap
51, # image with custom axes
52, # 3d quiver
],
)

Expand Down
2 changes: 1 addition & 1 deletion src/pipeline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ end

function _override_seriestype_check(plotattributes::AKW, st::Symbol)
# do we want to override the series type?
if !RecipesPipeline.is3d(st) && !(st in (:contour, :contour3d))
if !RecipesPipeline.is3d(st) && !(st in (:contour, :contour3d, :quiver))
z = plotattributes[:z]
if !isa(z, Nothing) &&
(size(plotattributes[:x]) == size(plotattributes[:y]) == size(z))
Expand Down

0 comments on commit a955ded

Please sign in to comment.