Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7e44d70

Browse files
phobsonQuLogic
authored andcommitted
FIX: don't compute flier positions if not showing
Closes GH #7263 Fliers are documented as being optional when showfliers=False. However the Axes.bxp method was trying to compute the x-values of the flier artists based on the length of the flier array before the logic to draw them.
1 parent e614026 commit 7e44d70

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3723,9 +3723,6 @@ def dopatch(xs, ys, **kwargs):
37233723
for pos, width, stats in zip(positions, widths, bxpstats):
37243724
# try to find a new label
37253725
datalabels.append(stats.get('label', pos))
3726-
# fliers coords
3727-
flier_x = np.ones(len(stats['fliers'])) * pos
3728-
flier_y = stats['fliers']
37293726

37303727
# whisker coords
37313728
whisker_x = np.ones(2) * pos
@@ -3799,6 +3796,10 @@ def dopatch(xs, ys, **kwargs):
37993796

38003797
# maybe draw the fliers
38013798
if showfliers:
3799+
# fliers coords
3800+
flier_x = np.ones(len(stats['fliers'])) * pos
3801+
flier_y = stats['fliers']
3802+
38023803
fliers.extend(doplot(
38033804
flier_x, flier_y, **final_flierprops
38043805
))

lib/matplotlib/tests/test_axes.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,23 @@ def test_bxp_nobox():
17131713
ax.bxp(logstats, showbox=False)
17141714

17151715

1716+
@image_comparison(baseline_images=['bxp_no_flier_stats'],
1717+
remove_text=True, extensions=['png'],
1718+
savefig_kwarg={'dpi': 40},
1719+
style='default')
1720+
def test_bxp_no_flier_stats():
1721+
np.random.seed(937)
1722+
logstats = matplotlib.cbook.boxplot_stats(
1723+
np.random.lognormal(mean=1.25, sigma=1., size=(37, 4))
1724+
)
1725+
for ls in logstats:
1726+
ls.pop('fliers', None)
1727+
1728+
fig, ax = plt.subplots()
1729+
ax.set_yscale('log')
1730+
ax.bxp(logstats, showfliers=False)
1731+
1732+
17161733
@image_comparison(baseline_images=['bxp_withmean_point'],
17171734
remove_text=True, extensions=['png'],
17181735
savefig_kwarg={'dpi': 40},

0 commit comments

Comments
 (0)