diff --git a/csep/core/regions.py b/csep/core/regions.py index 350d6cfc..934f148c 100644 --- a/csep/core/regions.py +++ b/csep/core/regions.py @@ -744,8 +744,15 @@ def tight_bbox(self): asc.insert(0, poly_min[0]) asc.insert(0, poly_min[1]) poly_max = self.polygons[int(row[argmax])].points - desc.append(poly_max[3]) - desc.append(poly_max[2]) + lat_0 = poly_max[2][1] + lat_1 = poly_max[3][1] + # last two points are 'right hand side of polygon' + if lat_0 < lat_1: + desc.append(poly_max[2]) + desc.append(poly_max[3]) + else: + desc.append(poly_max[3]) + desc.append(poly_max[2]) # close the loop poly = np.array(asc + desc) sorted_idx = np.sort(np.unique(poly, return_index=True, axis=0)[1], kind='stable') diff --git a/csep/utils/plots.py b/csep/utils/plots.py index 5c9aa5e8..05647b89 100644 --- a/csep/utils/plots.py +++ b/csep/utils/plots.py @@ -764,7 +764,8 @@ def size_map(markersize, values, scale): pts = catalog.region.tight_bbox() ax.plot(pts[:, 0], pts[:, 1], lw=1, color='black') except AttributeError: - print("unable to get tight bbox") + pass + # print("unable to get tight bbox") # Gridline options if grid: @@ -1295,7 +1296,7 @@ def plot_comparison_test(results_t, results_w=None, axes=None, plot_args=None): title = plot_args.get('title', 'CSEP1 Comparison Test') xlabel = plot_args.get('xlabel', 'X') ylabel = plot_args.get('ylabel', 'Y') - ylims = plot_args.get('ylims', (None, None)) + ylim = plot_args.get('ylim', (None, None)) capsize = plot_args.get('capsize', 2) linewidth = plot_args.get('linewidth', 1) markersize = plot_args.get('markersize', 2) @@ -1330,7 +1331,6 @@ def plot_comparison_test(results_t, results_w=None, axes=None, plot_args=None): facecolor = 'white' else: facecolor = 'white' - ax.plot(index, result_t.observed_statistic, marker='o', markerfacecolor=facecolor, markeredgecolor=color, markersize=markersize) 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): ax.set_ylabel(ylabel) ax.set_title(title) ax.yaxis.grid() - xTickPos, _ = pyplot.xticks() + xTickPos = ax.get_xticks() ax.yaxis.set_major_locator(matplotlib.ticker.MaxNLocator(integer=True)) - ax.set_ylim([ylims[0], ylims[1]]) - ax.set_xlim([ax.get_xlim()[0] + 0.5, ax.get_xlim()[1] - 0.5]) + ax.set_ylim([ylim[0], ylim[1]]) + ax.set_xlim([-0.5, len(results_t) - 0.5]) ax.bar(xTickPos, numpy.array([9999] * len(xTickPos)), bottom=-2000, width=(xTickPos[1] - xTickPos[0]), color=['gray', 'w'], alpha=0.2) fig.tight_layout() return ax - -def plot_poisson_consistency_test(eval_results, normalize=False, one_sided_lower=False, plot_args=None): +def plot_poisson_consistency_test(eval_results, normalize=False, one_sided_lower=False, axes=None, plot_args=None): """ Plots results from CSEP1 tests following the CSEP1 convention. 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 tight_layout = plot_args.get('tight_layout', True) percentile = plot_args.get('percentile', 95) - fig, ax = pyplot.subplots(figsize=figsize) + if axes is None: + fig, ax = pyplot.subplots(figsize=figsize) + else: + ax = axes + fig = ax.get_figure() + xlims = [] for index, res in enumerate(results): # handle analytical distributions first, they are all in the form ['name', parameters].