Skip to content

Boxplot: Median line too long after changing linewidth #19409

Closed
@ghost

Description

When changing the linewidth property of the median line in boxplots, the line will extend beyond the box width.

For example,

import matplotlib.pyplot as plt

data = [[1, 2, 3, 4, 5]]
fig, ax = plt.subplots()
ax.boxplot(data,
           medianprops={"linewidth": 8})

gives (on Matplotlib 3.2.2):

By simply chaning the solid_capstyle propery to "butt" in

ax.boxplot(data,
           medianprops={"linewidth": 8,
                        "solid_capstyle": "butt"})

I was able to improve this a bit (I stole that trick from here):

Ideally, one could now reduce the median line length such that it no longer overlaps with the black bounding line of the box.
Since the box line width is only accessible in "points" units, it would need to be transformed to data units.
I was unable to get this to work, though.

Would it be possible/desirable to change the default setting for solid_capstyle?
Could this be handled in a different way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesGood first issueOpen a pull request against these issues if there are no active ones!

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions