From 03ccc3bf5f30fc0d4b2c26bfbad964a238584f9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=BCnther?= Date: Mon, 18 Dec 2023 18:50:08 +0100 Subject: [PATCH] ENH: add aspect keyword for pg.show and cleanup a bit --- pygimli/viewer/mpl/colorbar.py | 17 +++++------------ pygimli/viewer/showmesh.py | 14 ++------------ 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/pygimli/viewer/mpl/colorbar.py b/pygimli/viewer/mpl/colorbar.py index b9c476e6b..42651cd50 100644 --- a/pygimli/viewer/mpl/colorbar.py +++ b/pygimli/viewer/mpl/colorbar.py @@ -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 @@ -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 @@ -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__ @@ -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 @@ -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 @@ -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 diff --git a/pygimli/viewer/showmesh.py b/pygimli/viewer/showmesh.py index a5fdff8f6..2f23c006a 100644 --- a/pygimli/viewer/showmesh.py +++ b/pygimli/viewer/showmesh.py @@ -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] @@ -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 @@ -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