Fix for SpectralModel.plot_error
@@ -306,7 +306,11 @@ class SpectralModel(object):
y_lo = self._plot_scale_flux(energy, flux - flux_err, energy_power)
y_hi = self._plot_scale_flux(energy, flux + flux_err, energy_power)
- where = (y_hi > 0) & (energy >= energy_range[0]) & (energy <= energy_range[1])
+ # The selection on y > 0 is to work around this matplotlib issue:
+ # https://github.com/matplotlib/matplotlib/issues/8623
+ # This was sometimes causing incorrect error bands because y == 0
+ # at high energies for exponential cutoff power-law spectra.
+ where = (y_hi > 0) & (y_lo > 0) & (energy >= energy_range[0]) & (energy <= energy_range[1])
ax.fill_between(energy.value, y_lo.value, y_hi.value, where=where, **kwargs)
self._plot_format_ax(ax, energy, y_lo, energy_power)
return ax
