Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
- wrong "ghost points" for boundary legend in pyplot
- don't round automatic colorlevels - we want to see real min/max
- fix constant plotting for GLMakie, PyPlot
  • Loading branch information
j-fu committed Jan 4, 2022
1 parent 460a23b commit 85da974
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 26 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 = "0.4.4"
version = "0.4.5"

[deps]
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Expand Down
4 changes: 3 additions & 1 deletion src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,9 @@ function isolevels(ctx,func)
end


map(t->round(t,sigdigits=4),levels),crange,map(t->round(t,sigdigits=4),colorbarticks)
# map(t->round(t,sigdigits=4),levels),crange,map(t->round(t,sigdigits=4),colorbarticks)
levels,crange,colorbarticks

end


Expand Down
44 changes: 26 additions & 18 deletions src/makie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -430,24 +430,6 @@ end
#######################################################################################
# 2D grid

"""
makescene2d(ctx)
Complete scene with title and status line showing interaction state.
This uses a gridlayout and its protrusion capabilities.
"""
function makescene2d(ctx,key)
Makie=ctx[:Plotter]
GL=Makie.GridLayout(ctx[:figure])
GL[1,1]=ctx[:scene]
if ctx[:colorbar]==:vertical
GL[1,2]=Makie.Colorbar(ctx[:figure],ctx[key],width=10,ticks=ctx[:cbarticks], textsize=0.5*ctx[:fontsize],ticklabelsize=0.5*ctx[:fontsize])
elseif ctx[:colorbar]==:horizontal
GL[2,1]=Makie.Colorbar(ctx[:figure],ctx[key],height=10,ticks=ctx[:cbarticks],textsize=0.5*ctx[:fontsize],ticklabelsize=0.5*ctx[:fontsize],vertical=false)
end
GL
end

function makescene2d_grid(ctx)
Makie=ctx[:Plotter]
GL=Makie.GridLayout(ctx[:figure])
Expand Down Expand Up @@ -527,6 +509,25 @@ function gridplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}},grid)
end


"""
makescene2d(ctx)
Complete scene with title and status line showing interaction state.
This uses a gridlayout and its protrusion capabilities.
"""
function makescene2d(ctx,key)
Makie=ctx[:Plotter]
GL=Makie.GridLayout(ctx[:figure])
GL[1,1]=ctx[:scene]

if ctx[:colorbar]==:vertical
GL[1,2]=Makie.Colorbar(ctx[:figure],ctx[key],width=10,ticks=unique(ctx[:cbarticks]), textsize=0.5*ctx[:fontsize],ticklabelsize=0.5*ctx[:fontsize])
elseif ctx[:colorbar]==:horizontal
GL[2,1]=Makie.Colorbar(ctx[:figure],ctx[key],height=10,ticks=ctx[:cbarticks],textsize=0.5*ctx[:fontsize],ticklabelsize=0.5*ctx[:fontsize],vertical=false)
end
GL
end

# 2D function
function scalarplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}},grid, func)
Makie=ctx[:Plotter]
Expand All @@ -548,6 +549,13 @@ function scalarplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}},grid, func)
end

levels,crange,ctx[:cbarticks]=isolevels(ctx,func)
eps=1.0e-1
if crange[1]==crange[2]
crange=(crange[1]-eps,crange[1]+eps)
end




set_plot_data!(ctx,Makie,:contourdata,(g=grid,f=func,e=ctx[:elevation],t=ctx[:title],l=levels,c=crange))

Expand Down
18 changes: 12 additions & 6 deletions src/pyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,12 @@ function gridplot!(ctx, TP::Type{PyPlotType}, ::Type{Val{2}},grid)
if nbfaceregions>0
cmap=bregion_cmap(nbfaceregions)
# see https://gist.github.com/gizmaa/7214002
xc=[coord[:,bfacenodes[1,i]] for i=1:num_sources(bfacenodes)]
yc=[coord[:,bfacenodes[2,i]] for i=1:num_sources(bfacenodes)]
c1=[coord[:,bfacenodes[1,i]] for i=1:num_sources(bfacenodes)]
c2=[coord[:,bfacenodes[2,i]] for i=1:num_sources(bfacenodes)]
rgb=[rgbtuple(cmap[bfaceregions[i]]) for i=1:length(bfaceregions)]
ax.add_collection(PyPlot.matplotlib.collections.LineCollection(collect(zip(xc,yc)),colors=rgb,linewidth=3))
ax.add_collection(PyPlot.matplotlib.collections.LineCollection(collect(zip(c1,c2)),colors=rgb,linewidth=3))
for i=1:nbfaceregions
ax.plot(coord[:,1], coord[:,1],label="$(i)", color=rgbtuple(cmap[i]))
ax.plot(coord[1,1:1], coord[2,1:1],label="$(i)", color=rgbtuple(cmap[i]))
end
end
if ctx[:legend]!=:none
Expand Down Expand Up @@ -458,8 +458,15 @@ function scalarplot!(ctx, TP::Type{PyPlotType}, ::Type{Val{2}},grid, func)
ax.set_title(ctx[:title])

levels,crange,colorbarticks=isolevels(ctx,func)
colorlevels=collect(crange[1]:(crange[2]-crange[1])/(ctx[:colorlevels]-1):crange[2])
eps=1.0e-5
if crange[1]==crange[2]
crange=(crange[1]-eps,crange[1]+eps)
colorlevels=collect(crange[1]:(crange[2]-crange[1])/(1):crange[2])
else
colorlevels=collect(crange[1]:(crange[2]-crange[1])/(ctx[:colorlevels]-1):crange[2])
end


if !haskey(ctx,:grid) || !seemingly_equal(ctx[:grid],grid)
ctx[:grid]=grid
ctx[:tridata]=tridata(grid)
Expand All @@ -473,7 +480,6 @@ function scalarplot!(ctx, TP::Type{PyPlotType}, ::Type{Val{2}},grid, func)
if ctx[:colorbar]==:horizontal
ctx[:cbar]=fig.colorbar(cnt,ax=ax,ticks=colorbarticks,boundaries=colorlevels, orientation="horizontal")
end

if ctx[:colorbar]==:vertical
ctx[:cbar]=fig.colorbar(cnt,ax=ax,ticks=colorbarticks,boundaries=colorlevels, orientation="vertical")
end
Expand Down

2 comments on commit 85da974

@j-fu
Copy link
Member Author

@j-fu j-fu commented on 85da974 Jan 4, 2022

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/51661

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 v0.4.5 -m "<description of version>" 85da974731f19eb4d3f526e2d9a48e2e9b6359e9
git push origin v0.4.5

Please sign in to comment.