Skip to content

Instantly share code, notes, and snippets.

View ImportanceOfBeingErnest's full-sized avatar

Elan Ernest ImportanceOfBeingErnest

  • Germany
View GitHub Profile
@ImportanceOfBeingErnest
ImportanceOfBeingErnest / gist:5e61287a6f63deb3a9f3da36c432124a
Created March 13, 2020 14:27
Code for adding a second legend without instantiating `legend.Legend`.
import numpy as np
import matplotlib.pyplot as plt
lines = []
styles = ['-', '--', '-.', ':']
x = np.linspace(0, 10, 1000)
fig, ax = plt.subplots()
for i in range(4):
lines += ax.plot(x, np.sin(x - i * np.pi / 2),
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from matplotlib.widgets import Button
def on_click(event):
print("hey")
fig = plt.figure(constrained_layout=True)
gs = gridspec.GridSpec(2, 1, height_ratios=[14, 1], figure=fig)
@ImportanceOfBeingErnest
ImportanceOfBeingErnest / pillowriter.py
Created November 6, 2018 19:05
mwe for saving an animation with pillow
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
numHeatMaps = 2
measurements = [[(i + 1, j + 1, k * 100 + i * 10 + j) for i in range(5) for j in range(5)] for k in range(numHeatMaps)]
fig, ax = plt.subplots()
im = ax.imshow(measurements[0])
def update(i):
@ImportanceOfBeingErnest
ImportanceOfBeingErnest / compare_mpl_contour.py
Last active February 5, 2017 16:37
Compare matplotlib contour and tricontour for randomized grid
# Code was written in an answer to this Stackoverflow question:
# http://stackoverflow.com/questions/42045921/why-does-pyplot-contour-require-z-to-be-a-2d-array
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
import numpy as np
fig, (ax, ax2) = plt.subplots(ncols=2, figsize=(6,3.7) )
plt.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.82, wspace=0.07)
def setup():