Skip to content

Instantly share code, notes, and snippets.

View rcomer's full-sized avatar
🐇

Ruth Comer rcomer

🐇
View GitHub Profile
@rcomer
rcomer / contourf_legend.py
Last active January 19, 2024 21:13
Make a single legend entry for a contourf plot by stacking proxy artists together. Proposed solution for https://stackoverflow.com/questions/77842076
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
import numpy as np
x, y = np.meshgrid(np.arange(10),np.arange(10))
z = np.sqrt(x**2 + y**2)
fig, ax = plt.subplots()
cs = ax.contourf(x,y,z,levels=[2,3,4,6])
@rcomer
rcomer / test_multiplots.py
Last active June 25, 2022 16:55
Sketch of how Iris gallery tests might work with `pytest-mpl`. I guess we'd need multiple classes to handle examples with different numbers of figures (at time of writing all examples have one, two or four figures). See also https://stackoverflow.com/questions/72659961/generate-multiple-tests-based-on-a-functions-output.
import warnings
import matplotlib.pyplot as plt
import pytest
def my_plots():
plt.figure()
plt.plot([0, 1])
plt.show()
@rcomer
rcomer / coord_comparison.py
Last active August 10, 2018 14:24
Print the differences between two Iris coordinates
from __future__ import print_function
import numpy as np
def coord_diffs(coord1, coord2):
"""
Print which aspects of two coords do not match.
"""
for attr in ['standard_name', 'long_name', 'var_name', 'units',