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

1from builtins import object 

2from .plotHandler import PlotHandler 

3import matplotlib.pylab as plt 

4 

5__all__ = ['PlotBundle'] 

6 

7class PlotBundle(object): 

8 """ 

9 Object designed to help organize multiple MetricBundles that will be plotted 

10 together using the PlotHandler. 

11 """ 

12 

13 def __init__(self, bundleList=None, plotDicts=None, plotFunc=None): 

14 """ 

15 Init object and set things if desired. 

16 bundleList: A list of bundleDict objects 

17 plotDicts: A list of dictionaries with plotting kwargs 

18 plotFunc: A single MAF plotting function 

19 """ 

20 if bundleList is None: 

21 self.bundleList = [] 

22 else: 

23 self.bundleList = bundleList 

24 

25 if plotDicts is None: 

26 if len(self.bundleList) > 0: 

27 self.plotDicts = [{}] 

28 else: 

29 self.plotDicts = [] 

30 else: 

31 self.plotDicts = plotDicts 

32 

33 self.plotFunc = plotFunc 

34 

35 def addBundle(self, bundle, plotDict=None, plotFunc=None): 

36 """ 

37 Add bundle to the object. 

38 Optionally add a plotDict and/or replace the plotFunc 

39 """ 

40 self.bundleList.append(bundle) 

41 if plotDict is not None: 

42 self.plotDicts.append(plotDict) 

43 else: 

44 self.plotDicts.append({}) 

45 if plotFunc is not None: 

46 self.plotFunc = plotFunc 

47 

48 def incrementPlotOrder(self): 

49 """ 

50 Find the maximium order number in the display dicts, and set them to +1 that 

51 """ 

52 maxOrder = 0 

53 for mB in self.bundleList: 

54 if 'order' in list(mB.displayDict.keys()): 

55 maxOrder = max([maxOrder, mB.displayDict['order']]) 

56 

57 for mB in self.bundleList: 

58 mB.displayDict['order'] = maxOrder + 1 

59 

60 def percentileLegend(self): 

61 """ 

62 Go through the bundles and change the lables if there are the correct summary stats 

63 """ 

64 for i, mB in enumerate(self.bundleList): 

65 if mB.summaryValues is not None: 

66 keys = list(mB.summaryValues.keys()) 

67 if ('25th%ile' in keys) & ('75th%ile' in keys) & ('Median' in keys): 

68 if 'label' not in list(self.plotDicts[i].keys()): 

69 self.plotDicts[i]['label'] = '' 

70 newstr = '%0.1f/%0.1f/%0.1f ' % (mB.summaryValues['25th%ile'], 

71 mB.summaryValues['Median'], 

72 mB.summaryValues['75th%ile']) 

73 self.plotDicts[i]['label'] = newstr + self.plotDicts[i]['label'] 

74 

75 def plot(self, outDir='Out', resultsDb=None, closeFigs=True): 

76 ph = PlotHandler(outDir=outDir, resultsDb=resultsDb) 

77 ph.setMetricBundles(self.bundleList) 

78 # Auto-generate labels and things 

79 ph.setPlotDicts(plotDicts=self.plotDicts, plotFunc=self.plotFunc) 

80 ph.plot(self.plotFunc, plotDicts=self.plotDicts) 

81 if closeFigs: 

82 plt.close('all')