Commit 10d97daa855809e59def8cd3a204f3371d4d8d97
1 parent
e71941d0
Adapted show_obs.py to coding conventions and suggestions from jknoedlseder
Showing
1 changed file
with
11 additions
and
12 deletions
examples/show_obs.py
| ... | ... | @@ -21,24 +21,23 @@ |
| 21 | 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | 22 | # |
| 23 | 23 | # ========================================================================== |
| 24 | - | |
| 24 | +import sys | |
| 25 | 25 | import gammalib |
| 26 | 26 | import ctools |
| 27 | 27 | import cscripts |
| 28 | -import sys | |
| 29 | 28 | try: |
| 30 | 29 | import matplotlib.pyplot as plt |
| 30 | + plt.figure() | |
| 31 | + plt.close() | |
| 31 | 32 | except: |
| 32 | - sys.exit("This script requires matplotlib") | |
| 33 | + print('This script needs the "matplotlib" module') | |
| 34 | + sys.exit() | |
| 33 | 35 | |
| 34 | 36 | |
| 35 | 37 | # ======================== # |
| 36 | 38 | # Main routine entry point # |
| 37 | 39 | # ======================== # |
| 38 | -if __name__ == "__main__": | |
| 39 | - """ | |
| 40 | - Print and display details of the observation container using matplotlib. | |
| 41 | - """ | |
| 40 | +if __name__ == '__main__': | |
| 42 | 41 | |
| 43 | 42 | # Print help if wrong number of arguments provided |
| 44 | 43 | if not len(sys.argv) > 1: |
| ... | ... | @@ -91,7 +90,7 @@ if __name__ == "__main__": |
| 91 | 90 | amin = min(azimuths) |
| 92 | 91 | amax = max(azimuths) |
| 93 | 92 | plt.hist(azimuths, bins=30, range=(amin, amax),fc='blue') |
| 94 | - plt.xlabel("Azimuth Angle [deg]") | |
| 93 | + plt.xlabel("Azimuth Angle (deg)") | |
| 95 | 94 | plt.ylabel("Abundance") |
| 96 | 95 | plt.title("Azimuth distribution") |
| 97 | 96 | |
| ... | ... | @@ -101,7 +100,7 @@ if __name__ == "__main__": |
| 101 | 100 | omin = min(offsets) |
| 102 | 101 | omax = max(offsets) |
| 103 | 102 | plt.hist(offsets, bins=30, range=(omin, omax),fc='blue') |
| 104 | - plt.xlabel("Offset from (RA, DEC)=("+str(ra)+","+str(dec)+") [deg]") | |
| 103 | + plt.xlabel("Offset from (RA, DEC)=("+str(ra)+","+str(dec)+") (deg)") | |
| 105 | 104 | plt.ylabel("Abundance") |
| 106 | 105 | plt.title("Offset distribution") |
| 107 | 106 | |
| ... | ... | @@ -116,7 +115,7 @@ if __name__ == "__main__": |
| 116 | 115 | plt.figure() |
| 117 | 116 | plt.hist(emin, bins=80, range=(-1.0, 2.0), fc='red',label="emin") |
| 118 | 117 | plt.hist(emax, bins=80, range=(-1.0, 2.0), fc='blue', label ="emax") |
| 119 | - plt.xlabel("Energy threshold [log10 (E/TeV)]") | |
| 118 | + plt.xlabel("Energy threshold (log10 (E/TeV))") | |
| 120 | 119 | plt.ylabel("Abundance") |
| 121 | 120 | plt.legend(loc="upper left") |
| 122 | 121 | plt.title("Energy threshold") |
| ... | ... | @@ -128,8 +127,8 @@ if __name__ == "__main__": |
| 128 | 127 | tmean = gti.tstart(i) + 0.5*(gti.tstart(i)-gti.tstart(i)) |
| 129 | 128 | times.append(tmean.mjd()) |
| 130 | 129 | plt.plot(times, zeniths, 'o',lw=2.0, color='black') |
| 131 | - plt.xlabel("Time [MJD]") | |
| 132 | - plt.ylabel("Zenith Angle [deg]") | |
| 130 | + plt.xlabel("Time (MJD)") | |
| 131 | + plt.ylabel("Zenith Angle (deg)") | |
| 133 | 132 | plt.title("Observation time") |
| 134 | 133 | |
| 135 | 134 | # Show plots | ... | ... |