Skip to content

Commit b8be735

Browse files
committed
Fix bug with plotting multiple figures
For the functions `_geomakie_plot_on_globe!`, `heatmap2D!`, and `line_plot1D!`, you cannot initialize multiple figures and use these functions afterward as you get the error "LoadError: There is no current axis to plot into". To fix this, we initialize an `Axis` object in the function and use that for plotting.
1 parent 7fe2021 commit b8be735

5 files changed

+18
-8
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var_no_ocean = ClimaAnalysis.apply_oceanmask(var)
2424
- Masking now affects the colorbar.
2525
- `Var.shift_to_start_of_previous_month` now checks for duplicate dates and throws an error
2626
if duplicate dates are detected.
27+
- Fix issue with plotting multiple figures at the same time.
2728

2829
v0.5.10
2930
-------

ext/ClimaAnalysisGeoMakieExt.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ function _geomakie_plot_on_globe!(
8484

8585
title = get(axis_kwargs, :title, var.attributes["long_name"])
8686

87-
GeoMakie.GeoAxis(place[p_loc...]; title, axis_kwargs...)
87+
ax = GeoMakie.GeoAxis(place[p_loc...]; title, axis_kwargs...)
8888

89-
plot = plot_fn(lon, lat, var.data; plot_kwargs...)
90-
plot_mask && Makie.poly!(mask; mask_kwargs...)
91-
plot_coastline && Makie.lines!(GeoMakie.coastlines(); coast_kwargs...)
89+
plot = plot_fn(ax, lon, lat, var.data; plot_kwargs...)
90+
plot_mask && Makie.poly!(ax, mask; mask_kwargs...)
91+
plot_coastline && Makie.lines!(ax, GeoMakie.coastlines(); coast_kwargs...)
9292

9393
if plot_colorbar
9494
p_loc_cb = Tuple([p_loc[1], p_loc[2] + 1])

ext/ClimaAnalysisMakieExt.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ function Visualize.heatmap2D!(
7979
axis_kwargs = pairs(axis_kwargs_dict)
8080
end
8181

82-
Makie.Axis(place[p_loc...]; title, xlabel, ylabel, axis_kwargs...)
82+
ax = Makie.Axis(place[p_loc...]; title, xlabel, ylabel, axis_kwargs...)
8383

84-
plot = Makie.heatmap!(dim1, dim2, var.data; plot_kwargs...)
84+
plot = Makie.heatmap!(ax, dim1, dim2, var.data; plot_kwargs...)
8585

8686
p_loc_cb = Tuple([p_loc[1], p_loc[2] + 1])
8787
Makie.Colorbar(
@@ -318,8 +318,8 @@ function Visualize.line_plot1D!(
318318
axis_kwargs = pairs(axis_kwargs_dict)
319319
end
320320

321-
Makie.Axis(place[p_loc...]; title, xlabel, ylabel, axis_kwargs...)
322-
Makie.lines!(x, y; plot_kwargs...)
321+
ax = Makie.Axis(place[p_loc...]; title, xlabel, ylabel, axis_kwargs...)
322+
Makie.lines!(ax, x, y; plot_kwargs...)
323323
end
324324

325325
"""

test/test_GeoMakieExt.jl

+3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ using OrderedCollections
2727
])
2828
var2D = ClimaAnalysis.OutputVar(attribs, dims2D, dim_attributes2D, data2D)
2929

30+
# Intialize another figure to see if plotting with multiple figures initialized is
31+
# possible
3032
fig = Makie.Figure()
33+
fig1 = Makie.Figure()
3134

3235
ClimaAnalysis.Visualize.heatmap2D_on_globe!(fig, var2D)
3336

test/test_MakieExt.jl

+6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ using OrderedCollections
2929
])
3030
var3D = ClimaAnalysis.OutputVar(attribs, dims3D, dim_attributes3D, data3D)
3131

32+
# Intialize another figure to see if plotting with multiple figures initialized is
33+
# possible
3234
fig = Makie.Figure()
35+
fig1 = Makie.Figure()
3336
@test_throws ErrorException ClimaAnalysis.Visualize.heatmap2D!(fig, var3D)
3437

3538
data2D = reshape(1.0:(91 * 181), (181, 91))
@@ -91,7 +94,10 @@ using OrderedCollections
9194
dim_attributes1D = OrderedDict(["lat" => Dict(["units" => "degrees"])])
9295
var1D = ClimaAnalysis.OutputVar(attribs, dims1D, dim_attributes1D, data1D)
9396

97+
# Intialize another figure to see if plotting with multiple figures initialized is
98+
# possible
9499
fig = Makie.Figure()
100+
fig2 = Makie.Figure()
95101
ClimaAnalysis.Visualize.line_plot1D!(fig, var1D)
96102
output_name = joinpath(tmp_dir, "test1D.png")
97103
Makie.save(output_name, fig)

0 commit comments

Comments
 (0)