Skip to content

Commit fcb41da

Browse files
MosesStewartjmshapirrcalvo12
authored
PR For #24: text alignment (#25)
* implemnts changs for #24 * updatees version for #24 * reemoves test code for #24 * fixes approx plots for #24 * Update src/BootstrapReport/main.py Co-authored-by: jmshapir <[email protected]> * #24 Adding axis labels to crossing plots * #24 Making box equidistant from bottom and side * offsetbox for #24 --------- Co-authored-by: jmshapir <[email protected]> Co-authored-by: Richard Calvo <[email protected]>
1 parent 70802a9 commit fcb41da

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "BootstrapReport"
7-
version = "3.0.0"
7+
version = "3.0.1"
88
authors = [
99
{name = "Jesse Shapiro", email = "[email protected]"},
1010
{name = "Isaiah Andrews", email = "[email protected]"}

src/BootstrapReport/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .main import ObjectOfInterest
22
from . import helpers
3-
__version__ = "3.0.0"
3+
__version__ = "3.0.1"
44
__all__ = []
55

66
"""

src/BootstrapReport/helpers.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from scipy import integrate, stats
55
from matplotlib import pyplot as plt
66
import matplotlib as mpl
7+
from matplotlib import offsetbox
78
from . import checkers
89

910
def get_nested_list(num_sublists) -> list:
@@ -271,7 +272,10 @@ def plot_min_crossings(optimal_path, crossings, alpha, replicates, estimate, std
271272
ax.hlines(y = botbound, xmin = replicates[0], xmax = replicates[-1], color = 'k', lw = 2)
272273
ax.hlines(y = botbound, xmin = replicates[-1], xmax = rbound, color = 'k', lw = 2, linestyle = (1.5, (1.5, 1)))
273274
ax.fill_between(x_axis, lower_band, upper_band, color = plt_set['bandcolor'], label = 'Confidence band', alpha = 0.25)
275+
ax.set_xlabel("Value of object of interest")
276+
ax.set_ylabel("Difference in CDFs")
274277
ax.legend(edgecolor = 'k', loc = 'upper left')
275-
ax.text(rbound - 0.04 * (rbound - lbound), botbound + 0.07 * (topbound - botbound), plot_data,
276-
fontsize = plt_set['legend_fontsize'], verticalalignment = 'bottom', horizontalalignment='right', bbox = props)
278+
offbox = offsetbox.AnchoredText(plot_data, loc = "lower right", borderpad = 1.25, pad = 0)
279+
offbox.patch.set(**props)
280+
ax.add_artist(offbox)
277281
return fig

src/BootstrapReport/main.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" Main file of the package """
2-
import numpy as np
2+
import numpy as np, matplotlib as mpl
33
from matplotlib import pyplot as plt
4-
import matplotlib as mpl
4+
from matplotlib import offsetbox
55
from scipy.stats import norm
66
from scipy.optimize import minimize
77
import warnings
@@ -110,7 +110,7 @@ def get_crossings(self, alpha = 0.05, outfile = None, **kwargs):
110110
:param alpha: 1 - alpha = confidence level for confidence bands
111111
:param outfile: path to output figure displaying algorithm
112112
"""
113-
plt_set = {'fontsize': 18, 'legend_fontsize': 20, 'labelsize': 28, 'linecolor': '#f9665e', 'bandcolor': '#a8d9ed', 'linewidth': 2, 'dpi': 100}
113+
plt_set = {'fontsize': 19, 'legend_fontsize': 20, 'labelsize': 28, 'linecolor': '#f9665e', 'bandcolor': '#a8d9ed', 'linewidth': 2, 'dpi': 100}
114114
for key, value in kwargs.items():
115115
plt_set[key] = value
116116

@@ -184,7 +184,7 @@ def pp_plot(self, confidence_band = True, alpha = 0.05, outfile = None, **kwargs
184184
:param alpha: the upper bound for the probability that an ecdf plot of the normal
185185
approximation falls outside the shaded region
186186
"""
187-
plt_set = {'fontsize': 18, 'legend_fontsize': 20, 'labelsize': 28, 'pointsize': 7, 'pointcolor': '#f9665e', 'bandcolor': '#a8d9ed', 'dpi': 100}
187+
plt_set = {'fontsize': 19, 'legend_fontsize': 20, 'labelsize': 28, 'pointsize': 7, 'pointcolor': '#f9665e', 'bandcolor': '#a8d9ed', 'dpi': 100}
188188
for key, value in kwargs.items():
189189
plt_set[key] = value
190190

@@ -203,26 +203,26 @@ def pp_plot(self, confidence_band = True, alpha = 0.05, outfile = None, **kwargs
203203
('Num. replicates = %d' % num_replicates,
204204
'Pos. distance = %.3f' % self.pos_dist,
205205
'Neg. distance = %.3f' % self.neg_dist))
206-
props = dict(boxstyle = 'round, pad = 0.75, rounding_size = 0.3', facecolor = 'white', alpha = 0.86)
206+
props = dict(boxstyle = 'round, pad = 0.75, rounding_size = 0.3', facecolor = 'white', alpha = 0.8)
207207

208208
plt.rc('font', size = plt_set['fontsize'])
209209
plt.rc('legend', fontsize = plt_set['legend_fontsize'])
210210
plt.rc('axes', labelsize = plt_set['labelsize'])
211211
fig, ax = plt.subplots(figsize = (10, 10))
212+
ax.set_ylim(0, 1)
213+
ax.set_xlim(0, 1)
212214

213215
if confidence_band == True:
214216
ax.fill_between(dkw_xgrid, dkw_lbound, dkw_ubound, color = plt_set['bandcolor'], label = 'Confidence band', alpha = 0.35)
215217
ax.scatter(replicates_eval_normcdf, replicate_ecdf, s = plt_set['pointsize'],
216-
c = plt_set['pointcolor'], label='Bootstrap replicates')
218+
c = plt_set['pointcolor'], label='Bootstrap reps.')
217219
ax.set_xlabel("CDF of normal distribution")
218220
ax.set_ylabel("CDF of bootstrap distribution")
219221
ax.legend(edgecolor = 'k', loc = 'upper left')
220222
ax.axline((0, 0), (1, 1), color="black", linestyle=(0, (5, 5)))
221-
ax.text(0.52, 0.06, plot_data, fontsize = plt_set['legend_fontsize'], \
222-
verticalalignment = 'bottom', horizontalalignment='left', bbox = props)
223-
ax.set_ylim(0, 1)
224-
ax.set_xlim(0, 1)
225-
223+
offbox = offsetbox.AnchoredText(plot_data, loc = "lower right", borderpad = 1.25, pad = 0)
224+
offbox.patch.set(**props)
225+
ax.add_artist(offbox)
226226
if not outfile == None:
227227
fig.savefig(outfile, transparent = True, dpi = plt_set['dpi'])
228228
return fig

0 commit comments

Comments
 (0)