Skip to content

Commit

Permalink
Bugfix - hexbin density plots ymin ymax reversal
Browse files Browse the repository at this point in the history
  • Loading branch information
morganjwilliams committed May 17, 2024
1 parent 6e3e86c commit 86a78b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pyrolite/plot/density/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Kernel desnity estimation plots for geochemical data.
"""

import copy

import matplotlib.pyplot as plt
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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":
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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")
Expand All @@ -225,7 +226,7 @@ def density(
percentiles=percentiles,
cmap=cmap,
vmin=vmin,
**kwargs
**kwargs,
)
if relim and (extent is not None):
ax.axis(extent)
Expand Down Expand Up @@ -256,7 +257,7 @@ def density(
cmap=cmap,
vmin=vmin,
shading=shading,
**subkwargs(kwargs, pcolor)
**subkwargs(kwargs, pcolor),
)

mappable = tri_poly_collection
Expand All @@ -269,7 +270,7 @@ def density(
percentiles=percentiles,
cmap=cmap,
vmin=vmin,
**kwargs
**kwargs,
)
ax.set_aspect("equal")
else:
Expand All @@ -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.
Expand All @@ -310,7 +311,7 @@ def _add_contours(
percentiles=levels,
extent=extent,
cmap=cmap,
**kwargs
**kwargs,
)
mappable = _cs
else:
Expand Down
7 changes: 7 additions & 0 deletions pyrolite/plot/density/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 86a78b0

Please sign in to comment.