Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aa2545f

Browse filesBrowse files
timhoffmjklymak
andcommitted
Improve hexbin() documentation
- See-also-link between hexbin() and hist2d() - More compact example code notation - Better example Introduction Co-authored-by: Jody Klymak <jklymak@gmail.com>
1 parent 63261cc commit aa2545f
Copy full SHA for aa2545f

File tree

Expand file treeCollapse file tree

2 files changed

+26
-31
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+26
-31
lines changed

‎examples/statistics/hexbin_demo.py

Copy file name to clipboardExpand all lines: examples/statistics/hexbin_demo.py
+20-30Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
"""
2-
===========
3-
Hexbin Demo
4-
===========
2+
=====================
3+
Hexagonal binned plot
4+
=====================
55
6-
Plotting hexbins with Matplotlib.
7-
8-
Hexbin is an axes method or pyplot function that is essentially
9-
a pcolor of a 2D histogram with hexagonal cells. It can be
10-
much more informative than a scatter plot. In the first plot
11-
below, try substituting 'scatter' for 'hexbin'.
6+
`~.Axes.hexbin` is a 2D histogram plot, in which the bins are hexagons and
7+
the color represents the number of data points within each bin.
128
"""
139

1410
import numpy as np
@@ -17,29 +13,23 @@
1713
# Fixing random state for reproducibility
1814
np.random.seed(19680801)
1915

20-
n = 100000
16+
n = 100_000
2117
x = np.random.standard_normal(n)
2218
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n)
23-
xmin = x.min()
24-
xmax = x.max()
25-
ymin = y.min()
26-
ymax = y.max()
27-
28-
fig, axs = plt.subplots(ncols=2, sharey=True, figsize=(7, 4))
29-
fig.subplots_adjust(hspace=0.5, left=0.07, right=0.93)
30-
ax = axs[0]
31-
hb = ax.hexbin(x, y, gridsize=50, cmap='inferno')
32-
ax.set(xlim=(xmin, xmax), ylim=(ymin, ymax))
33-
ax.set_title("Hexagon binning")
34-
cb = fig.colorbar(hb, ax=ax)
35-
cb.set_label('counts')
36-
37-
ax = axs[1]
38-
hb = ax.hexbin(x, y, gridsize=50, bins='log', cmap='inferno')
39-
ax.set(xlim=(xmin, xmax), ylim=(ymin, ymax))
40-
ax.set_title("With a log color scale")
41-
cb = fig.colorbar(hb, ax=ax)
42-
cb.set_label('log10(N)')
19+
xlim = x.min(), x.max()
20+
ylim = y.min(), y.max()
21+
22+
fig, (ax0, ax1) = plt.subplots(ncols=2, sharey=True, figsize=(9, 4))
23+
24+
hb = ax0.hexbin(x, y, gridsize=50, cmap='inferno')
25+
ax0.set(xlim=xlim, ylim=ylim)
26+
ax0.set_title("Hexagon binning")
27+
cb = fig.colorbar(hb, ax=ax0, label='counts')
28+
29+
hb = ax1.hexbin(x, y, gridsize=50, bins='log', cmap='inferno')
30+
ax1.set(xlim=xlim, ylim=ylim)
31+
ax1.set_title("With a log color scale")
32+
cb = fig.colorbar(hb, ax=ax1, label='log10(N)')
4333

4434
plt.show()
4535

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4755,6 +4755,9 @@ def reduce_C_function(C: array) -> float
47554755
47564756
%(PolyCollection:kwdoc)s
47574757
4758+
See Also
4759+
--------
4760+
hist2d : 2D histogram rectangular bins
47584761
"""
47594762
self._process_unit_info([("x", x), ("y", y)], kwargs, convert=False)
47604763

@@ -6650,7 +6653,8 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
66506653
66516654
See Also
66526655
--------
6653-
hist2d : 2D histograms
6656+
hist2d : 2D histogram with rectangular bins
6657+
hexbin : 2D histogram with hexagonal bins
66546658
66556659
Notes
66566660
-----
@@ -7093,6 +7097,7 @@ def hist2d(self, x, y, bins=10, range=None, density=False, weights=None,
70937097
See Also
70947098
--------
70957099
hist : 1D histogram plotting
7100+
hexbin : 2D histogram with hexagonal bins
70967101
70977102
Notes
70987103
-----

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.