Skip to content

Instantly share code, notes, and snippets.

@tkf
Created October 2, 2009 05:18
Show Gist options
  • Save tkf/199485 to your computer and use it in GitHub Desktop.
Save tkf/199485 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import matplotlib.pyplot as plt
import numpy
class SublotsForReuse(object):
def __init__(self, *args, **kwds):
self.fig = plt.figure(*args, **kwds)
self.ax = []
def add_axes(self, *args, **kwds):
a = self.fig.add_axes(*args, **kwds)
self.ax.append(a)
return a
def cla_all(self):
for a in self.ax:
a.cla()
def clf(self):
self.fig.clf()
self.ax = []
sfr = SublotsForReuse()
left, width = 0.1, 0.8
rect1 = [left, 0.7, width, 0.2]
rect2 = [left, 0.3, width, 0.4]
rect3 = [left, 0.1, width, 0.2]
ax1 = sfr.add_axes(rect1)
ax2 = sfr.add_axes(rect2, sharex=ax1)
ax3 = sfr.add_axes(rect3, sharex=ax1)
t = numpy.arange(0.0, 2.0, 0.01)
s1 = numpy.sin(2*pi*t)
s2 = numpy.exp(-t)
s3 = s1*s2
sfr.cla_all()
ax1.plot(t,s1)
ax2.plot(t,s2)
ax3.plot(t,s3)
sfr.fig.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment