MCPcopy Index your code
hub / github.com/plotly/plotly.py / _compute_hexbin

Function _compute_hexbin

plotly/figure_factory/_hexbin_map.py:58–223  ·  view source on GitHub ↗

Computes the aggregation at hexagonal bin level. Also defines the coordinates of the hexagons for plotting. The binning is inspired by matplotlib's implementation. Parameters ---------- x : np.ndarray Array of x values (shape N) y : np.ndarray Array of y

(x, y, x_range, y_range, color, nx, agg_func, min_count)

Source from the content-addressed store, hash-verified

56
57
58def _compute_hexbin(x, y, x_range, y_range, color, nx, agg_func, min_count):
59 """
60 Computes the aggregation at hexagonal bin level.
61 Also defines the coordinates of the hexagons for plotting.
62 The binning is inspired by matplotlib's implementation.
63
64 Parameters
65 ----------
66 x : np.ndarray
67 Array of x values (shape N)
68 y : np.ndarray
69 Array of y values (shape N)
70 x_range : np.ndarray
71 Min and max x (shape 2)
72 y_range : np.ndarray
73 Min and max y (shape 2)
74 color : np.ndarray
75 Metric to aggregate at hexagon level (shape N)
76 nx : int
77 Number of hexagons horizontally
78 agg_func : function
79 Numpy compatible aggregator, this function must take a one-dimensional
80 np.ndarray as input and output a scalar
81 min_count : int
82 Minimum number of points in the hexagon for the hexagon to be displayed
83
84 Returns
85 -------
86 np.ndarray
87 X coordinates of each hexagon (shape M x 6)
88 np.ndarray
89 Y coordinates of each hexagon (shape M x 6)
90 np.ndarray
91 Centers of the hexagons (shape M x 2)
92 np.ndarray
93 Aggregated value in each hexagon (shape M)
94
95 """
96 xmin = x_range.min()
97 xmax = x_range.max()
98 ymin = y_range.min()
99 ymax = y_range.max()
100
101 # In the x-direction, the hexagons exactly cover the region from
102 # xmin to xmax. Need some padding to avoid roundoff errors.
103 padding = 1.0e-9 * (xmax - xmin)
104 xmin -= padding
105 xmax += padding
106
107 Dx = xmax - xmin
108 Dy = ymax - ymin
109 if Dx == 0 and Dy > 0:
110 dx = Dy / nx
111 elif Dx == 0 and Dy == 0:
112 dx, _ = _project_latlon_to_wgs84(1, 1)
113 else:
114 dx = Dx / nx
115 dy = dx * np.sqrt(3)

Callers 1

_compute_wgs84_hexbinFunction · 0.85

Calls 3

_project_latlon_to_wgs84Function · 0.85
minMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected