spex-xray / spex-help

These are the help and manual pages for the SPEX X-ray spectral fitting package.
1 stars 1 forks source link

[PYSPEX] How to change a pyspex plot? #8

Closed jdeplaa closed 1 year ago

jdeplaa commented 4 years ago

Using a pyspex plot command, for example plot_data(), I get a standard matplotlib plot. But how do I change the plot properties, like axes labels, intervals, etc.?

jdeplaa commented 4 years ago

To change the plot properties, you can delay showing the plot by passing the show=False flag to the plot command and save the plot data and objects in variables:

plotobj, plt = s.plot_data(show=False)

The returned plt object is a pyplot object from matplotlib that you can use to change the properties of the plot. If you want to change the plot axes, then you can use commands like: 'xlabel', 'xlim', 'xscale', 'xticks', 'ylabel', 'ylim', 'yscale', 'yticks', etc. So:

>>> plt.xlim(0.5,10.)    # Set xaxis limits from 0.5 to 10 keV
>>> plt.show()           # Show the final plot in the window.

When you are done, you give the plt.show() command to show the plot. ‘plt’ is a pyplot object, so you can find the descriptions of its functions here: https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.html