Figures with Multiple Panels


In [1]:
import numpy
from matplotlib import pyplot
%matplotlib inline

###  initialize the figure
fig, axs = pyplot.subplots(nrows=1, ncols=2, figsize=(9,4))

t1 = axs[0].text(0.5, 0.5, 'Hello', size=20)
t2 = axs[1].text(0.5, 0.5, 'World', size=20)



Sharing Axes (is caring)


In [2]:
xdata1 = numpy.arange(40, 60, 1)
xdata2 = numpy.arange(30, 70, 2)
ydata = numpy.random.randn(20)

fig, (ax1, ax2) = pyplot.subplots(nrows=2, ncols=1, sharex=True)

ax1.plot(xdata1, ydata, marker='o', color='cyan')
ax2.plot(xdata2, ydata, marker='s', color='magenta')


Out[2]:
[<matplotlib.lines.Line2D at 0x110cecfd0>]

Custom Panels


In [3]:
fig = pyplot.figure(figsize=(6,5))

ax1 = pyplot.subplot2grid((3, 3), (0, 0), colspan=3)
ax2 = pyplot.subplot2grid((3, 3), (1, 0), rowspan=2)
ax3 = pyplot.subplot2grid((3, 3), (1, 1), rowspan=2, colspan=2)

t1 = ax1.text(0.5, 0.5, 'first', size=18)
t2 = ax2.text(0.5, 0.5, 'second', size=18, horizontalalignment='center')
t3 = ax3.text(0.5, 0.5, 'third', size=18)



Spacing of Panels


In [4]:
fig = pyplot.figure(figsize=(6,5))

ax1 = pyplot.subplot2grid((3, 3), (0, 0), colspan=3, zorder=1)
ax2 = pyplot.subplot2grid((3, 3), (1, 0), rowspan=2, zorder=3)
ax3 = pyplot.subplot2grid((3, 3), (1, 1), rowspan=2, colspan=2, zorder=2)

t1 = ax1.text(0.5, 0.5, 'first', size=18)
t2 = ax2.text(0.5, 0.5, 'second', size=18, horizontalalignment='center')
t3 = ax3.text(0.5, 0.5, 'third', size=18)

fig.subplots_adjust(hspace=0.5, wspace=0.5)



In [ ]: