Hide keyboard shortcuts

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 

2 

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__) 

9 

10__all__ = ['settwopanel'] 

11 

12 

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. 

24 

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) 

37 

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) 

46 

47 if figsize == None: 

48 fig = plt.figure() 

49 else: 

50 fig = plt.figure(figsize=figsize) 

51 

52 gs = gridspec.GridSpec( 

53 2, 1, width_ratios=width_ratios, height_ratios=height_ratios) 

54 

55 ax0 = plt.subplot(gs[0]) 

56 ax1 = plt.subplot(gs[1]) 

57 

58 if setdifflimits != None: 

59 ax1.set_ylim(setdifflimits) 

60 

61 ax0.set_xticklabels("", visible=False) 

62 ax1.yaxis.set_major_formatter(majorformatter) 

63 

64 if setgrid[0]: 

65 

66 ax0.grid(True) 

67 

68 if setgrid[1]: 

69 ax1.grid(True) 

70 

71 hpad = 0.0 

72 return fig, ax0, ax1