From f7ed1ae7c2aab9dc8c52232c4689ccf13c6aebe5 Mon Sep 17 00:00:00 2001 From: Mihai Babiac Date: Tue, 3 Nov 2020 00:18:44 +0100 Subject: [PATCH 1/2] Add warning when hexbin extent values are in wrong order --- lib/matplotlib/axes/_axes.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 01252b2bfa15..34b2e74c3463 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4603,6 +4603,9 @@ def reduce_C_function(C: array) -> float y = np.log10(y) if extent is not None: xmin, xmax, ymin, ymax = extent + if xmin > xmax or ymin > ymax: + raise ValueError("extent values in wrong order. Should be" + " (left, right, bottom, top)") else: xmin, xmax = (np.min(x), np.max(x)) if len(x) else (0, 1) ymin, ymax = (np.min(y), np.max(y)) if len(y) else (0, 1) From 54bf126860e3c6f46f6b3763cd32f59b7d224c79 Mon Sep 17 00:00:00 2001 From: Mihai Babiac Date: Tue, 3 Nov 2020 00:19:45 +0100 Subject: [PATCH 2/2] Improve bins for hexbin marginals --- lib/matplotlib/axes/_axes.py | 48 +++++++++++++++++------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 34b2e74c3463..08a2f75efded 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4786,32 +4786,28 @@ def reduce_C_function(C: array) -> float if not marginals: return collection - if C is None: - C = np.ones(len(x)) - def coarse_bin(x, y, coarse): - ind = coarse.searchsorted(x).clip(0, len(coarse) - 1) - mus = np.zeros(len(coarse)) - for i in range(len(coarse)): - yi = y[ind == i] - if len(yi) > 0: - mu = reduce_C_function(yi) - else: - mu = np.nan - mus[i] = mu + ind = coarse.searchsorted(x) + mus = np.zeros(len(coarse)-1) + if y is None: + for i in range(len(coarse)-1): + mus[i] = np.sum(ind == i+1) + else: + for i in range(len(coarse)-1): + yi = y[ind == i+1] + if len(yi) > 0: + mus[i] = reduce_C_function(yi) + mus[mus == 0] = np.nan return mus - coarse = np.linspace(xmin, xmax, gridsize) + coarse = np.linspace(xmin, xmax, nx+1) xcoarse = coarse_bin(xorig, C, coarse) valid = ~np.isnan(xcoarse) verts, values = [], [] for i, val in enumerate(xcoarse): thismin = coarse[i] - if i < len(coarse) - 1: - thismax = coarse[i + 1] - else: - thismax = thismin + np.diff(coarse)[-1] + thismax = coarse[i + 1] if not valid[i]: continue @@ -4834,27 +4830,29 @@ def coarse_bin(x, y, coarse): hbar.update(kwargs) self.add_collection(hbar, autolim=False) - coarse = np.linspace(ymin, ymax, gridsize) + coarse = np.linspace(ymin, ymax, ny+1) + ycoarse = coarse_bin(yorig, C, coarse) valid = ~np.isnan(ycoarse) verts, values = [], [] for i, val in enumerate(ycoarse): thismin = coarse[i] - if i < len(coarse) - 1: - thismax = coarse[i + 1] - else: - thismax = thismin + np.diff(coarse)[-1] + thismax = coarse[i + 1] + if not valid[i]: continue - verts.append([(0, thismin), (0.0, thismax), - (0.05, thismax), (0.05, thismin)]) + + verts.append([(0, thismin), + (0, thismax), + (0.05, thismax), + (0.05, thismin)]) values.append(val) values = np.array(values) - trans = self.get_yaxis_transform(which='grid') vbar = mcoll.PolyCollection(verts, transform=trans, edgecolors='face') + vbar.set_array(values) vbar.set_cmap(cmap) vbar.set_norm(norm) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy