Skip to content

Instantly share code, notes, and snippets.

@joferkington
Created December 2, 2014 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joferkington/3ca60b0b05b7310f09e8 to your computer and use it in GitHub Desktop.
Save joferkington/3ca60b0b05b7310f09e8 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
x, y = np.mgrid[:10, :10]
z = np.hypot(x - 4.5, y - 4.5)
#-- Create two masked arrays, one with the upper region and one with the lower.
z1 = np.ma.masked_where(y > 5, z)
# If we just invert the previous masked region, we'll have a gap. There are
# better ways to do this, but for simple cases, we can just ensure a one-pixel
# region of overlap between the two by using a different value.
z2 = np.ma.masked_where(y < 4, z)
# We need to fix the levels, otherwise different contour values might be chosen
# for each region
levels = range(6)
fig, ax = plt.subplots()
ax.contour(x, y, z1, levels=levels)
ax.contour(x, y, z2, levels=levels, linestyles='dashed')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment