Skip to content

Commit 81151a5

Browse files
committed
Add singular keyword options to indicate_error
1 parent a9e3e28 commit 81151a5

File tree

2 files changed

+43
-31
lines changed

2 files changed

+43
-31
lines changed

docs/1dplots.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,14 @@
205205
# `~matplotlib.axes.Axes.plot`, `~matplotlib.axes.Axes.scatter`,
206206
# `~matplotlib.axes.Axes.bar`, or `~matplotlib.axes.Axes.barh`.
207207
#
208-
# If you pass 2D arrays to these methods with ``means=True`` or
209-
# ``medians=True``, the means or medians of each column are drawn as points,
210-
# lines, or bars, and *error bars* or *shading* is drawn to represent the spread
211-
# of the distribution for each column. You can also specify the error bounds
212-
# *manually* with the `bardata`, `boxdata`, `shadedata`, and `fadedata` keywords.
208+
# If you pass 2D arrays to these methods with ``mean=True`` or ``median=True``,
209+
# the means or medians of each column are drawn as points, lines, or bars, and
210+
# *error bars* or *shading* is drawn to represent the spread of the distribution
211+
# for each column. You can also specify the error bounds *manually* with the
212+
# `bardata`, `boxdata`, `shadedata`, and `fadedata` keywords.
213213
# `~proplot.axes.indicate_error` can draw thin error bars with optional whiskers,
214-
# thick "boxes" overlayed on top of these bars (think of this as a miniature boxplot),
215-
# and up to 2 regions of shading. See `~proplot.axes.indicate_error` for details.
214+
# thick "boxes" overlayed on top of these bars (think of these as miniature boxplots),
215+
# and up to 2 layers of shading. See `~proplot.axes.indicate_error` for details.
216216

217217

218218
# %%
@@ -240,8 +240,8 @@
240240
ax = axs[0]
241241
obj = ax.barh(
242242
data, color='light red', legend=True,
243-
medians=True, barpctiles=90, boxpctiles=True,
244-
# medians=True, barpctiles=(5, 95), boxpctiles=(25, 75) # equivalent
243+
median=True, barpctile=90, boxpctile=True,
244+
# median=True, barpctile=(5, 95), boxpctile=(25, 75) # equivalent
245245
)
246246
ax.format(title='Column statistics')
247247
ax.format(ylabel='column number', title='Bar plot', ygrid=False)
@@ -251,8 +251,8 @@
251251
ax.scatter(
252252
data, color='denim', marker='x', markersize=8**2, linewidth=0.8, legend='ll',
253253
label='mean', shadelabel=True,
254-
means=True, shadestds=1,
255-
# means=True, shadestds=(-1, 1) # equivalent
254+
mean=True, shadestd=1,
255+
# mean=True, shadestd=(-1, 1) # equivalent
256256
)
257257
ax.format(title='Marker plot')
258258

proplot/axes/plot.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -546,13 +546,14 @@ def _auto_format_1d(
546546
# NOTE: Where columns represent distributions, like for box and violin plots or
547547
# where we use 'means' or 'medians', columns coords (axis 1) are 'x' coords.
548548
# Otherwise, columns represent e.g. lines, and row coords (axis 0) are 'x' coords.
549-
xaxis = int(box or hist or kwargs.get('means') or kwargs.get('medians') or False)
549+
reduce = any(kwargs.get(s) for s in ('mean', 'means', 'median', 'medians'))
550+
sx = int(box or hist or reduce or False)
550551
if hist:
551552
if labels is None:
552-
labels = _get_labels(ys[0], axis=xaxis, always=False) # hist labels
553+
labels = _get_labels(ys[0], axis=sx, always=False) # hist labels
553554
else:
554555
if x is None:
555-
x = _get_labels(ys[0], axis=xaxis) # infer from rows or columns
556+
x = _get_labels(ys[0], axis=sx) # infer from rows or columns
556557
x = _to_arraylike(x)
557558

558559
# The labels and XY axis settings
@@ -1185,10 +1186,11 @@ def _get_error_data(
11851186
@_deprecate_add_errorbars
11861187
def indicate_error(
11871188
self, func, *args,
1188-
medians=False, means=False,
1189-
boxdata=None, bardata=None, shadedata=None, fadedata=None,
1190-
boxstds=None, barstds=None, shadestds=None, fadestds=None,
1191-
boxpctiles=None, barpctiles=None, shadepctiles=None, fadepctiles=None,
1189+
mean=None, means=None, median=None, medians=None,
1190+
barstd=None, barstds=None, barpctile=None, barpctiles=None, bardata=None,
1191+
boxstd=None, boxstds=None, boxpctile=None, boxpctiles=None, boxdata=None,
1192+
shadestd=None, shadestds=None, shadepctile=None, shadepctiles=None, shadedata=None,
1193+
fadestd=None, fadestds=None, fadepctile=None, fadepctiles=None, fadedata=None,
11921194
boxmarker=None, boxmarkercolor='white',
11931195
boxcolor=None, barcolor=None, shadecolor=None, fadecolor=None,
11941196
shadelabel=False, fadelabel=False, shadealpha=0.4, fadealpha=0.2,
@@ -1211,27 +1213,27 @@ def indicate_error(
12111213
----------
12121214
*args
12131215
The input data.
1214-
means : bool, optional
1216+
mean, means : bool, optional
12151217
Whether to plot the means of each column in the input data. If no other
1216-
arguments specified, this also sets ``barstds=True`` (and ``boxstds=True``
1218+
arguments specified, this also sets ``barstd=True`` (and ``boxstd=True``
12171219
for violin plots).
1218-
medians : bool, optional
1220+
median, medians : bool, optional
12191221
Whether to plot the medians of each column in the input data. If no other
1220-
arguments specified, this also sets ``barstds=True`` (and ``boxstds=True``
1222+
arguments specified, this also sets ``barstd=True`` (and ``boxstd=True``
12211223
for violin plots).
12221224
vert : bool, optional
12231225
If ``False``, error data is drawn horizontally rather than vertially. Set
12241226
automatically by methods like `bar`, `barh`, `area`, and `areax`.
12251227
orientation : {{None, 'vertical', 'horizontal'}}, optional
12261228
Alternative to the `vert` keyword arg. If ``'horizontal'``, error data is
12271229
drawn horizontally rather than vertically.
1228-
barstds : float, (float, float), or bool, optional
1230+
barstd, barstds : float, (float, float), or bool, optional
12291231
Standard deviation multiples for *thin error bars* with optional whiskers
12301232
(i.e. caps). If scalar, then +/- that number is used. If ``True``, the
12311233
default of +/-3 standard deviations is used. This argument is only valid
12321234
if `means` or `medians` is ``True``.
1233-
barpctiles : float, (float, float) or bool, optional
1234-
As with `barstds`, but instead using *percentiles* for the error bars. The
1235+
barpctile, barpctiles : float, (float, float) or bool, optional
1236+
As with `barstd`, but instead using *percentiles* for the error bars. The
12351237
percentiles are calculated with `numpy.percentile`. If scalar, that width
12361238
surrounding the 50th percentile is used (e.g. ``90`` shows the 5th to 95th
12371239
percentiles). If ``True``, the default percentile range of 0 to 100 is
@@ -1242,21 +1244,21 @@ def indicate_error(
12421244
points. This should be used if `means` and `medians` are both ``False`` (i.e.
12431245
you did not provide dataset columns from which statistical properties can be
12441246
calculated automatically).
1245-
boxstds, boxpctiles, boxdata : optional
1246-
As with `barstds`, `barpctiles`, and `bardata`, but for *thicker error bars*
1247+
boxstd, boxstds, boxpctile, boxpctiles, boxdata : optional
1248+
As with `barstd`, `barpctile`, and `bardata`, but for *thicker error bars*
12471249
representing a smaller interval than the thin error bars. If `boxstds` is
12481250
``True``, the default standard deviation range of +/-1 is used. If `boxpctiles`
12491251
is ``True``, the default percentile range of 25 to 75 is used (i.e. the
12501252
interquartile range). When "boxes" and "bars" are combined, this has the effect
12511253
of drawing miniature box-and-whisker plots.
1252-
shadestds, shadepctiles, shadedata : optional
1253-
As with `barstds`, `barpctiles`, and `bardata`, but using *shading* to indicate
1254+
shadestd, shadestds, shadepctile, shadepctiles, shadedata : optional
1255+
As with `barstd`, `barpctile`, and `bardata`, but using *shading* to indicate
12541256
the error range. If `shadestds` is ``True``, the default standard deviation
12551257
range of +/-2 is used. If `shadepctiles` is ``True``, the default
12561258
percentile range of 10 to 90 is used. Shading is generally useful for
12571259
`~matplotlib.axes.Axes.plot` plots.
1258-
fadestds, fadepctiles, fadedata : optional
1259-
As with `shadestds`, `shadepctiles`, and `shadedata`, but for an additional,
1260+
fadestd, fadestds, fadepctile, fadepctiles, fadedata : optional
1261+
As with `shadestd`, `shadepctile`, and `shadedata`, but for an additional,
12601262
more faded, *secondary* shaded region. If `fadestds` is ``True``, the default
12611263
standard deviation range of +/-3 is used. If `fadepctiles` is ``True``,
12621264
the default percentile range of 0 to 100 is used.
@@ -1291,6 +1293,16 @@ def indicate_error(
12911293
bar = name in ('bar',)
12921294
violin = name in ('violinplot',)
12931295
plot = name in ('plot', 'scatter')
1296+
means = _not_none(mean=mean, means=means)
1297+
medians = _not_none(median=median, medians=medians)
1298+
barstds = _not_none(barstd=barstd, barstds=barstds)
1299+
boxstds = _not_none(boxstd=boxstd, boxstds=boxstds)
1300+
shadestds = _not_none(shadestd=shadestd, shadestds=shadestds)
1301+
fadestds = _not_none(fadestd=fadestd, fadestds=fadestds)
1302+
barpctiles = _not_none(barpctile=barpctile, barpctiles=barpctiles)
1303+
boxpctiles = _not_none(boxpctile=boxpctile, boxpctiles=boxpctiles)
1304+
shadepctiles = _not_none(shadepctile=shadepctile, shadepctiles=shadepctiles)
1305+
fadepctiles = _not_none(fadepctile=fadepctile, fadepctiles=fadepctiles)
12941306
bars = any(_ is not None for _ in (bardata, barstds, barpctiles))
12951307
boxes = any(_ is not None for _ in (boxdata, boxstds, boxpctiles))
12961308
shade = any(_ is not None for _ in (shadedata, shadestds, shadepctiles))

0 commit comments

Comments
 (0)