Coverage for python/lsst/sims/catUtils/supernovae/utils.py : 21%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import warnings
3try:
4 import matplotlib.gridspec as gridspec
5 import matplotlib.ticker as ticker
6 import matplotlib.pyplot as plt
7except Exception as e:
8 warnings.warn("matplotlib not imported in %s\n\n" % __file__)
10__all__ = ['settwopanel']
13def settwopanel(height_ratios=[1.0, 0.3],
14 width_ratios=[1., 0.],
15 padding=None,
16 setdifflimits=[0.9, 1.1],
17 setoffset=None,
18 setgrid=[True, True],
19 figsize=None):
20 """
21 returns a figure and axes for a main panel and a lower panel for
22 showing differential information of overplotted quantities in
23 the top panel.
25 Parameters
26 ----------
27 height_ratios: list of floats, optional defaults to [1.0, 0.3]
28 height ratio between the upper and lower panel
29 width_ratios: list of floats, optional defaults to [1.0, 0.0]
30 width ratio between the left and right panel
31 figsize: figure size
32 setgrid: List of bools, optional, defaults to [True, True]
33 whether to set grid on the two panels
34 Returns
35 -------
36 figure object , ax0 (axes for top panel) , and ax1 (axes for lower panel)
38 Examples
39 --------
40 >>> myfig, myax0 , myax1 = settwopanel ( )
41 >>> myax0.plot( x, y)
42 >>> myax1.plot(x, x)
43 >>> myfig.tight_layout()
44 """
45 majorformatter = ticker.ScalarFormatter(useOffset=False)
47 if figsize == None:
48 fig = plt.figure()
49 else:
50 fig = plt.figure(figsize=figsize)
52 gs = gridspec.GridSpec(
53 2, 1, width_ratios=width_ratios, height_ratios=height_ratios)
55 ax0 = plt.subplot(gs[0])
56 ax1 = plt.subplot(gs[1])
58 if setdifflimits != None:
59 ax1.set_ylim(setdifflimits)
61 ax0.set_xticklabels("", visible=False)
62 ax1.yaxis.set_major_formatter(majorformatter)
64 if setgrid[0]:
66 ax0.grid(True)
68 if setgrid[1]:
69 ax1.grid(True)
71 hpad = 0.0
72 return fig, ax0, ax1