Multiple Subplots

In the case of having multiple subplots, you can initialize one of the mw-plot class instances to utilize transform() method to transform one or more subplots.

Tranform a single subplot

 1import pylab as plt
 2from mw_plot import MWPlot
 3from astropy import units as  u
 4
 5# setup a mw-plot instance of bird's eyes view of the disc
 6mw1 = MWPlot(radius=20 * u.kpc, center=(0, 0)*u.kpc, unit=u.kpc, coord='galactocentric', rot90=2, grayscale=False, annotation=False)
 7
 8# setup subplots with matplotlib
 9fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 7.5))
10
11# transform the second subplot with mw-plot
12mw1.transform(ax2)
13
14# you can plot something on top of the transformed subplot
15ax2.scatter(8, 0, c='r', s=100)
16
17# plot something in the first subplot
18ax1.plot([0, 1], [0, 1])
19ax1.plot([0, 1], [1, 0])

(Source code, png, pdf)

_images/matplotlib_multi-1.png

Tranform multiple subplots

 1import pylab as plt
 2from mw_plot import MWPlot
 3from astropy import units as  u
 4
 5# setup a mw-plot instance of bird's eyes view of the disc
 6mw1 = MWPlot(radius=20 * u.kpc, center=(0, 0)*u.kpc, unit=u.kpc, coord='galactocentric', rot90=2, grayscale=False, annotation=False)
 7
 8# setup subplots with matplotlib
 9fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 7.5))
10
11# transform the whole figure with mw-plot
12# mw1.transform(fig) will have the same effect
13mw1.transform([ax1, ax2])
14
15# you can plot something on top of the transformed subplot
16ax2.scatter(8, 0, c='r', s=100)
17
18# plot something in the first subplot
19ax1.plot([20, -20], [20, -20])
20ax1.plot([20, -20], [-20, 20])

(Source code, png, pdf)

_images/matplotlib_multi-2.png

Tranform subplots with different style

Not only you can transform with one style, you can do multiple style too

 1import pylab as plt
 2from mw_plot import MWPlot, MWSkyMap
 3from astropy import units as  u
 4
 5# setup a mw-plot instance of bird's eyes view of the disc
 6mw1 = MWPlot(radius=20 * u.kpc, center=(0, 0)*u.kpc, unit=u.kpc, coord='galactocentric', rot90=2, grayscale=False, annotation=False)
 7mw2 = MWPlot(radius=20 * u.kpc, center=(0, 0)*u.kpc, unit=u.kpc, coord='galactocentric', rot90=2, grayscale=True, annotation=False)
 8mw3 = MWSkyMap()
 9
10# setup subplots with matplotlib
11fig = plt.figure(figsize=(15, 15))
12ax1 = fig.add_subplot(221)
13ax2 = fig.add_subplot(222)
14ax3 = fig.add_subplot(212)
15
16# transform the subplots with different style
17mw1.transform(ax1)
18mw2.transform(ax2)
19mw3.transform(ax3)
20
21fig.tight_layout()

(Source code, png, pdf)

_images/matplotlib_multi-3.png

Tranform all subplots

You can quickly transform all subplots in a figure

 1import pylab as plt
 2from mw_plot import MWPlot
 3from astropy import units as  u
 4
 5# setup a mw-plot instance of bird's eyes view of the disc
 6mw1 = MWPlot(radius=20 * u.kpc, center=(0, 0)*u.kpc, unit=u.kpc, coord='galactocentric', grayscale=False, annotation=False)
 7
 8# setup subplots with matplotlib
 9fig, (ax_top, ax_bottom) = plt.subplots(2, 4, figsize=(20, 10))
10
11# transform the whole figure with mw-plot
12# mw1.transform([ax1, ax2]) will have the same effect
13mw1.transform(fig)

(Source code, png, pdf)

_images/matplotlib_multi-4.png