Skip to content

Commit

Permalink
pyplot: fix window size outside of pluto, limits for 1D plots
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fu committed Jun 27, 2023
1 parent e5419c3 commit 7e3ecb3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 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.2"
version = "1.1.3"

[deps]
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Expand Down
32 changes: 21 additions & 11 deletions src/makie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -592,23 +592,36 @@ function gridplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grid)
nregions = num_cellregions(grid)

nbregions = num_bfaceregions(grid)

@show "here"
set_plot_data!(ctx, :grid, grid)

if !haskey(ctx, :gridplot)
if !haskey(ctx, :scene)
coord = grid[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])
aspect = nothing
autolimitaspect = nothing
if ctx[:aspect] 1.0
aspect = XMakie.DataAspect()
else
autolimitaspect = ctx[:aspect]
end
ctx[:scene] = XMakie.Axis(
ctx[:figure];
title = ctx[:title],
aspect = makie_aspect,
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 cells with region mark
cmap = region_cmap(nregions)
ctx[:cmap] = cmap
Expand Down Expand Up @@ -760,12 +773,9 @@ 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))

aspect = nothing
autolimitaspect = nothing
if ctx[:aspect] == 1.0
if ctx[:aspect] 1.0
aspect = XMakie.DataAspect()
else
autolimitaspect = ctx[:aspect]
Expand Down
26 changes: 18 additions & 8 deletions src/pyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ function initialize!(p, ::Type{PyPlotType})
PyPlot.PyObject(PyPlot.axes3D)# see https://github.com/JuliaPy/PyPlot.jl/issues/351
if !haskey(p.context, :figure)
res = p.context[:size]
p.context[:figure] = PyPlot.figure(p.context[:fignumber]; dpi = 100)
if !isdefined(Main, :PlutoRunner)
p.context[:figure] = PyPlot.figure(p.context[:fignumber]; dpi = 50)
else
p.context[:figure] = PyPlot.figure(p.context[:fignumber]; dpi = 100)
end
p.context[:figure].set_size_inches(res[1] / 100, res[2] / 100; forward = true)
for ctx in p.subplots
ctx[:figure] = p.context[:figure]
Expand Down Expand Up @@ -382,25 +386,31 @@ end
function scalarplot!(ctx, TP::Type{PyPlotType}, ::Type{Val{1}}, grids, parentgrid, funcs)
PyPlot = ctx[:Plotter]
nfuncs = length(funcs)
if !haskey(ctx, :ax)
ctx[:ax] = ctx[:figure].add_subplot(ctx[:layout]..., ctx[:iplot])
end
if ctx[:clear]
ctx[:ax].cla()

function set_limits_grid_title()
ax=ctx[:ax]
xlimits = ctx[:xlimits]
ylimits = ctx[:limits]
ax = ctx[:ax]

if xlimits[1] < xlimits[2]
ax.set_xlim(xlimits...)
end
if ylimits[1] < ylimits[2]
ax.set_ylim(ylimits...)
end
ax.set_title(ctx[:title])
ax.grid()
end

if !haskey(ctx, :ax)
ctx[:ax] = ctx[:figure].add_subplot(ctx[:layout]..., ctx[:iplot])
set_limits_grid_title()
end
if ctx[:clear]
ctx[:ax].cla()
set_limits_grid_title()
end
ax = ctx[:ax]
ax.set_title(ctx[:title])
fig = ctx[:figure]

pplot = ax.plot
Expand Down

2 comments on commit 7e3ecb3

@j-fu
Copy link
Member Author

@j-fu j-fu commented on 7e3ecb3 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/86358

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.3 -m "<description of version>" 7e3ecb328f6236f8a7e0ea0b251868907b8e3478
git push origin v1.1.3

Please sign in to comment.