From 86a78b0d459d3635b24010fc894a3cf643f1f4d4 Mon Sep 17 00:00:00 2001 From: Morgan Williams Date: Fri, 17 May 2024 11:29:08 +1000 Subject: [PATCH] Bugfix - hexbin density plots ymin ymax reversal --- pyrolite/plot/density/__init__.py | 23 ++++++++++++----------- pyrolite/plot/density/grid.py | 7 +++++++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/pyrolite/plot/density/__init__.py b/pyrolite/plot/density/__init__.py index 8b244f32..ac9a0974 100644 --- a/pyrolite/plot/density/__init__.py +++ b/pyrolite/plot/density/__init__.py @@ -1,6 +1,7 @@ """ Kernel desnity estimation plots for geochemical data. """ + import copy import matplotlib.pyplot as plt @@ -38,7 +39,7 @@ def density( shading="auto", vmin=0.0, colorbar=False, - **kwargs + **kwargs, ): """ Creates diagramatic representation of data density and/or frequency for either @@ -159,7 +160,7 @@ def density( logx=logx, logy=logy, extent=extent, - **subkwargs(kwargs, DensityGrid) + **subkwargs(kwargs, DensityGrid), ) if mode == "hexbin": # extent values are exponents (i.e. 3 -> 10**3) @@ -171,7 +172,7 @@ def density( extent=grid.get_hex_extent(), xscale=["linear", "log"][logx], yscale=["linear", "log"][logy], - **subkwargs(kwargs, ax.hexbin) + **subkwargs(kwargs, ax.hexbin), ) elif mode == "hist2d": @@ -182,7 +183,7 @@ def density( range=grid.get_range(), cmap=cmap, cmin=[0, 1][vmin > 0], - **subkwargs(kwargs, ax.hist2d) + **subkwargs(kwargs, ax.hist2d), ) mappable = im @@ -192,7 +193,7 @@ def density( xtransform=[lambda x: x, np.log][logx], ytransform=[lambda y: y, np.log][logy], mode="edges", - **subkwargs(kwargs, grid.kdefrom) + **subkwargs(kwargs, grid.kdefrom), ) if percentiles: # 98th percentile @@ -210,7 +211,7 @@ def density( cmap=cmap, vmin=vmin, shading=shading, - **subkwargs(kwargs, pcolor) + **subkwargs(kwargs, pcolor), ) mappable.set_edgecolor(background_color) mappable.set_linestyle("None") @@ -225,7 +226,7 @@ def density( percentiles=percentiles, cmap=cmap, vmin=vmin, - **kwargs + **kwargs, ) if relim and (extent is not None): ax.axis(extent) @@ -256,7 +257,7 @@ def density( cmap=cmap, vmin=vmin, shading=shading, - **subkwargs(kwargs, pcolor) + **subkwargs(kwargs, pcolor), ) mappable = tri_poly_collection @@ -269,7 +270,7 @@ def density( percentiles=percentiles, cmap=cmap, vmin=vmin, - **kwargs + **kwargs, ) ax.set_aspect("equal") else: @@ -292,7 +293,7 @@ def _add_contours( cmap=DEFAULT_CONT_COLORMAP, vmin=0.0, extent=None, - **kwargs + **kwargs, ): """ Add density-based contours to a plot. @@ -310,7 +311,7 @@ def _add_contours( percentiles=levels, extent=extent, cmap=cmap, - **kwargs + **kwargs, ) mappable = _cs else: diff --git a/pyrolite/plot/density/grid.py b/pyrolite/plot/density/grid.py index 118f7352..7edcfaa2 100644 --- a/pyrolite/plot/density/grid.py +++ b/pyrolite/plot/density/grid.py @@ -46,6 +46,13 @@ def __init__( self.xmin, self.xmax, self.ymin, self.ymax = self.extent_from_xy(x, y) else: self.xmin, self.xmax, self.ymin, self.ymax = extent + # validation + self.xmin, self.xmax = min([self.xmin, self.xmax]), max( + [self.xmin, self.xmax] + ) + self.ymin, self.ymax = min([self.ymin, self.ymax]), max( + [self.ymin, self.ymax] + ) self.xstep = self.get_xstep() self.ystep = self.get_ystep()