Skip to content

Commit

Permalink
Merge pull request #13 from demarley/goldilocks
Browse files Browse the repository at this point in the history
Goldilocks
  • Loading branch information
demarley authored Sep 19, 2018
2 parents 1f2078a + b167c3e commit b711cb7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
6 changes: 6 additions & 0 deletions python/histogram1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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"""
Expand Down
6 changes: 3 additions & 3 deletions python/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions python/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:])}

Expand Down Expand Up @@ -319,4 +319,4 @@ def betterColors():

return {'linecolors':lc,'linestyles':ls}

## THE END
## THE END

0 comments on commit b711cb7

Please sign in to comment.