threeML / hawc_hal

HAWC Accelerated Likelihood - python-only framework for HAWC data analysis
BSD 3-Clause "New" or "Revised" License
12 stars 22 forks source link

Fix spectral plot #30

Closed henrikef closed 4 years ago

henrikef commented 5 years ago

spectral_plot crashes for some older versions of matplotlib (I'm using 2.1.1) as it cannot deal with non-numerical x values. See error message below.

This pull request fixes that issue by providing numerical values to plot, and later setting the tick labels to the bin names.

Tests pass (1 xfail) on my laptop.

test_complete_analysis.py:49: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../miniconda3/envs/st_test3/lib/python2.7/site-packages/hawc_hal/HAL.py:407: in display_spectrum
    return self._plot_spectrum(net_counts, yerr, model_only, residuals, residuals_err)
../../../miniconda3/envs/st_test3/lib/python2.7/site-packages/hawc_hal/HAL.py:415: in _plot_spectrum
    color='black', label='Net counts', fmt='.')
../../../miniconda3/envs/st_test3/lib/python2.7/site-packages/matplotlib/__init__.py:1898: in inner
    return func(ax, *args, **kwargs)
../../../miniconda3/envs/st_test3/lib/python2.7/site-packages/matplotlib/axes/_axes.py:3030: in errorbar
    barcols.append(self.vlines(xo, lo, uo, **eb_lines_style))
../../../miniconda3/envs/st_test3/lib/python2.7/site-packages/matplotlib/__init__.py:1898: in inner
    return func(ax, *args, **kwargs)
../../../miniconda3/envs/st_test3/lib/python2.7/site-packages/matplotlib/axes/_axes.py:1072: in vlines
    minx = x.min()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

a = array(['1', '2', '3', '4', '5', '6', '7', '8', '9'], dtype='|S1'), axis = None, out = None, keepdims = False, initial = <no value>

    def _amin(a, axis=None, out=None, keepdims=False,
              initial=_NoValue):
>       return umr_minimum(a, axis, None, out, keepdims, initial)
E       TypeError: cannot perform reduce with flexible type

../../../miniconda3/envs/st_test3/lib/python2.7/site-packages/numpy/core/_methods.py:32: TypeError
henrikef commented 4 years ago

I don't think this is necessary anymore. Is anyone still using matplotlib 2.1.1? If so, we can revisit this.