You are reading documentation for the unreleased version of Matplotlib. Try searching for the released version of this page instead?
Applications are open for the 2018 John Hunter Matplotlib Summer Fellowship. Apply now!
Version 2.2.2.post1766+g38476fd23
Fork me on GitHub

Related Topics

Frontpage contour exampleΒΆ

This example reproduces the frontpage contour example.

import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm

extent = (-3, 3, -3, 3)

delta = 0.5
x = np.arange(-3.0, 4.001, delta)
y = np.arange(-4.0, 3.001, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = Z1 - Z2

norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max())

fig, ax = plt.subplots()
cset1 = ax.contourf(
    X, Y, Z, 40,
ax.set_xlim(-2, 2)
ax.set_ylim(-2, 2)
fig.savefig("contour_frontpage.png", dpi=25)  # results in 160x120 px image

Keywords: matplotlib code example, codex, python plot, pyplot Gallery generated by Sphinx-Gallery