Skip to content

Commit fe858e5

Browse files
authored
contains hotfixes for plotting utilities (#133)
* hotfixes for plotting utilities * fixed issue where border was drawn incorrectly * supressed std out message if unable to obtain region_border * axes can be chained for plot_consistency_test_result * grab xticks from axes correly in plot_comparison_test * properly adjust xlim in plot_comparison_test * try to determine which points to plot based on latitude values
1 parent 4195021 commit fe858e5

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

csep/core/regions.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,15 @@ def tight_bbox(self):
744744
asc.insert(0, poly_min[0])
745745
asc.insert(0, poly_min[1])
746746
poly_max = self.polygons[int(row[argmax])].points
747-
desc.append(poly_max[3])
748-
desc.append(poly_max[2])
747+
lat_0 = poly_max[2][1]
748+
lat_1 = poly_max[3][1]
749+
# last two points are 'right hand side of polygon'
750+
if lat_0 < lat_1:
751+
desc.append(poly_max[2])
752+
desc.append(poly_max[3])
753+
else:
754+
desc.append(poly_max[3])
755+
desc.append(poly_max[2])
749756
# close the loop
750757
poly = np.array(asc + desc)
751758
sorted_idx = np.sort(np.unique(poly, return_index=True, axis=0)[1], kind='stable')

csep/utils/plots.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,8 @@ def size_map(markersize, values, scale):
764764
pts = catalog.region.tight_bbox()
765765
ax.plot(pts[:, 0], pts[:, 1], lw=1, color='black')
766766
except AttributeError:
767-
print("unable to get tight bbox")
767+
pass
768+
# print("unable to get tight bbox")
768769

769770
# Gridline options
770771
if grid:
@@ -1295,7 +1296,7 @@ def plot_comparison_test(results_t, results_w=None, axes=None, plot_args=None):
12951296
title = plot_args.get('title', 'CSEP1 Comparison Test')
12961297
xlabel = plot_args.get('xlabel', 'X')
12971298
ylabel = plot_args.get('ylabel', 'Y')
1298-
ylims = plot_args.get('ylims', (None, None))
1299+
ylim = plot_args.get('ylim', (None, None))
12991300
capsize = plot_args.get('capsize', 2)
13001301
linewidth = plot_args.get('linewidth', 1)
13011302
markersize = plot_args.get('markersize', 2)
@@ -1330,7 +1331,6 @@ def plot_comparison_test(results_t, results_w=None, axes=None, plot_args=None):
13301331
facecolor = 'white'
13311332
else:
13321333
facecolor = 'white'
1333-
13341334
ax.plot(index, result_t.observed_statistic, marker='o', markerfacecolor=facecolor, markeredgecolor=color, markersize=markersize)
13351335

13361336
ax.set_xticklabels([res.sim_name[0] for res in results_t], rotation=90)
@@ -1339,18 +1339,17 @@ def plot_comparison_test(results_t, results_w=None, axes=None, plot_args=None):
13391339
ax.set_ylabel(ylabel)
13401340
ax.set_title(title)
13411341
ax.yaxis.grid()
1342-
xTickPos, _ = pyplot.xticks()
1342+
xTickPos = ax.get_xticks()
13431343
ax.yaxis.set_major_locator(matplotlib.ticker.MaxNLocator(integer=True))
1344-
ax.set_ylim([ylims[0], ylims[1]])
1345-
ax.set_xlim([ax.get_xlim()[0] + 0.5, ax.get_xlim()[1] - 0.5])
1344+
ax.set_ylim([ylim[0], ylim[1]])
1345+
ax.set_xlim([-0.5, len(results_t) - 0.5])
13461346
ax.bar(xTickPos, numpy.array([9999] * len(xTickPos)), bottom=-2000,
13471347
width=(xTickPos[1] - xTickPos[0]), color=['gray', 'w'], alpha=0.2)
13481348
fig.tight_layout()
13491349

13501350
return ax
13511351

1352-
1353-
def plot_poisson_consistency_test(eval_results, normalize=False, one_sided_lower=False, plot_args=None):
1352+
def plot_poisson_consistency_test(eval_results, normalize=False, one_sided_lower=False, axes=None, plot_args=None):
13541353
""" Plots results from CSEP1 tests following the CSEP1 convention.
13551354
13561355
Note: All of the evaluations should be from the same type of evaluation, otherwise the results will not be
@@ -1404,7 +1403,12 @@ def plot_poisson_consistency_test(eval_results, normalize=False, one_sided_lower
14041403
tight_layout = plot_args.get('tight_layout', True)
14051404
percentile = plot_args.get('percentile', 95)
14061405

1407-
fig, ax = pyplot.subplots(figsize=figsize)
1406+
if axes is None:
1407+
fig, ax = pyplot.subplots(figsize=figsize)
1408+
else:
1409+
ax = axes
1410+
fig = ax.get_figure()
1411+
14081412
xlims = []
14091413
for index, res in enumerate(results):
14101414
# handle analytical distributions first, they are all in the form ['name', parameters].

0 commit comments

Comments
 (0)