@@ -389,7 +389,7 @@ def plot_histogram(simulated, observation, bins='fd', percentile=None,
389
389
pyplot .show ()
390
390
return ax
391
391
392
- def plot_ecdf (x , ecdf , axes = None , xv = None , show = False , plot_args = None ):
392
+ def plot_ecdf (x , ecdf , axes = None , xv = None , show = False , plot_args = None ):
393
393
""" Plots empirical cumulative distribution function. """
394
394
plot_args = plot_args or {}
395
395
# get values from plotting args
@@ -970,32 +970,56 @@ def plot_number_test(evaluation_result, axes=None, show=True, plot_args=None):
970
970
Takes result from evaluation and generates a specific histogram plot to show the results of the statistical evaluation
971
971
for the n-test.
972
972
973
-
974
973
Args:
975
974
evaluation_result: object-like var that implements the interface of the above EvaluationResult
975
+ axes (matplotlib.Axes): axes object used to chain this plot
976
+ show (bool): if true, call pyplot.show()
977
+ plot_args(dict): optional argument containing a dictionary of plotting arguments, with keys as strings and items as described below
978
+
979
+ Optional plotting arguments:
980
+ * figsize: (:class:`list`/:class:`tuple`) - default: [6.4, 4.8]
981
+ * title: (:class:`str`) - default: name of the first evaluation result type
982
+ * title_fontsize: (:class:`float`) Fontsize of the plot title - default: 10
983
+ * xlabel: (:class:`str`) - default: 'X'
984
+ * xlabel_fontsize: (:class:`float`) - default: 10
985
+ * xticks_fontsize: (:class:`float`) - default: 10
986
+ * ylabel_fontsize: (:class:`float`) - default: 10
987
+ * text_fontsize: (:class:`float`) - default: 14
988
+ * tight_layout: (:class:`bool`) Set matplotlib.figure.tight_layout to remove excess blank space in the plot - default: True
989
+ * percentile (:class:`float`) Critial region to shade on histogram - default: 95
990
+ * bins: (:class:`str`) - Set binning type. see matplotlib.hist for more info - default: 'auto'
991
+ * xy: (:class:`list`/:class:`tuple`) - default: (0.55, 0.3)
976
992
977
993
Returns:
978
994
ax (matplotlib.axes.Axes): can be used to modify the figure
979
995
980
996
"""
981
- plot_args = plot_args or {}
982
- # handle plotting
997
+
998
+ # chain plotting axes if requested
983
999
if axes :
984
1000
chained = True
985
1001
else :
986
1002
chained = False
987
- # supply fixed arguments to plots
988
- # might want to add other defaults here
989
- filename = plot_args .get ('filename' , None )
990
- xlabel = plot_args .get ('xlabel' , 'Event count of catalog' )
1003
+
1004
+ # default plotting arguments
1005
+ plot_args = plot_args or {}
1006
+ title = plot_args .get ('title' , 'Number Test' )
1007
+ title_fontsize = plot_args .get ('title_fontsize' , None )
1008
+ xlabel = plot_args .get ('xlabel' , 'Event count of catalogs' )
1009
+ xlabel_fontsize = plot_args .get ('xlabel_fontsize' , None )
991
1010
ylabel = plot_args .get ('ylabel' , 'Number of catalogs' )
1011
+ ylabel_fontsize = plot_args .get ('ylabel_fontsize' , None )
1012
+ text_fontsize = plot_args .get ('text_fontsize' , 14 )
1013
+ tight_layout = plot_args .get ('tight_layout' , True )
1014
+ percentile = plot_args .get ('percentile' , 95 )
1015
+ filename = plot_args .get ('filename' , None )
1016
+ bins = plot_args .get ('bins' , 'auto' )
992
1017
xy = plot_args .get ('xy' , (0.5 , 0.3 ))
993
1018
1019
+ # set default plotting arguments
994
1020
fixed_plot_args = {'obs_label' : evaluation_result .obs_name ,
995
1021
'sim_label' : evaluation_result .sim_name }
996
1022
plot_args .update (fixed_plot_args )
997
- bins = plot_args .get ('mag_bins' , 'auto' )
998
- percentile = plot_args .get ('percentile' , 95 )
999
1023
ax = plot_histogram (evaluation_result .test_distribution , evaluation_result .observed_statistic ,
1000
1024
catalog = evaluation_result .obs_catalog_repr ,
1001
1025
plot_args = plot_args ,
@@ -1010,18 +1034,20 @@ def plot_number_test(evaluation_result, axes=None, show=True, plot_args=None):
1010
1034
.format (* evaluation_result .quantile , evaluation_result .observed_statistic ),
1011
1035
xycoords = 'axes fraction' ,
1012
1036
xy = xy ,
1013
- fontsize = 14 )
1037
+ fontsize = text_fontsize )
1014
1038
except :
1015
1039
ax .annotate ('$\gamma = P(X \leq x) = {:.2f}$\n $\omega = {:.2f}$'
1016
1040
.format (evaluation_result .quantile , evaluation_result .observed_statistic ),
1017
1041
xycoords = 'axes fraction' ,
1018
1042
xy = xy ,
1019
- fontsize = 14 )
1043
+ fontsize = text_fontsize )
1020
1044
1021
- title = plot_args .get ('title' , evaluation_result .name )
1022
- ax .set_title (title , fontsize = 14 )
1023
- ax .set_xlabel (xlabel )
1024
- ax .set_ylabel (ylabel )
1045
+ ax .set_title (title , fontsize = title_fontsize )
1046
+ ax .set_xlabel (xlabel , fontsize = xlabel_fontsize )
1047
+ ax .set_ylabel (ylabel , fontsize = ylabel_fontsize )
1048
+
1049
+ if tight_layout :
1050
+ ax .figure .tight_layout ()
1025
1051
1026
1052
if filename is not None :
1027
1053
ax .figure .savefig (filename + '.pdf' )
@@ -1040,31 +1066,54 @@ def plot_magnitude_test(evaluation_result, axes=None, show=True, plot_args=None)
1040
1066
Takes result from evaluation and generates a specific histogram plot to show the results of the statistical evaluation
1041
1067
for the M-test.
1042
1068
1043
-
1044
1069
Args:
1045
- evaluation_result: object that implements the interface of EvaluationResult
1070
+ evaluation_result: object-like var that implements the interface of the above EvaluationResult
1071
+ axes (matplotlib.Axes): axes object used to chain this plot
1072
+ show (bool): if true, call pyplot.show()
1073
+ plot_args(dict): optional argument containing a dictionary of plotting arguments, with keys as strings and items as described below
1074
+
1075
+ Optional plotting arguments:
1076
+ * figsize: (:class:`list`/:class:`tuple`) - default: [6.4, 4.8]
1077
+ * title: (:class:`str`) - default: name of the first evaluation result type
1078
+ * title_fontsize: (:class:`float`) Fontsize of the plot title - default: 10
1079
+ * xlabel: (:class:`str`) - default: 'X'
1080
+ * xlabel_fontsize: (:class:`float`) - default: 10
1081
+ * xticks_fontsize: (:class:`float`) - default: 10
1082
+ * ylabel_fontsize: (:class:`float`) - default: 10
1083
+ * tight_layout: (:class:`bool`) Set matplotlib.figure.tight_layout to remove excess blank space in the plot - default: True
1084
+ * percentile (:class:`float`) Critial region to shade on histogram - default: 95
1085
+ * bins: (:class:`str`) - Set binning type. see matplotlib.hist for more info - default: 'auto'
1086
+ * xy: (:class:`list`/:class:`tuple`) - default: (0.55, 0.6)
1046
1087
1047
1088
Returns:
1048
- ax (matplotlib.axes. Axes): can be used to modify the figure
1089
+ ax (matplotlib.Axes): containing the new plot
1049
1090
1050
1091
"""
1051
1092
plot_args = plot_args or {}
1093
+ title = plot_args .get ('title' , 'Magnitude Test' )
1094
+ title_fontsize = plot_args .get ('title_fontsize' , None )
1095
+ xlabel = plot_args .get ('xlabel' , 'D* Statistic' )
1096
+ xlabel_fontsize = plot_args .get ('xlabel_fontsize' , None )
1097
+ ylabel = plot_args .get ('ylabel' , 'Number of catalogs' )
1098
+ ylabel_fontsize = plot_args .get ('ylabel_fontsize' , None )
1099
+ tight_layout = plot_args .get ('tight_layout' , True )
1100
+ percentile = plot_args .get ('percentile' , 95 )
1101
+ text_fontsize = plot_args .get ('text_fontsize' , 14 )
1102
+ filename = plot_args .get ('filename' , None )
1103
+ bins = plot_args .get ('bins' , 'auto' )
1104
+ xy = plot_args .get ('xy' , (0.55 , 0.6 ))
1105
+
1052
1106
# handle plotting
1053
1107
if axes :
1054
1108
chained = True
1055
1109
else :
1056
1110
chained = False
1111
+
1057
1112
# supply fixed arguments to plots
1058
1113
# might want to add other defaults here
1059
- filename = plot_args .get ('filename' , None )
1060
- xy = plot_args .get ('xy' , (0.55 , 0.6 ))
1061
- fixed_plot_args = {'xlabel' : 'D* Statistic' ,
1062
- 'ylabel' : 'Number of Catalogs' ,
1063
- 'obs_label' : evaluation_result .obs_name ,
1114
+ fixed_plot_args = {'obs_label' : evaluation_result .obs_name ,
1064
1115
'sim_label' : evaluation_result .sim_name }
1065
1116
plot_args .update (fixed_plot_args )
1066
- bins = plot_args .get ('bins' , 'auto' )
1067
- percentile = plot_args .get ('percentile' , 95 )
1068
1117
ax = plot_histogram (evaluation_result .test_distribution , evaluation_result .observed_statistic ,
1069
1118
catalog = evaluation_result .obs_catalog_repr ,
1070
1119
plot_args = plot_args ,
@@ -1079,17 +1128,22 @@ def plot_magnitude_test(evaluation_result, axes=None, show=True, plot_args=None)
1079
1128
.format (evaluation_result .quantile , evaluation_result .observed_statistic ),
1080
1129
xycoords = 'axes fraction' ,
1081
1130
xy = xy ,
1082
- fontsize = 14 )
1131
+ fontsize = text_fontsize )
1083
1132
except TypeError :
1084
1133
# if both quantiles are provided, we want to plot the greater-equal quantile
1085
1134
ax .annotate ('$\gamma = P(X \geq x) = {:.2f}$\n $\omega = {:.2f}$'
1086
1135
.format (evaluation_result .quantile [0 ], evaluation_result .observed_statistic ),
1087
1136
xycoords = 'axes fraction' ,
1088
1137
xy = xy ,
1089
- fontsize = 14 )
1138
+ fontsize = text_fontsize )
1090
1139
1091
- title = plot_args .get ('title' , 'Magnitude Test' )
1092
- ax .set_title (title , fontsize = 14 )
1140
+ ax .set_title (title , fontsize = title_fontsize )
1141
+ ax .set_xlabel (xlabel , fontsize = xlabel_fontsize )
1142
+ ax .set_ylabel (ylabel , fontsize = ylabel_fontsize )
1143
+
1144
+ if tight_layout :
1145
+ var = ax .get_figure ().tight_layout
1146
+ ()
1093
1147
1094
1148
if filename is not None :
1095
1149
ax .figure .savefig (filename + '.pdf' )
@@ -1149,7 +1203,6 @@ def plot_distribution_test(evaluation_result, axes=None, show=True, plot_args=No
1149
1203
1150
1204
title = plot_args .get ('title' , evaluation_result .name )
1151
1205
ax .set_title (title , fontsize = 14 )
1152
- ax .set_title (title , fontsize = 14 )
1153
1206
ax .set_xlabel (xlabel )
1154
1207
ax .set_ylabel (ylabel )
1155
1208
@@ -1170,30 +1223,53 @@ def plot_likelihood_test(evaluation_result, axes=None, show=True, plot_args=None
1170
1223
Takes result from evaluation and generates a specific histogram plot to show the results of the statistical evaluation
1171
1224
for the L-test.
1172
1225
1173
-
1174
1226
Args:
1175
1227
evaluation_result: object-like var that implements the interface of the above EvaluationResult
1228
+ axes (matplotlib.Axes): axes object used to chain this plot
1229
+ show (bool): if true, call pyplot.show()
1230
+ plot_args(dict): optional argument containing a dictionary of plotting arguments, with keys as strings and items as described below
1231
+
1232
+ Optional plotting arguments:
1233
+ * figsize: (:class:`list`/:class:`tuple`) - default: [6.4, 4.8]
1234
+ * title: (:class:`str`) - default: name of the first evaluation result type
1235
+ * title_fontsize: (:class:`float`) Fontsize of the plot title - default: 10
1236
+ * xlabel: (:class:`str`) - default: 'X'
1237
+ * xlabel_fontsize: (:class:`float`) - default: 10
1238
+ * xticks_fontsize: (:class:`float`) - default: 10
1239
+ * ylabel_fontsize: (:class:`float`) - default: 10
1240
+ * text_fontsize: (:class:`float`) - default: 14
1241
+ * tight_layout: (:class:`bool`) Set matplotlib.figure.tight_layout to remove excess blank space in the plot - default: True
1242
+ * percentile (:class:`float`) Critial region to shade on histogram - default: 95
1243
+ * bins: (:class:`str`) - Set binning type. see matplotlib.hist for more info - default: 'auto'
1244
+ * xy: (:class:`list`/:class:`tuple`) - default: (0.55, 0.3)
1176
1245
1177
1246
Returns:
1178
1247
ax (matplotlib.axes.Axes): can be used to modify the figure
1179
-
1180
1248
"""
1181
1249
plot_args = plot_args or {}
1250
+ title = plot_args .get ('title' , 'Pseudo-likelihood Test' )
1251
+ title_fontsize = plot_args .get ('title_fontsize' , None )
1252
+ xlabel = plot_args .get ('xlabel' , 'Pseudo likelihood' )
1253
+ xlabel_fontsize = plot_args .get ('xlabel_fontsize' , None )
1254
+ ylabel = plot_args .get ('ylabel' , 'Number of catalogs' )
1255
+ ylabel_fontsize = plot_args .get ('ylabel_fontsize' , None )
1256
+ text_fontsize = plot_args .get ('text_fontsize' , 14 )
1257
+ tight_layout = plot_args .get ('tight_layout' , True )
1258
+ percentile = plot_args .get ('percentile' , 95 )
1259
+ filename = plot_args .get ('filename' , None )
1260
+ bins = plot_args .get ('bins' , 'auto' )
1261
+ xy = plot_args .get ('xy' , (0.55 , 0.3 ))
1262
+
1182
1263
# handle plotting
1183
1264
if axes :
1184
1265
chained = True
1185
1266
else :
1186
1267
chained = False
1187
1268
# supply fixed arguments to plots
1188
1269
# might want to add other defaults here
1189
- filename = plot_args .get ('filename' , None )
1190
- fixed_plot_args = {'xlabel' : 'Pseudo likelihood' ,
1191
- 'ylabel' : 'Number of catalogs' ,
1192
- 'obs_label' : evaluation_result .obs_name ,
1270
+ fixed_plot_args = {'obs_label' : evaluation_result .obs_name ,
1193
1271
'sim_label' : evaluation_result .sim_name }
1194
1272
plot_args .update (fixed_plot_args )
1195
- bins = plot_args .get ('bins' , 'auto' )
1196
- percentile = plot_args .get ('percentile' , 95 )
1197
1273
ax = plot_histogram (evaluation_result .test_distribution , evaluation_result .observed_statistic ,
1198
1274
catalog = evaluation_result .obs_catalog_repr ,
1199
1275
plot_args = plot_args ,
@@ -1207,19 +1283,22 @@ def plot_likelihood_test(evaluation_result, axes=None, show=True, plot_args=None
1207
1283
ax .annotate ('$\gamma = P(X \leq x) = {:.2f}$\n $\omega = {:.2f}$'
1208
1284
.format (evaluation_result .quantile , evaluation_result .observed_statistic ),
1209
1285
xycoords = 'axes fraction' ,
1210
- xy = ( 0.55 , 0.3 ) ,
1211
- fontsize = 14 )
1286
+ xy = xy ,
1287
+ fontsize = text_fontsize )
1212
1288
except TypeError :
1213
1289
# if both quantiles are provided, we want to plot the greater-equal quantile
1214
1290
ax .annotate ('$\gamma = P(X \leq x) = {:.2f}$\n $\omega = {:.2f}$'
1215
1291
.format (evaluation_result .quantile [1 ], evaluation_result .observed_statistic ),
1216
1292
xycoords = 'axes fraction' ,
1217
- xy = ( 0.55 , 0.3 ) ,
1218
- fontsize = 14 )
1293
+ xy = xy ,
1294
+ fontsize = text_fontsize )
1219
1295
1296
+ ax .set_title (title , fontsize = title_fontsize )
1297
+ ax .set_xlabel (xlabel , fontsize = xlabel_fontsize )
1298
+ ax .set_ylabel (ylabel , fontsize = ylabel_fontsize )
1220
1299
1221
- title = plot_args . get ( 'title' , 'Likelihood Test' )
1222
- ax .set_title ( title , fontsize = 14 )
1300
+ if tight_layout :
1301
+ ax .figure . tight_layout ( )
1223
1302
1224
1303
if filename is not None :
1225
1304
ax .figure .savefig (filename + '.pdf' )
@@ -1237,31 +1316,59 @@ def plot_spatial_test(evaluation_result, axes=None, plot_args=None, show=True):
1237
1316
Plot spatial test result from catalog based forecast
1238
1317
1239
1318
Args:
1240
- evaluation_result:
1319
+ evaluation_result: object-like var that implements the interface of the above EvaluationResult
1320
+ axes (matplotlib.Axes): axes object used to chain this plot
1321
+ show (bool): if true, call pyplot.show()
1322
+ plot_args(dict): optional argument containing a dictionary of plotting arguments, with keys as strings and items as described below
1241
1323
1242
- Returns:
1324
+ Optional plotting arguments:
1325
+ * figsize: (:class:`list`/:class:`tuple`) - default: [6.4, 4.8]
1326
+ * title: (:class:`str`) - default: name of the first evaluation result type
1327
+ * title_fontsize: (:class:`float`) Fontsize of the plot title - default: 10
1328
+ * xlabel: (:class:`str`) - default: 'X'
1329
+ * xlabel_fontsize: (:class:`float`) - default: 10
1330
+ * xticks_fontsize: (:class:`float`) - default: 10
1331
+ * ylabel_fontsize: (:class:`float`) - default: 10
1332
+ * text_fontsize: (:class:`float`) - default: 14
1333
+ * tight_layout: (:class:`bool`) Set matplotlib.figure.tight_layout to remove excess blank space in the plot - default: True
1334
+ * percentile (:class:`float`) Critial region to shade on histogram - default: 95
1335
+ * bins: (:class:`str`) - Set binning type. see matplotlib.hist for more info - default: 'auto'
1336
+ * xy: (:class:`list`/:class:`tuple`) - default: (0.2, 0.6)
1243
1337
1338
+ Returns:
1339
+ ax (matplotlib.axes.Axes): can be used to modify the figure
1244
1340
"""
1341
+
1245
1342
plot_args = plot_args or {}
1343
+ title = plot_args .get ('title' , 'Spatial Test' )
1344
+ title_fontsize = plot_args .get ('title_fontsize' , None )
1345
+ xlabel = plot_args .get ('xlabel' , 'Normalized pseudo-likelihood' )
1346
+ xlabel_fontsize = plot_args .get ('xlabel_fontsize' , None )
1347
+ ylabel = plot_args .get ('ylabel' , 'Number of catalogs' )
1348
+ ylabel_fontsize = plot_args .get ('ylabel_fontsize' , None )
1349
+ text_fontsize = plot_args .get ('text_fontsize' , 14 )
1350
+ tight_layout = plot_args .get ('tight_layout' , True )
1351
+ percentile = plot_args .get ('percentile' , 95 )
1352
+ filename = plot_args .get ('filename' , None )
1353
+ bins = plot_args .get ('bins' , 'auto' )
1354
+ xy = plot_args .get ('xy' , (0.2 , 0.6 ))
1355
+
1246
1356
# handle plotting
1247
1357
if axes :
1248
1358
chained = True
1249
1359
else :
1250
1360
chained = False
1361
+
1251
1362
# supply fixed arguments to plots
1252
1363
# might want to add other defaults here
1253
- filename = plot_args .get ('filename' , None )
1254
1364
fixed_plot_args = {'obs_label' : evaluation_result .obs_name ,
1255
- 'sim_label' : evaluation_result .sim_name ,
1256
- 'xlabel' : 'Normalized pseudo likelihood' ,
1257
- 'ylabel' : 'Number of catalogs' }
1365
+ 'sim_label' : evaluation_result .sim_name }
1258
1366
plot_args .update (fixed_plot_args )
1259
- title = plot_args .get ('title' , 'Spatial Test' )
1260
- percentile = plot_args .get ('percentile' , 95 )
1367
+
1261
1368
ax = plot_histogram (evaluation_result .test_distribution , evaluation_result .observed_statistic ,
1262
1369
catalog = evaluation_result .obs_catalog_repr ,
1263
1370
plot_args = plot_args ,
1264
- bins = 'fd' ,
1371
+ bins = bins ,
1265
1372
axes = axes ,
1266
1373
percentile = percentile )
1267
1374
@@ -1271,18 +1378,22 @@ def plot_spatial_test(evaluation_result, axes=None, plot_args=None, show=True):
1271
1378
ax .annotate ('$\gamma = P(X \leq x) = {:.2f}$\n $\omega = {:.2f}$'
1272
1379
.format (evaluation_result .quantile , evaluation_result .observed_statistic ),
1273
1380
xycoords = 'axes fraction' ,
1274
- xy = ( 0.2 , 0.6 ) ,
1275
- fontsize = 14 )
1381
+ xy = xy ,
1382
+ fontsize = text_fontsize )
1276
1383
except TypeError :
1277
1384
# if both quantiles are provided, we want to plot the greater-equal quantile
1278
1385
ax .annotate ('$\gamma = P(X \leq x) = {:.2f}$\n $\omega = {:.2f}$'
1279
1386
.format (evaluation_result .quantile [1 ], evaluation_result .observed_statistic ),
1280
1387
xycoords = 'axes fraction' ,
1281
- xy = ( 0.2 , 0.6 ) ,
1282
- fontsize = 14 )
1388
+ xy = xy ,
1389
+ fontsize = text_fontsize )
1283
1390
1391
+ ax .set_title (title , fontsize = title_fontsize )
1392
+ ax .set_xlabel (xlabel , fontsize = xlabel_fontsize )
1393
+ ax .set_ylabel (ylabel , fontsize = ylabel_fontsize )
1284
1394
1285
- ax .set_title (title , fontsize = 14 )
1395
+ if tight_layout :
1396
+ ax .figure .tight_layout ()
1286
1397
1287
1398
if filename is not None :
1288
1399
ax .figure .savefig (filename + '.pdf' )
0 commit comments