From 7e3ecb328f6236f8a7e0ea0b251868907b8e3478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Fuhrmann?= Date: Tue, 27 Jun 2023 18:12:34 +0200 Subject: [PATCH] pyplot: fix window size outside of pluto, limits for 1D plots --- Project.toml | 2 +- src/makie.jl | 32 +++++++++++++++++++++----------- src/pyplot.jl | 26 ++++++++++++++++++-------- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/Project.toml b/Project.toml index cb0c370..3eb9d71 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GridVisualize" uuid = "5eed8a63-0fb0-45eb-886d-8d5a387d12b8" authors = ["Juergen Fuhrmann "] -version = "1.1.2" +version = "1.1.3" [deps] ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4" diff --git a/src/makie.jl b/src/makie.jl index 86fbc63..2ffacca 100644 --- a/src/makie.jl +++ b/src/makie.jl @@ -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 @@ -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] diff --git a/src/pyplot.jl b/src/pyplot.jl index a69e404..053cc39 100644 --- a/src/pyplot.jl +++ b/src/pyplot.jl @@ -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] @@ -382,14 +386,11 @@ 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...) @@ -397,10 +398,19 @@ function scalarplot!(ctx, TP::Type{PyPlotType}, ::Type{Val{1}}, grids, parentgri 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