Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.