From 1d78e7e1e428554101b706e520d776af84bf2aae Mon Sep 17 00:00:00 2001 From: Daniel Marley Date: Fri, 14 Sep 2018 12:51:12 -0500 Subject: [PATCH 1/3] Add option to update legend in main figure using items from ratio plot --- python/histogram1D.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python/histogram1D.py b/python/histogram1D.py index afeb0a9..fa61a1e 100644 --- a/python/histogram1D.py +++ b/python/histogram1D.py @@ -286,6 +286,11 @@ def plotRatio(self): formatter = FormatStrFormatter('%g') self.ax2.set_yticklabels(np.array([formatter(i) for i in axis_ticks])) + if self.ratio.update_legend: + extra_handles,extra_labels = self.ax2.get_legend_handles_labels() + self.legend['extra_handles'] = extra_handles + self.legend['extra_labels'] = extra_labels + return @@ -365,6 +370,7 @@ def __init__(self): self.ylim = None self.yticks = None self.ylabel = '' + self.update_legend = False # add ratio values to legend on main plot def initialize(self): """Set some default options if not set by the user""" From 66c27f277d48ebf6bb3d84d6002796a9d18a753d Mon Sep 17 00:00:00 2001 From: Daniel Marley Date: Mon, 17 Sep 2018 09:50:33 -0500 Subject: [PATCH 2/3] Bug fixes for converting array data to Data() object --- python/tools.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/python/tools.py b/python/tools.py index 3a4396f..b85b7d9 100755 --- a/python/tools.py +++ b/python/tools.py @@ -73,7 +73,7 @@ def __init__(self): def data2list(data,weights=None,normed=False,binning=1): """Convert array of data into dictionary of information matching 'hist2list' """ - data,bins = np.histogram(data,bins=binning,weights=weights,density=normed) + data,bins = np.histogram(data,bins=binning,weights=weights,normed=normed) results = Data() results.content = data @@ -94,20 +94,20 @@ def data2list2D(data,weights=None,normed=False,binning=1): x = data[0] y = data[1] - data,bins_x,bins_y = np.histogram2d(x,y,bins=binning,density=normed,weights=weights) + data,bins_x,bins_y = np.histogram2d(x,y,bins=binning,normed=normed,weights=weights) # create dummy binning - bins_x = midpoints(bins_x) # get midpoints of bins given the bin edges - bins_y = midpoints(bins_y) - xbins = binsx.repeat(len(bins_y)) - ybins = np.tile(bins_y, (1,len(bins_x)) )[0] + mbins_x = midpoints(bins_x) # get midpoints of bins given the bin edges + mbins_y = midpoints(bins_y) + xbins = mbins_x.repeat(len(mbins_y)) + ybins = np.tile(mbins_y, (1,len(mbins_x)) )[0] results = Data() results.content = data.flatten() # data is a ndarray (nxbins,nybins) results.error = np.sqrt(data) results.bins = {'x':np.array(bins_x),'y':np.array(bins_y)} - results.center = {'x':binnsx,'y':binnsy} + results.center = {'x':xbins,'y':ybins} results.width = {'x':0.5*(bins_x[:-1]-bins_x[1:]), 'y':0.5*(bins_y[:-1]-bins_y[1:])} @@ -319,4 +319,4 @@ def betterColors(): return {'linecolors':lc,'linestyles':ls} -## THE END \ No newline at end of file +## THE END From b167c3ec175047250342f9b3da78841fe832b4db Mon Sep 17 00:00:00 2001 From: Daniel Marley Date: Tue, 18 Sep 2018 10:07:13 -0500 Subject: [PATCH 3/3] Add ability to change savefig options --- python/plotter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/plotter.py b/python/plotter.py index d2269d8..161c9df 100755 --- a/python/plotter.py +++ b/python/plotter.py @@ -343,9 +343,9 @@ def text_labels(self,axis=None): - def savefig(self): - """Save the figure""" - plt.savefig(self.saveAs+'.'+self.format) + def savefig(self,**kwargs): + """Save the figure. Use kwargs to modify arguments from style file""" + plt.savefig(self.saveAs+'.'+self.format,**kwargs) plt.close() return