8000 Merge pull request #15798 from pharshalp/boxplots_line_markers · matplotlib/matplotlib@29a1afe · GitHub
[go: up one dir, main page]

Skip to content

Commit 29a1afe

Browse files
authored
Merge pull request #15798 from pharshalp/boxplots_line_markers
Better default behavior for boxplots when rcParams['lines.marker'] is set
2 parents f842e9f + 6fceb05 commit 29a1afe

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3876,10 +3876,13 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
38763876

38773877
zdelta = 0.1
38783878

3879-
def line_props_with_rcdefaults(subkey, explicit, zdelta=0):
3879+
def line_props_with_rcdefaults(subkey, explicit, zdelta=0,
3880+
use_marker=True):
38803881
d = {k.split('.')[-1]: v for k, v in rcParams.items()
38813882
if k.startswith(f'boxplot.{subkey}')}
38823883
d['zorder'] = zorder + zdelta
3884+
if not use_marker:
3885+
d['marker'] = ''
38833886
if explicit is not None:
38843887
d.update(
38853888
cbook.normalize_kwargs(explicit, mlines.Line2D._alias_map))
@@ -3900,15 +3903,16 @@ def line_props_with_rcdefaults(subkey, explicit, zdelta=0):
39003903
cbook.normalize_kwargs(
39013904
boxprops, mpatches.PathPatch._alias_map))
39023905
else:
3903-
final_boxprops = line_props_with_rcdefaults('boxprops', boxprops)
3906+
final_boxprops = line_props_with_rcdefaults('boxprops', boxprops,
3907+
use_marker=False)
39043908
final_whiskerprops = line_props_with_rcdefaults(
3905-
'whiskerprops', whiskerprops)
3909+
'whiskerprops', whiskerprops, use_marker=False)
39063910
final_capprops = line_props_with_rcdefaults(
3907-
'capprops', capprops)
3911+
'capprops', capprops, use_marker=False)
39083912
final_flierprops = line_props_with_rcdefaults(
39093913
'flierprops', flierprops)
39103914
final_medianprops = line_props_with_rcdefaults(
3911-
'medianprops', medianprops, zdelta)
3915+
'medianprops', medianprops, zdelta, use_marker=False)
39123916
final_meanprops = line_props_with_rcdefaults(
39133917
'meanprops', meanprops, zdelta)
39143918
removed_prop = 'marker' if meanline else 'linestyle'

lib/matplotlib/tests/test_axes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,6 +2701,24 @@ def test_boxplot_bad_ci_2():
27012701
ax.boxplot([x, x], conf_intervals=[[1, 2], [1]])
27022702

27032703

2704+
def test_boxplot_marker_behavior():
2705+
plt.rcParams['lines.marker'] = 's'
2706+
plt.rcParams['boxplot.flierprops.marker'] = 'o'
2707+
plt.rcParams['boxplot.meanprops.marker'] = '^'
2708+
fig, ax = plt.subplots()
2709+
test_data = np.arange(100)
2710+
test_data[-1] = 150 # a flier point
2711+
bxp_handle = ax.boxplot(test_data, showmeans=True)
2712+
for bxp_lines in ['whiskers', 'caps', 'boxes', 'medians']:
2713+
for each_line in bxp_handle[bxp_lines]:
2714+
# Ensure that the rcParams['lines.marker'] is overridden by ''
2715+
assert each_line.get_marker() == ''
2716+
2717+
# Ensure that markers for fliers and means aren't overridden with ''
2718+
assert bxp_handle['fliers'][0].get_marker() == 'o'
2719+
assert bxp_handle['means'][0].get_marker() == '^'
2720+
2721+
27042722
@image_comparison(['boxplot_mod_artists_after_plotting.png'],
27052723
remove_text=True, savefig_kwarg={'dpi': 40}, style='default')
27062724
def test_boxplot_mod_artist_after_plotting():

0 commit comments

Comments
 (0)
0