Changing the labels of the plot axesÂ
Sherpa datasets have set_xlabel and set_ylabel methods that let you customise the labels in plots. However, note that these labels used whatever the analysis setting (for PHA data) and may appear in screen output.
The following code loads in the same dataset three times and sets the same energy range for all of them:
from sherpa.astro import ui from sherpa.utils.logging import SherpaVerbosity with SherpaVerbosity("ERROR"): ui.load_pha(1, "3c273.pi") ui.load_pha(2, "3c273.pi") ui.load_pha(3, "3c273.pi") ui.notice(0.5, 5)
The output of this is
dataset 1: 0.00146:14.9504 -> 0.4672:5.0224 Energy (keV) dataset 2: 0.00146:14.9504 -> 0.4672:5.0224 Energy (keV) dataset 3: 0.00146:14.9504 -> 0.4672:5.0224 Energy (keV)
The x label of the second dataset is set to "X axis [2]", and the x and y labels of the third dataset to "xx" and "yy" respectively with the following:
data2 = ui.get_data(2) data3 = ui.get_data(3) data2.set_xlabel("X axis [2]") data3.set_xlabel("xx") data3.set_ylabel("yy")
After changing the labels, the third dataset is changed to use "wavelength" units:
ui.set_analysis(3, "wave")
This creates the following output (note that the screen message uses the manually-specified units for the X axis rather than the expected "Angstrom" message, thanks to the set_xlabel call for this dataset:
dataset 3: 2.46862:26.5377 xx
The data plots generate the following three figures:
ui.plot_data(1) ui.plot_data(2) ui.plot_data(3)
Figure 1: The default labels
![[The data set has an x label of "Energy (keV)" and y label "Counts/sec/keV".]](label.none.png)
![[Print media version: The data set has an x label of "Energy (keV)" and y label "Counts/sec/keV".]](label.none.png)
Figure 1: The default labels
Figure 2: Only the X axis has been changed
![[The data set has an x label of "X axis [2]" and y label "counts/sec/kev". The data values are the same as the previous plot.]](label.x.png)
![[Print media version: The data set has an x label of "X axis [2]" and y label "counts/sec/kev". The data values are the same as the previous plot.]](label.x.png)
Figure 2: Only the X axis has been changed
Figure 3: Changing both axis labels
![[The data set has an x label of "xx" and y label "yy". The data is different to the other two plots as it is being displayed in wavelength space.]](label.xy.png)
![[Print media version: The data set has an x label of "xx" and y label "yy". The data is different to the other two plots as it is being displayed in wavelength space.]](label.xy.png)