Support xunit in FluxPoints.plot() #5219
-
Using v1.0.1, but I believe it still applies to the development version. Looking at the code (https://docs.gammapy.org/dev/_modules/gammapy/estimators/points/core.html#FluxPoints.plot ), it looks like like the units in the y-axis are hardcoded in the DEFAULT_UNIT dictionary, but I don't see a reference to the x-axis units. I believe it uses the default units stored in that FluxPoints object. It would be nice if, similar to how the SpectralModel.plot() work, it could take xunit and yunit as possible parameters and handle the conversions (e.g. TeV -> GeV). |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Add: I would think it is also useful to be able to pass |
Beta Was this translation helpful? Give feedback.
-
@mireianievas Have you checked out the entry "Choose units for plotting" in our how to? (see https://docs.gammapy.org/1.1/user-guide/howto.html) Removing the unit handling from the Gammapy API was a deliberate decision, because the combination of import matplotlib.pyplot as plt
from gammapy.estimators import FluxPoints
from astropy import units as u
filename = "$GAMMAPY_DATA/hawc_crab/HAWC19_flux_points.fits"
fp = FluxPoints.read(filename)
ax = plt.subplot()
ax.xaxis.set_units(u.eV)
ax.yaxis.set_units(u.Unit("erg cm-2 s-1"))
fp.plot(ax=ax, sed_type="e2dnde") The
|
Beta Was this translation helpful? Give feedback.
@mireianievas Have you checked out the entry "Choose units for plotting" in our how to? (see https://docs.gammapy.org/1.1/user-guide/howto.html)
Removing the unit handling from the Gammapy API was a deliberate decision, because the combination of
matpplotlib
andAstropy
already offers every functionality needed. Here is the copy and paste example from the how to:The
ax.xaxi…