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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

import warnings 

 

try: 

import matplotlib.gridspec as gridspec 

import matplotlib.ticker as ticker 

import matplotlib.pyplot as plt 

except Exception as e: 

warnings.warn("matplotlib not imported in %s\n\n" % __file__) 

 

__all__ = ['settwopanel'] 

 

 

def settwopanel(height_ratios=[1.0, 0.3], 

width_ratios=[1., 0.], 

padding=None, 

setdifflimits=[0.9, 1.1], 

setoffset=None, 

setgrid=[True, True], 

figsize=None): 

""" 

returns a figure and axes for a main panel and a lower panel for 

showing differential information of overplotted quantities in 

the top panel. 

 

Parameters 

---------- 

height_ratios: list of floats, optional defaults to [1.0, 0.3] 

height ratio between the upper and lower panel 

width_ratios: list of floats, optional defaults to [1.0, 0.0] 

width ratio between the left and right panel 

figsize: figure size 

setgrid: List of bools, optional, defaults to [True, True] 

whether to set grid on the two panels 

Returns 

------- 

figure object , ax0 (axes for top panel) , and ax1 (axes for lower panel) 

 

Examples 

-------- 

>>> myfig, myax0 , myax1 = settwopanel ( ) 

>>> myax0.plot( x, y) 

>>> myax1.plot(x, x) 

>>> myfig.tight_layout() 

""" 

majorformatter = ticker.ScalarFormatter(useOffset=False) 

 

if figsize == None: 

fig = plt.figure() 

else: 

fig = plt.figure(figsize=figsize) 

 

gs = gridspec.GridSpec( 

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

 

ax0 = plt.subplot(gs[0]) 

ax1 = plt.subplot(gs[1]) 

 

if setdifflimits != None: 

ax1.set_ylim(setdifflimits) 

 

ax0.set_xticklabels("", visible=False) 

ax1.yaxis.set_major_formatter(majorformatter) 

 

if setgrid[0]: 

 

ax0.grid(True) 

 

if setgrid[1]: 

ax1.grid(True) 

 

hpad = 0.0 

return fig, ax0, ax1