Created
December 2, 2014 02:00
-
-
Save joferkington/3ca60b0b05b7310f09e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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