8000 DOC: sphinx-gallery histograms by choldgraf · Pull Request #8245 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

DOC: sphinx-gallery histograms #8245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
combining and updating 2d hist examples
  • Loading branch information
choldgraf committed Mar 8, 2017
commit eba8ab1199c17e298d47a9325a01e3de21eb791c
43 changes: 39 additions & 4 deletions examples/pylab_examples/hist2d_demo.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
"""
=============
2D Histograms
=============

Demonstrates how to plot 2-dimensional histograms.
"""

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LogNorm

###############################################################################
# Plot a 2D histogram
# -------------------
#
# To plot a 2D histogram, one only needs two vectors of the same length,
# corresponding to each axis of the histogram.

# Fixing random state for reproducibility
np.random.seed(19680801)

# Generate a normal distribution, center at x=0 and y=5
x = np.random.randn(100000)
y = .4 * x + np.random.randn(100000) + 5

fig, ax = plt.subplots()
hist = ax.hist2d(x, y)

###############################################################################
# Customizing your histogram
# --------------------------
#
# Customizing a 2D histogram is similar to the 1D case, you can control
# visual components such as the bin size or color normalization

fig, axs = plt.subplots(1, 3, figsize=(15, 5), sharex=True, sharey=True)

# We can increase the number of bins on each axis
axs[0].hist2d(x, y, bins=40)

# As well as define normalization of the colors
axs[1].hist2d(x, y, bins=40, norm=LogNorm())

x = np.random.randn(1000)
y = np.random.randn(1000) + 5
# We can also define custom numbers of bins for each axis
axs[2].hist2d(x, y, bins=(80, 10), norm=LogNorm())

# normal distribution center at x=0 and y=5
plt.hist2d(x, y, bins=40)
plt.show()
15 changes: 0 additions & 15 deletions examples/pylab_examples/hist2d_log_demo.py

This file was deleted.

0