Skip to content

Commit

Permalink
Separate _getvector from streamplot
Browse files Browse the repository at this point in the history
  • Loading branch information
henry2004y committed Aug 3, 2024
1 parent 861ecd4 commit 0a6d7e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/plot/pyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,19 @@ end
streamplot(data, var, ax=nothing; plotrange=[-Inf,Inf,-Inf,Inf], plotinterval=0.1,
kwargs...)
Wrapper over `streamplot` in matplotlib .
Wrapper over `streamplot` in matplotlib.
"""
function PyPlot.streamplot(bd::BATLData{2, T}, var::AbstractString, ax=nothing;
plotrange=[-Inf,Inf,-Inf,Inf], plotinterval=0.1, kwargs...) where T
xi, yi, v1, v2 = _getvector(bd, var; plotrange, plotinterval)

if isnothing(ax) ax = plt.gca() end

ax.streamplot(xi, yi, v1, v2; kwargs...)
end

function _getvector(bd::BATLData{2, T}, var::AbstractString;
plotrange=[-Inf,Inf,-Inf,Inf], plotinterval=0.1) where T
x, w = bd.x, bd.w
varstream = split(var, ";")
wnames = lowercase.(bd.head.wnames)
Expand Down Expand Up @@ -701,9 +710,8 @@ function PyPlot.streamplot(bd::BATLData{2, T}, var::AbstractString, ax=nothing;
v2 = [interp2(i, j) for j in yi, i in xi]
end
end
if isnothing(ax) ax = plt.gca() end

ax.streamplot(xi, yi, v1, v2; kwargs...)
xi, yi, v1, v2
end

"""
Expand Down
1 change: 1 addition & 0 deletions src/plot/utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ function interpolate2d_generalized_coords(X::T, Y::T, W::T,
xi = range(plotrange[1], stop=plotrange[2], step=plotinterval)
yi = range(plotrange[3], stop=plotrange[4], step=plotinterval)
itp = NN.interpolate(X, Y, W)
#TODO Interpolate as a whole using predicates with multithreading
Wi = [itp(x, y; method=NN.Triangle()) for y in yi, x in xi]::Matrix{eltype(W)}

xi, yi, Wi
Expand Down

0 comments on commit 0a6d7e1

Please sign in to comment.