8000 Better default behavior for boxplots when rcParams['lines.marker'] is set by pharshalp · Pull Request #15798 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Better default behavior for boxplots when rcParams['lines.marker'] is set #15798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
8000
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3910,10 +3910,13 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,

zdelta = 0.1

def line_props_with_rcdefaults(subkey, explicit, zdelta=0):
def line_props_with_rcdefaults(subkey, explicit, zdelta=0,
use_marker=True):
d = {k.split('.')[-1]: v for k, v in rcParams.items()
if k.startswith(f'boxplot.{subkey}')}
d['zorder'] = zorder + zdelta
if not use_marker:
d['marker'] = ''
if explicit is not None:
d.update(
cbook.normalize_kwargs(explicit, mlines.Line2D._alias_map))
Expand All @@ -3934,15 +3937,16 @@ def line_props_with_rcdefaults(subkey, explicit, zdelta=0):
cbook.normalize_kwargs(
boxprops, mpatches.PathPatch._alias_map))
else:
final_boxprops = line_props_with_rcdefaults('boxprops', boxprops)
final_boxprops = line_props_with_rcdefaults('boxprops', boxprops,
use_marker=False)
final_whiskerprops = line_props_with_rcdefaults(
'whiskerprops', whiskerprops)
'whiskerprops', whiskerprops, use_marker=False)
final_capprops = line_props_with_rcdefaults(
'capprops', capprops)
'capprops', capprops, use_marker=False)
final_flierprops = line_props_with_rcdefaults(
'flierprops', flierprops)
final_medianprops = line_props_with_rcdefaults(
'medianprops', medianprops, zdelta)
'medianprops', medianprops, zdelta, use_marker=False)
final_meanprops = line_props_with_rcdefaults(
'meanprops', meanprops, zdelta)
removed_prop = 'marker' if meanline else 'linestyle'
Expand Down
18 changes: 18 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2701,6 +2701,24 @@ def test_boxplot_bad_ci_2():
ax.boxplot([x, x], conf_intervals=[[1, 2], [1]])


def test_boxplot_marker_behavior():
plt.rcParams['lines.marker'] = 's'
plt.rcParams['boxplot.flierprops.marker'] = 'o'
plt.rcParams['boxplot.meanprops.marker'] = '^'
fig, ax = plt.subplots()
test_data = np.arange(100)
test_data[-1] = 150 # a flier point
bxp_handle = ax.boxplot(test_data, showmeans=True)
for bxp_lines in ['whiskers', 'caps', 'boxes', 'medians']:
Copy link
Contributor Author
@pharshalp pharshalp Dec 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you test the kwarg?

@jklymak yes, it gets checked (for 'whiskers', 'caps', 'boxes', 'medians') when the line markers are forced to '' irrespective of what the rcParams['lines.marker'] says (explicitly set to 's' in this test). [This implicitly tests use_marker=False].

    for bxp_lines in ['whiskers', 'caps', 'boxes', 'medians']:
        for each_line in bxp_handle[bxp_lines]:
            # Ensure that the rcParams['lines.marker'] is overridden by ''
            assert each_line.get_marker() == ''

I am also checking that the markers are allowed for fliers and means (and not forced to ''). [This implicitly tests use_marker=True].

    # Ensure that markers for fliers and means aren't overridden with ''
    assert bxp_handle['fliers'][0].get_marker() == 'o'
    assert bxp_handle['means'][0].get_marker() == '^'

for each_line in bxp_handle[bxp_lines]:
# Ensure that the rcParams['lines.marker'] is overridden by ''
assert each_line.get_marker() == ''

# Ensure that markers for fliers and means aren't overridden with ''
assert bxp_handle['fliers'][0].get_marker() == 'o'
assert bxp_handle['means'][0].get_marker() == '^'


@image_comparison(['boxplot_mod_artists_after_plotting.png'],
remove_text=True, savefig_kwarg={'dpi': 40}, style='default')
def test_boxplot_mod_artist_after_plotting():
Expand Down
0