Skip to content

Instantly share code, notes, and snippets.

@TAJD
Last active November 2, 2017 14:38
Show Gist options
  • Save TAJD/dd3285a619183df5551e3b922f990c0e to your computer and use it in GitHub Desktop.
Save TAJD/dd3285a619183df5551e3b922f990c0e to your computer and use it in GitHub Desktop.
Specifying the different levels to plot in a python plot.
"""Specifying the different levels to plot in a python contour plot."""
import numpy as np
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1,2)
x = np.linspace(0, 1, 100)
X, Y = np.meshgrid(x, x)
Z = np.sin(X)*np.sin(Y)
levels = np.linspace(-1, 1, 40)
zdata = np.sin(8*X)*np.sin(8*Y)
cs = axs[0].contourf(X, Y, zdata, levels=levels)
fig.colorbar(cs, ax=axs[0], format="%.2f")
cs = axs[1].contourf(X, Y, zdata, levels=[-1,0,1])
fig.colorbar(cs, ax=axs[1])
fig.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment