Skip to content

Commit

Permalink
Fix aspect & limits handling for 2D Makie plots
Browse files Browse the repository at this point in the history
Aspect handling now appears to be similar to pyplot.
  • Loading branch information
j-fu committed Jun 27, 2023
1 parent 48acf9f commit e5419c3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 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 <[email protected]>"]
version = "1.1.1"
version = "1.1.2"

[deps]
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Expand Down
2 changes: 1 addition & 1 deletion src/dispatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ function default_plot_kwargs()
:color => Pair((0.0, 0.0, 0.0), "1D plot line color"),
:cellwise => Pair(false, "1D plots cellwise; unmaintained and can be slow)"),
:label => Pair("", "1D plot label"),
:levels => Pair(5, "array of isolevels or number of isolevels for contour plots"),
:levels => Pair(7, "array of isolevels or number of isolevels for contour plots"),
:elevation => Pair(0.0, "2D plot height factor for elevation"),
:colorlevels => Pair(51, "2D/3D contour plot: number of color levels"),
:colormap => Pair(
Expand Down
28 changes: 24 additions & 4 deletions src/makie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -761,23 +761,43 @@ function scalarplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grids, parentgrid
if !haskey(ctx, :contourplot)
if !haskey(ctx, :scene)
coord = parentgrid[Coordinates]
ex = extrema(coord; dims = (2))
data_aspect = (ex[2][2] - ex[2][1]) / (ex[1][2] - ex[1][1])
makie_aspect = 1.0 / (data_aspect * ctx[:aspect])
# ex = extrema(coord; dims = (2))

aspect = nothing
autolimitaspect = nothing
if ctx[:aspect] == 1.0
aspect = XMakie.DataAspect()
else
autolimitaspect = ctx[:aspect]
end
if ctx[:elevation] 0
ctx[:scene] = XMakie.Axis(
ctx[:figure];
title = map(data -> data.t, ctx[:contourdata]),
aspect = makie_aspect,
aspect = aspect,
autolimitaspect = autolimitaspect,
scenekwargs(ctx)...,
)
else
ctx[:scene] = XMakie.Axis3(
ctx[:figure];
title = map(data -> data.t, ctx[:contourdata]),
aspect = aspect,
autolimitaspect = autolimitaspect,
scenekwargs(ctx)...,
)
end

xlimits = ctx[:xlimits]
ylimits = ctx[:ylimits]
if xlimits[1] < xlimits[2]
XMakie.xlims!(ctx[:scene], xlimits...)
end
if ylimits[1] < ylimits[2]
XMakie.ylims!(ctx[:scene], ylimits...)
end


end

# Draw the mesh for the cells
Expand Down

2 comments on commit e5419c3

@j-fu
Copy link
Member Author

@j-fu j-fu commented on e5419c3 Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/86345

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.2 -m "<description of version>" e5419c3f0e6d184ff2ab1dad8c759b62c0d3e77e
git push origin v1.1.2

Please sign in to comment.