Skip to content

Commit

Permalink
Add pcolormesh
Browse files Browse the repository at this point in the history
  • Loading branch information
henry2004y committed Nov 28, 2023
1 parent be9f99c commit 7036cbf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
19 changes: 18 additions & 1 deletion src/plot/pyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using PyPlot
using Dierckx: Spline2D

export plotdata, plotlogdata, plot, scatter, contour, contourf, plot_surface,
tricontourf, plot_trisurf, streamplot, streamslice, quiver, cutplot
tricontourf, plot_trisurf, streamplot, streamslice, quiver, cutplot, pcolormesh

@static if matplotlib.__version__ >= "3.3"
matplotlib.rc("image", cmap="turbo") # set default colormap
Expand Down Expand Up @@ -644,6 +644,23 @@ function PyPlot.plot_surface(bd::BATLData, var::AbstractString;
plot_surface(Xi, Yi, Wi'; kwargs...)
end


"""
pcolormesh(data, var, levels=0; ax=nothing, plotrange=[-Inf,Inf,-Inf,Inf],
plotinterval=0.1, innermask=false, kwargs...)
Wrapper over `pcolormesh` in matplotlib.
"""
function PyPlot.pcolormesh(bd::BATLData, var::AbstractString; ax=nothing,
plotrange=[-Inf,Inf,-Inf,Inf], plotinterval=0.1, innermask=false, kwargs...)

Xi, Yi, Wi = getdata(bd, var, plotrange, plotinterval; innermask)

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

c = ax.pcolormesh(Xi, Yi, Wi'; kwargs...)
end

"""
streamplot(data, var, ax=nothing; plotrange=[-Inf,Inf,-Inf,Inf], plotinterval=0.1,
kwargs...)
Expand Down
13 changes: 7 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ end
@test plt isa Heatmap
end

@testset "1D ascii" begin
@testset "PyPlot" begin
# 1D ascii
file = "1d__raw_2_t25.60000_n00000258.out"
bd = load(file, dir=datapath, verbose=false)
plotdata(bd, "p", plotmode="line")
line = get(gca().lines, 0)
@test line.get_xdata() bd.x
@test line.get_ydata() bd.w[:,10]
end

@testset "2D structured binary" begin

# 2D structured binary
file = "z=0_raw_1_t25.60000_n00000258.out"
bd = load(file, dir=datapath)
plotdata(bd, "p bx;by", plotmode="contbar streamover")
Expand All @@ -140,15 +140,16 @@ end
@test isa(gca(), PyPlot.PyObject)
PyPlot.streamplot(bd, "bx;by")
@test isa(gca(), PyPlot.PyObject)
p = PyPlot.pcolormesh(bd, "p").get_array()
@test p[end] == 0.1f0
plt.close()
fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")
plot_surface(bd, "rho")
@test isa(gca(), PyPlot.PyObject)
plt.close()
end

@testset "2D AMR Cartesian" begin
# 2D AMR Cartesian
file = "bx0_mhd_6_t00000100_n00000352.out"
bd = load(file, dir=datapath)
plotdata(bd, "P", plotmode="contbar")
Expand Down

0 comments on commit 7036cbf

Please sign in to comment.