@@ -101,6 +101,7 @@ def plot_magnitude_versus_time(
101
101
max_size : int = 300 ,
102
102
power : int = 4 ,
103
103
alpha : float = 0.5 ,
104
+ reset_times : bool = False ,
104
105
ax : Optional [matplotlib .axes .Axes ] = None ,
105
106
show : bool = False ,
106
107
** kwargs : Any ,
@@ -118,6 +119,7 @@ def plot_magnitude_versus_time(
118
119
Defaults to `300`.
119
120
power (int, optional): Power scaling of the scatter sizing. Defaults to `4`.
120
121
alpha (float, optional): Transparency level for the scatter points. Defaults to `0.5`.
122
+ reset_times (bool): If True, x-axis shows time in days since first event.
121
123
ax (matplotlib.axes.Axes, optional): Axis object on which to plot. If not provided, a
122
124
new figure and axis are created. Defaults to `None`.
123
125
show (bool, optional): Whether to display the plot. Defaults to `False`.
@@ -149,8 +151,19 @@ def plot_magnitude_versus_time(
149
151
# Plot data
150
152
mag = catalog .data ["magnitude" ]
151
153
datetimes = catalog .get_datetimes ()
154
+
155
+ if reset_times :
156
+ # Convert to days since first event
157
+ SECONDS_PER_DAY = 86400
158
+ timestamps = numpy .array ([dt .timestamp () for dt in datetimes ])
159
+ xdata = (timestamps - timestamps [0 ]) / SECONDS_PER_DAY
160
+ xlabel = plot_args ["xlabel" ] or "Days since first event"
161
+ else :
162
+ xdata = datetimes
163
+ xlabel = plot_args ["xlabel" ] or "Datetime"
164
+
152
165
ax .scatter (
153
- datetimes ,
166
+ xdata ,
154
167
mag ,
155
168
marker = "o" ,
156
169
c = color ,
@@ -159,15 +172,16 @@ def plot_magnitude_versus_time(
159
172
)
160
173
161
174
# Set labels and title
162
- ax .set_xlabel (plot_args [ " xlabel" ] or "Datetime" , fontsize = plot_args ["xlabel_fontsize" ])
175
+ ax .set_xlabel (xlabel , fontsize = plot_args ["xlabel_fontsize" ])
163
176
ax .set_ylabel (plot_args ["ylabel" ] or "Magnitude" , fontsize = plot_args ["ylabel_fontsize" ])
164
177
ax .set_title (plot_args ["title" ], fontsize = plot_args ["title_fontsize" ])
165
178
166
179
# Autoformat ticks and labels
167
- ax .xaxis .set_major_locator (plot_args ["datetime_locator" ])
168
- ax .xaxis .set_major_formatter (plot_args ["datetime_formatter" ])
180
+ if not reset_times :
181
+ ax .xaxis .set_major_locator (plot_args ["datetime_locator" ])
182
+ ax .xaxis .set_major_formatter (plot_args ["datetime_formatter" ])
183
+ fig .autofmt_xdate ()
169
184
ax .grid (plot_args ["grid" ])
170
- fig .autofmt_xdate ()
171
185
172
186
if plot_args ["tight_layout" ]:
173
187
fig .tight_layout ()
@@ -177,7 +191,7 @@ def plot_magnitude_versus_time(
177
191
return ax
178
192
179
193
180
- def plot_cumulative_events_versus_time (
194
+ def _plot_cumulative_events_versus_time (
181
195
catalog_forecast : "CatalogForecast" ,
182
196
observation : "CSEPCatalog" ,
183
197
time_axis : str = "datetime" ,
@@ -232,7 +246,6 @@ def plot_cumulative_events_versus_time(
232
246
Returns:
233
247
matplotlib.axes.Axes: The Matplotlib axes object with the plotted data.
234
248
"""
235
-
236
249
# Initialize plot
237
250
plot_args = {** DEFAULT_PLOT_ARGS , ** kwargs }
238
251
fig , ax = pyplot .subplots (figsize = plot_args ["figsize" ]) if ax is None else (ax .figure , ax )
@@ -507,7 +520,7 @@ def get_histogram_synthetic_cat(x, mags, normed=True):
507
520
###############
508
521
# Spatial plots
509
522
###############
510
- def plot_basemap (
523
+ def _plot_basemap (
511
524
basemap : Optional [str ] = None ,
512
525
extent : Optional [List [float ]] = None ,
513
526
coastline : bool = True ,
@@ -887,7 +900,7 @@ def plot_gridded_dataset(
887
900
#####################
888
901
# Single Result plots
889
902
#####################
890
- def plot_distribution_test (
903
+ def plot_test_distribution (
891
904
evaluation_result : "EvaluationResult" ,
892
905
bins : Union [str , int , List [Any ]] = "fd" ,
893
906
percentile : Optional [int ] = 95 ,
@@ -1123,7 +1136,7 @@ def plot_calibration_test(
1123
1136
#####################
1124
1137
# Results batch plots
1125
1138
#####################
1126
- def plot_comparison_test (
1139
+ def _plot_comparison_test (
1127
1140
results_t : List ["EvaluationResult" ],
1128
1141
results_w : Optional [List ["EvaluationResult" ]] = None ,
1129
1142
percentile : int = 95 ,
@@ -1282,7 +1295,7 @@ def plot_comparison_test(
1282
1295
return ax
1283
1296
1284
1297
1285
- def plot_consistency_test (
1298
+ def _plot_consistency_test (
1286
1299
eval_results : Union [List ["EvaluationResult" ], "EvaluationResult" ],
1287
1300
normalize : bool = False ,
1288
1301
one_sided_lower : bool = False ,
@@ -1416,7 +1429,7 @@ def plot_consistency_test(
1416
1429
###################
1417
1430
# Alarm-based plots
1418
1431
###################
1419
- def plot_concentration_ROC_diagram (
1432
+ def _plot_concentration_ROC_diagram (
1420
1433
forecast : "GriddedForecast" ,
1421
1434
catalog : "CSEPCatalog" ,
1422
1435
linear : bool = True ,
@@ -1532,7 +1545,7 @@ def plot_concentration_ROC_diagram(
1532
1545
return ax
1533
1546
1534
1547
1535
- def plot_ROC_diagram (
1548
+ def _plot_ROC_diagram (
1536
1549
forecast : "GriddedForecast" ,
1537
1550
catalog : "CSEPCatalog" ,
1538
1551
linear : bool = True ,
@@ -1659,7 +1672,7 @@ def plot_ROC_diagram(
1659
1672
return ax
1660
1673
1661
1674
1662
- def plot_Molchan_diagram (
1675
+ def _plot_Molchan_diagram (
1663
1676
forecast : "GriddedForecast" ,
1664
1677
catalog : "CSEPCatalog" ,
1665
1678
linear : bool = True ,
@@ -2159,7 +2172,7 @@ def _annotate_distribution_plot(
2159
2172
2160
2173
if auto_annotate :
2161
2174
if evaluation_result .name == "Catalog N-Test" :
2162
- xlabel = "Event Count "
2175
+ xlabel = "Event Counts "
2163
2176
ylabel = "Number of Catalogs"
2164
2177
title = f"{ evaluation_result .name } : { evaluation_result .sim_name } "
2165
2178
annotation_xy = (0.5 , 0.3 )
@@ -2176,7 +2189,7 @@ def _annotate_distribution_plot(
2176
2189
)
2177
2190
2178
2191
elif evaluation_result .name == "Catalog S-Test" :
2179
- xlabel = "Normalized Spatial Statistic"
2192
+ xlabel = "Spatial Statistic"
2180
2193
ylabel = "Number of Catalogs"
2181
2194
title = f"{ evaluation_result .name } : { evaluation_result .sim_name } "
2182
2195
annotation_xy = (0.2 , 0.6 )
@@ -2187,7 +2200,7 @@ def _annotate_distribution_plot(
2187
2200
)
2188
2201
2189
2202
elif evaluation_result .name == "Catalog M-Test" :
2190
- xlabel = "Magnitude"
2203
+ xlabel = "Magnitude Statistic "
2191
2204
ylabel = "Number of Catalogs"
2192
2205
title = f"{ evaluation_result .name } : { evaluation_result .sim_name } "
2193
2206
annotation_xy = (0.55 , 0.6 )
@@ -2197,7 +2210,7 @@ def _annotate_distribution_plot(
2197
2210
f"$\\ omega = { evaluation_result .observed_statistic :.2f} $"
2198
2211
)
2199
2212
elif evaluation_result .name == "Catalog PL-Test" :
2200
- xlabel = "Likelihood"
2213
+ xlabel = "Pseudo- Likelihood"
2201
2214
ylabel = "Number of Catalogs"
2202
2215
title = f"{ evaluation_result .name } : { evaluation_result .sim_name } "
2203
2216
annotation_xy = (0.55 , 0.3 )
@@ -2411,3 +2424,26 @@ def _process_stat_distribution(
2411
2424
mean = numpy .mean (test_distribution )
2412
2425
2413
2426
return plow , phigh , mean , observed_statistic
2427
+
2428
+
2429
+ # Public export of function wrappers for backwards/legacy compatibility.
2430
+ from .plots_legacy import (plot_cumulative_events_versus_time ,
2431
+ plot_cumulative_events_versus_time_dev ,
2432
+ plot_histogram ,
2433
+ plot_ecdf ,
2434
+ plot_magnitude_histogram_dev ,
2435
+ plot_basemap ,
2436
+ plot_spatial_dataset ,
2437
+ plot_number_test ,
2438
+ plot_magnitude_test ,
2439
+ plot_distribution_test ,
2440
+ plot_likelihood_test ,
2441
+ plot_spatial_test ,
2442
+ plot_poisson_consistency_test ,
2443
+ plot_comparison_test ,
2444
+ plot_consistency_test ,
2445
+ plot_pvalues_and_intervals ,
2446
+ plot_concentration_ROC_diagram ,
2447
+ plot_ROC_diagram ,
2448
+ plot_Molchan_diagram )
2449
+
0 commit comments