8000 added a new argument use_marker=True to fix the issue with line marke… · matplotlib/matplotlib@6fceb05 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6fceb05

Browse files
committed
added a new argument use_marker=True to fix the issue with line markers showing up on boxplots. added a test.
1 parent e240493 commit 6fceb05

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
@@ -3910,10 +3910,13 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
39103910

39113911
zdelta = 0.1
39123912

3913-
def line_props_with_rcdefaults(subkey, explicit, zdelta=0):
3913+
def line_props_with_rcdefaults(subkey, explicit, zdelta=0,
3914+
use_marker=True):
39143915
d = {k.split('.')[-1]: v for k, v in rcParams.items()
39153916
if k.startswith(f'boxplot.{subkey}')}
39163917
d['zorder'] = zorder + zdelta
3918+
if not use_marker:
3919+
d['marker'] = ''
39173920
if explicit is not None:
39183921
d.update(
39193922
cbook.normalize_kwargs(explicit, mlines.Line2D._alias_map))
@@ -3934,15 +3937,16 @@ def line_props_with_rcdefaults(subkey, explicit, zdelta=0):
39343937
cbook.normalize_kwargs(
39353938
boxprops, mpatches.PathPatch._alias_map))
39363939
else:
3937-
final_boxprops = line_props_with_rcdefaults('boxprops', boxprops)
3940+
final_boxprops = line_props_with_rcdefaults('boxprops', boxprops,
3941+
use_marker=False)
39383942
final_whiskerprops = line_props_with_rcdefaults(
3939-
'whiskerprops', whiskerprops)
3943+
'whiskerprops', whiskerprops, use_marker=False)
39403944
final_capprops = line_props_with_rcdefaults(
3941-
'capprops', capprops)
3945+
'capprops', capprops, use_marker=False)
39423946
final_flierprops = line_props_with_rcdefaults(
39433947
'flierprops', flierprops)
39443948
final_medianprops = line_props_with_rcdefaults(
3945-
'medianprops', medianprops, zdelta)
3949+
'medianprops', medianprops, zdelta, use_marker=False)
39463950
final_meanprops = line_props_with_rcdefaults(
39473951
'meanprops', meanprops, zdelta)
39483952
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