Skip to content

Commit

Permalink
Added optional colorscale on DC plots. Fixed DC percentile color clip.
Browse files Browse the repository at this point in the history
  • Loading branch information
thurinj committed Nov 21, 2024
1 parent 80a5266 commit 59a5967
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions mtuq/graphics/uq/_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ def _plot_dc_matplotlib(filename, coords,
vals = np.append(np.append(values_sigma_kappa.ravel(), values_sigma_kappa.ravel()),(values_sigma_h.ravel()))
# Plot data
# Use the percentile method to filter out outliers (Will alway clip the 10% greater values)
vmin, vmax = np.nanpercentile(vals, [0,75])
vmin, vmax = np.nanpercentile(vals, clip_interval)

# plot surfaces
_pcolor(axes[0][0], coords['h'], coords['kappa'], values_h_kappa, colormap, vmin=vmin, vmax=vmax)
im0 = _pcolor(axes[0][0], coords['h'], coords['kappa'], values_h_kappa, colormap, vmin=vmin, vmax=vmax)

_pcolor(axes[0][1], coords['sigma'], coords['kappa'], values_sigma_kappa, colormap, vmin=vmin, vmax=vmax)

Expand All @@ -322,7 +322,23 @@ def _plot_dc_matplotlib(filename, coords,

_set_dc_labels(axes, fontsize=fontsize)

pyplot.savefig(filename)
if plot_colorbar:
cbar_ax = fig.add_axes([0.91, 0.13, 0.0125, 0.27]) # [left, bottom, width, height]
cb = pyplot.colorbar(im0, cax=cbar_ax, orientation='vertical')
formatter = ticker.ScalarFormatter()
formatter.set_powerlimits((-2, 2)) # Avoid scientific notation between 10^-2 and 10^2
cb.ax.yaxis.set_major_formatter(formatter)
if 'colorbar_label' in kwargs:
cb.set_label(kwargs['colorbar_label'])
else:
cb.set_label('l2-misfit')


# Set the title if provided
if title:
fig.suptitle(title, fontsize=fontsize + 2)

pyplot.savefig(filename, dpi=300)
pyplot.close()


Expand Down Expand Up @@ -627,6 +643,9 @@ def _pcolor(axis, x, y, values, colormap, **kwargs):
except:
axis.pcolor(x, y, values, cmap=colormap, **kwargs)

# Return a mappable object
return axis.collections[0]


def _set_dc_labels(axes, **kwargs):

Expand Down

0 comments on commit 59a5967

Please sign in to comment.