Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent PyPlot from normalizing quiver vectors #19

Merged
merged 4 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
QUARRY
.project.jl
docs/build
docs/src/examples/*.png
docs/src/examples/*.svg
docs/src/examples/*.gif
*~
*.html
*.svg
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GridVisualize"
uuid = "5eed8a63-0fb0-45eb-886d-8d5a387d12b8"
authors = ["Juergen Fuhrmann <juergen.fuhrmann@wias-berlin.de>"]
version = "1.3.2"
version = "1.3.3"

[deps]
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Expand All @@ -26,7 +26,7 @@ PlutoVista = "646e1f28-b900-46d7-9d87-d554eb38a413"
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"

[compat]
CairoMakie = "0.11"
CairoMakie = "0.11.3"
ColorSchemes = "3"
Colors = "0.12,1"
DocStringExtensions = "0.8,0.9"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ExtendableGrids = "cfc395e8-590f-11e8-1f13-43a2532b2fa8"
GridVisualize = "5eed8a63-0fb0-45eb-886d-8d5a387d12b8"
HypertextLiteral = "ac1192a8-f4b3-4bfe-ba22-af5b92cd3ab2"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Pluto = "c3e4b0f8-55cb-11ea-2926-15256bba5781"
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
PlutoVista = "646e1f28-b900-46d7-9d87-d554eb38a413"
Expand Down
18 changes: 7 additions & 11 deletions examples/plutovista.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
### A Pluto.jl notebook ###
# v0.19.29
# v0.19.32

using Markdown
using InteractiveUtils

# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local iv = try
Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value
catch
b -> missing
end
local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
local el = $(esc(element))
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el)
el
Expand Down Expand Up @@ -459,7 +455,7 @@ Revise = "~3.5.6"
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised

julia_version = "1.9.3"
julia_version = "1.9.4"
manifest_format = "2.0"
project_hash = "e16c3e55d1b87c5f4dccb5b049d023b943a3107e"

Expand Down Expand Up @@ -749,12 +745,12 @@ version = "0.9.26"
[[deps.LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
version = "0.6.3"
version = "0.6.4"

[[deps.LibCURL_jll]]
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
version = "7.84.0+0"
version = "8.4.0+0"

[[deps.LibGit2]]
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
Expand All @@ -763,7 +759,7 @@ uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
[[deps.LibSSH2_jll]]
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"
version = "1.10.2+0"
version = "1.11.0+1"

[[deps.Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Expand Down Expand Up @@ -1067,7 +1063,7 @@ version = "5.8.0+0"
[[deps.nghttp2_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"
version = "1.48.0+0"
version = "1.52.0+1"

[[deps.p7zip_jll]]
deps = ["Artifacts", "Libdl"]
Expand Down
2 changes: 1 addition & 1 deletion src/makie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ function vectorplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grid, func)
XMakie = ctx[:Plotter]

rc, rv = vectorsample(grid, func; spacing = ctx[:spacing], offset = ctx[:offset])
qc, qv = quiverdata(rc, rv; vscale = ctx[:vscale], vnormalize = ctx[:vnormalize])
qc, qv = quiverdata(rc, rv; vscale = ctx[:vscale], vnormalize = ctx[:vnormalize], vconstant = ctx[:vconstant])

set_plot_data!(ctx, :arrowdata, (qc = qc, qv = qv))

Expand Down
13 changes: 8 additions & 5 deletions src/plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,17 @@ function rectdata(grid, U)
end

function scalarplot!(ctx, TP::Type{PlotsType}, ::Type{Val{2}}, grids, parentgrid, funcs)
grid = parentgrid
grid = grids[1]
func = funcs[1]
rdata = rectdata(grid, func)
if rdata == nothing
return nothing
end
Plots = ctx[:Plotter]
if !haskey(ctx, :ax)
ctx[:ax] = Plots.plot(; title = ctx[:title])
end
if rdata == nothing
@warn "2D scalarplot with Plots backend works only on rectangular grids with X and Y coordinate vectors"
return reveal(ctx, TP)
end
p = ctx[:ax]

levels, crange, colorbarticks = isolevels(ctx, func)
Expand Down Expand Up @@ -375,15 +376,17 @@ function gridplot!(ctx, TP::Type{PlotsType}, ::Type{Val{3}}, grid)
if !haskey(ctx, :ax)
ctx[:ax] = Plots.plot(; title = ctx[:title])
end
@warn "3D gridplot with Plots backend is not available."
reveal(ctx, TP)
end

function scalarplot!(ctx, TP::Type{PlotsType}, ::Type{Val{3}}, grids, parentgrid, funcs)
grid = parentgrid
grid = grids[1]
func = funcs[1]
Plots = ctx[:Plotter]
if !haskey(ctx, :ax)
ctx[:ax] = Plots.plot(; title = ctx[:title])
end
@warn "3D Scalarplot with Plots backend is not available."
reveal(ctx, TP)
end
5 changes: 4 additions & 1 deletion src/pyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,10 @@ function vectorplot!(ctx, TP::Type{PyPlotType}, ::Type{Val{2}}, grid, func)
ylimits = ctx[:ylimits])
qc, qv = quiverdata(rc, rv; vscale = ctx[:vscale], vnormalize = ctx[:vnormalize], vconstant = ctx[:vconstant])

ax.quiver(qc[1, :], qc[2, :], qv[1, :], qv[2, :]; color = ctx[:color])
# For the kwargs, see
# https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.quiver.html
# Without them, PyPlot itself normalizes
ax.quiver(qc[1, :], qc[2, :], qv[1, :], qv[2, :]; color = ctx[:color], scale = 1, angles = "xy", scale_units = "xy")
ax.set_xlabel(ctx[:xlabel])
ax.set_ylabel(ctx[:ylabel])

Expand Down
Loading