Skip to content

Commit

Permalink
square bin fix
Browse files Browse the repository at this point in the history
  • Loading branch information
psathyrella committed Aug 29, 2024
1 parent 286e981 commit 94b2a40
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
4 changes: 2 additions & 2 deletions projects/cf-gcdyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
args.bool_args = ['dont-scale-params'] # need to keep track of bool args separately (see utils.add_to_scan_cmd())
if 'data' in args.actions:
args.data_samples_list = ':'.join(os.path.basename(d) for d in glob.glob('%s/*' % args.data_dir))
print(' running on %d data samples from %s' % (len(args.data_samples_list), args.data_dir))
print(' running on %d data samples from %s' % (len(args.data_samples_list.split(':')), args.data_dir))
utils.process_scanvar_args(args, after_actions, plot_actions, all_perf_metrics)
if args.inference_extra_args is not None:
raise Exception('not used atm')
Expand Down Expand Up @@ -164,7 +164,7 @@ def add_scan_args(cmd, skip_fcn=None): # using nargs='+' syntax for these rathe
if action in ['simu', 'check-dl']:
cmd += ' --outdir %s --debug 1' % odr # --debug 1
# --make-plots
# --tree-inference-method iqtree
# cmd += ' --tree-inference-method gctree' #iqtree'
if args.test:
cmd += ' --test'
cmd = add_scan_args(cmd, skip_fcn=lambda v: v not in args.scan_vars[action] or action=='check-dl' and v not in check_dl_args)
Expand Down
16 changes: 2 additions & 14 deletions python/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ def mpl_plot(self, ax, ignore_overflows=False, label=None, color=None, alpha=Non
def sqbplot(kwargs):
kwargs['markersize'] = 0
for ibin in self.ibiniter(include_overflows=False):
if not keep_bin(self.low_edges[ibin], self.bin_contents[ibin]): # maybe should use bin centers rather than low edges, i dunno
continue
tplt = ax.plot([self.low_edges[ibin], self.low_edges[ibin+1]], [self.bin_contents[ibin], self.bin_contents[ibin]], **kwargs) # horizontal line for this bin
kwargs['label'] = None # make sure there's only one legend entry for each hist
if not no_vertical_bin_lines:
Expand All @@ -477,20 +479,6 @@ def sqbplot(kwargs):
if not no_vertical_bin_lines:
tplt = ax.plot([self.low_edges[ibin+1], self.low_edges[ibin+1]], [self.bin_contents[ibin], 0], **kwargs) # vertical line for right side of last bin
return tplt # not sure if this gets used anywhere?
# TODO some oldercalls of this may require the following code, so I need to figure shit out
print(' %s square_bins option needs to be checked/fixed, it does not work in some cases (seems to eat bins)' % utils.wrnstr())
import matplotlib.pyplot as plt
if abs(xvals[-1] - xvals[0]) > 5: # greater/less than five is kind of a shitty way to decide whether to int() and +/- 0.5 or not, but I'm calling it now with a range much less than 1, and I don't want the int()s, but where I call it elsewhere I do and the range is much larger, so...
npbins = list(numpy.arange(int(xvals[0]) - 0.5, int(xvals[-1]) - 0.5))
npbins.append(npbins[-1] + 1)
elif xvals[0] != xvals[-1]:
n_bins = len(xvals) # uh, maybe?
npbins = list(numpy.arange(xvals[0], xvals[-1], (xvals[-1] - xvals[0]) / float(n_bins)))
else:
npbins = [0, 1]
kwargs = {k : kwargs[k] for k in kwargs if k not in ['marker', 'markersize']}
kwargs['histtype'] = 'step'
return plt.hist(xvals, npbins, weights=yvals, **kwargs)
# ----------------------------------------------------------------------------------------
if linewidth is not None: # i'd really rather this wasn't here, but the error message mpl kicks is spectacularly uninformative so you have to catch it beforehand (when writing the svg file, it throws TypeError: Cannot cast array data from dtype('<U1') to dtype('float64') according to the rule 'safe')
if not isinstance(linewidth, int):
Expand Down

0 comments on commit 94b2a40

Please sign in to comment.