Skip to content

Commit

Permalink
ENH: add aspect keyword for pg.show and cleanup a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Günther committed Dec 18, 2023
1 parent 48ce372 commit 03ccc3b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
17 changes: 5 additions & 12 deletions pygimli/viewer/mpl/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def updateColorBar(cbar, gci=None, cMin=None, cMax=None, cMap=None,
cbar.set_label(label)
else:
setCbarLevels(mappable, cMin, cMax, nLevs, levels)


return cbar

Expand Down Expand Up @@ -283,7 +283,6 @@ def createColorBar(gci, orientation='horizontal', size=0.2, pad=None,

ax = kwargs.pop('ax', None)
if ax is None:

try:
if hasattr(gci, 'axes'):
ax = gci.axes
Expand All @@ -295,12 +294,6 @@ def createColorBar(gci, orientation='horizontal', size=0.2, pad=None,
pass

cbar = None
# if hasattr(ax, '__cBar__'):
# # update colorbar is broken and will not work as supposed so we need
# # to remove them for now
# #ax.__cBar__.remove()
# # delattr(ax, '__cBar__')
# pass

if hasattr(ax, '__cBar__'):
cbar = ax.__cBar__
Expand Down Expand Up @@ -331,7 +324,7 @@ def createColorBar(gci, orientation='horizontal', size=0.2, pad=None,
updateColorBar(cbar, **kwargs)
else:
updateColorBar(None, gci=gci, **kwargs)


return cbar

Expand Down Expand Up @@ -417,10 +410,10 @@ def setCbarLevels(cbar, cMin=None, cMax=None, nLevs=5, levels=None):

if cMin is None:
cMin = mappable.get_clim()[0]

if cMax is None:
cMax = mappable.get_clim()[1]

if cMin == cMax:

cMin *= 0.999
Expand Down Expand Up @@ -464,7 +457,7 @@ def setCbarLevels(cbar, cMin=None, cMax=None, nLevs=5, levels=None):
try:
cbar.ax.figure.draw_without_rendering()
#cbar._draw_all() # work but dunno how long this will exists
except:
except:
cbar.draw_all() # removed by mpl-3.8

# necessary since mpl 3.0
Expand Down
14 changes: 2 additions & 12 deletions pygimli/viewer/showmesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ def showMesh(mesh, data=None, block=False, colorBar=None,
Useful to combine multiple plots into one figure.
savefig: string
Filename for a direct save to disc.
The matplotlib pdf-output is a little bit big so we try
an epstopdf if the .eps suffix is found in savefig
showMesh: bool [False]
Shows the mesh itself additional.
showBoundary: bool [None]
Expand Down Expand Up @@ -466,7 +464,7 @@ def _drawField(ax, mesh, data, kwargs):

if fitView is not False:
ax.autoscale(enable=True, axis='both', tight=True)
ax.set_aspect('equal')
ax.set_aspect(kwargs.pop('aspect', 'equal'))

cBar = None

Expand Down Expand Up @@ -532,20 +530,12 @@ def _drawField(ax, mesh, data, kwargs):
pg.viewer.mpl.hold(val=lastHoldStatus)

if savefig:
print('saving: ' + savefig + ' ...')

print('saving: ' + savefig + ' ...', end="")
if '.' not in savefig:
savefig += '.pdf'

ax.figure.savefig(savefig, bbox_inches='tight')
# rc params savefig.format=pdf

if '.eps' in savefig:
try:
print("trying eps2pdf ... ")
os.system('epstopdf ' + savefig)
except BaseException:
pass
print('.. done')

return ax, cBar
Expand Down

0 comments on commit 03ccc3b

Please sign in to comment.