Created
January 22, 2020 05:05
-
-
Save will-henney/6982617a9e6bb6d14774338db454122b to your computer and use it in GitHub Desktop.
Demo of contours for Tere
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
#!/usr/bin/env python | |
# coding: utf-8 | |
# In[1]: | |
import numpy as np | |
from matplotlib import pyplot as plt | |
get_ipython().run_line_magic('matplotlib', 'inline') | |
# Generate grid of parameter values (`R_coma` and `L_crit` in Tere's example) | |
# In[2]: | |
X, Y = np.meshgrid( | |
np.linspace(0.0, 0.5), | |
np.linspace(0.0, 0.5) | |
) | |
# Fake data generated on this grid. Not exactly the same as Tere's, but close enough | |
# In[3]: | |
data = 1.0/(1.0 + 0.1*(X**2 + Y**2)) | |
# Now generate the figure with image, labelled contours, and color key. | |
# In[4]: | |
fig, ax = plt.subplots(figsize=(5, 5)) | |
# False color image of data | |
im = ax.imshow(data, | |
extent=[X.min(), X.max(), Y.min(), Y.max()], | |
origin="lower") | |
# Contours of two selected values | |
cs = ax.contour(X, Y, data, [0.97, 0.98], colors="w") | |
# Label the contours | |
ax.clabel(cs, inline=True, fmt="%.2f") | |
ax.set( | |
xlabel=r"$R_\mathrm{coma}$", | |
ylabel=r"$L_\mathrm{crit}$", | |
) | |
# Add a key to the colors | |
fig.colorbar(im, ax=ax, shrink=0.8).set_label("Data") | |
None | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment