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

Fix Pyplot, Add unit tests #55

Merged
merged 3 commits into from
Nov 29, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

- unit test for undocumented names

- Unit test for `PyPlot` and `PlutoVista`

### Removed

- dangling exported function `backend!`
Expand Down
11 changes: 11 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@ Printf = "1.6"
PyPlot = "2"
StaticArrays = "1"
julia = "1.9"

[extras]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
ExtendableGrids = "cfc395e8-590f-11e8-1f13-43a2532b2fa8"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PlutoVista = "646e1f28-b900-46d7-9d87-d554eb38a413"
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["CairoMakie", "ExtendableGrids", "Pkg", "PlutoVista", "PyPlot", "Test"]
11 changes: 9 additions & 2 deletions src/pyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,17 @@ function gridplot!(ctx, TP::Type{PyPlotType}, ::Type{Val{2}}, grid)

cell_colors = cellcolors(grid, ctx[:cellcoloring])

# the first triangle for dummy plot below
dummy_triangle = @views tridat[3][1, :]

# the corresponding coordinates (add +1 for Python → Julia)
dummy_coords_x = [ tridat[1][i + 1] for i in dummy_triangle ]
dummy_coords_y = [ tridat[2][i + 1] for i in dummy_triangle ]

# dummy plot to get a correct color bar for the boundary data
bcdata = ax.tripcolor(
tridat[1][1:3], tridat[2][1:3]; # extract a single point from the original triangulation
facecolors = cell_colors[1:1], # only one triangle!
dummy_coords_x, dummy_coords_y, dummy_triangle; # use the dummy triangle
facecolors = cell_colors[1:1], # only one triangle!
cmap = PyPlot.ColorMap(bcmap, length(bcmap)),
vmin = 0.5,
vmax = length(bcmap) + 0.5,
Expand Down
6 changes: 0 additions & 6 deletions test/Project.toml

This file was deleted.

22 changes: 19 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
using Test, ExtendableGrids, GridVisualize, Pkg
import CairoMakie

import CairoMakie, PyPlot, PlutoVista

CairoMakie.activate!(; type = "svg", visible = false)

plotting = joinpath(@__DIR__, "..", "examples", "plotting.jl")
include(plotting)
include("../docs/makeplots.jl")
@testset "makeplots - CairoMakie" begin
makeplots(mktempdir(); Plotter = CairoMakie, extension = ".svg")

for Plotter in [CairoMakie]
@eval begin
@testset "makeplots - $(nameof($Plotter))" begin
makeplots(mktempdir(); Plotter = $Plotter, extension = ".svg")
end
end
end

# Some Plotters cannot perform the `makeplots` run, only try a `multiscene`
for Plotter in [PyPlot, PlutoVista]
@eval begin
@testset "plotting_multiscene - $(nameof($Plotter))" begin
@test plotting_multiscene(Plotter = $Plotter) !== nothing
end
end
end


Expand Down
Loading