Plotting histogram with 1d data when fig argument is given
Hi, When trying to plot two sets of 1d histograms (1d data xs1 and xs2, with weights weights1 and weights2) on the same figure e.g.
fig = corner.corner(xs1, weights1) fig = corner.corner(xs2, weights2, fig = fig)
EDIT: I think this bug generalises to plotting 1d histograms and supplying a fig argument, rather than the more specific case of plotting two 1d histograms on the same figure
on the second call to corner.corner I get an error in corner.py on line 239:
n, _, _ = ax.hist(x, bins=bins[i], weights=weights, range=np.sort(range[i]), **hist_kwargs)
that the object ax is a np.array not an axes object. This is because the proceeding statement at line 233 is:
if np.shape(xs)[0] == 1: ax = axes else: ax = axes[i, i]
and sets ax = axes in the case of 1d data. But axes is an array in the case of supplying corner.corner() a fig argument since in line 206 we have:
if fig is None: fig, axes = pl.subplots(K, K, figsize=(dim, dim)) else: try: axes = np.array(fig.axes).reshape((K, K)) except: raise ValueError("Provided figure has {0} axes, but data has " "dimensions K={1}".format(len(fig.axes), K))
However I think I rectified this buy by replacing the conditional at line 233 with: try: ax = axes[i, i] except TypeError: ax = axes
Hopefully, this does not introduce new bugs. From what I've seen it looks ok but I have in no way tested it thoroughly.
Thanks
Kamran
Thanks for this. We definitely don't test for the 1-D case, but it would be good to support it.
If anyone feels up to it, please write a test and the fix for this bug. If not, I'll get to it at some point!