Skip to content
/ matplotlib Public
  • Notifications You must be signed in to change notification settings
  • Fork 7.5k
  • Star 19.5k
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.

Sign up for GitHub

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

Jump to bottom

Boxplot: Median line too long after changing linewidth #19409

Closed
ghost opened this issue Jan 31, 2021 · 9 comments · Fixed by #26462
Closed

Boxplot: Median line too long after changing linewidth #19409

ghost opened this issue Jan 31, 2021 · 9 comments · Fixed by #26462
Labels
Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones!
Milestone
v3.8.0

Comments

@ghost
Copy link

ghost commented Jan 31, 2021

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?

@anntzer
Copy link
Contributor

anntzer commented Jan 31, 2021

I agree with changing the capstyle. As for the overlap at the edges, likely it's a zorder issue? #18216/ #17247 likely matter too.

@ghost
Copy link
Author

ghost commented Jan 31, 2021

Just another note: The mean (as opposed to median lines) do not seem to have the same issue:

data = [[1, 2, 3, 4, 7]]
fig, ax = plt.subplots()
ax.boxplot(data,
           showmeans=True,
           meanline=True,
           meanprops={"linewidth": 8})

gives me

where the length of the green mean line is fine. (The line is broken because that is the default mean line style.)

Edit: The mean line still overlaps the bounding box, but at least does not extend beyond it.

@ghost
Copy link
Author

ghost commented Jan 31, 2021

A symptomatic workaround for the overlapping issue would be to change

zdelta = 0.1

in this line to

zdelta = - 0.1

That resolves it for me.

As far as I can see, zdelta is only used for drawing mean and median lines, so changing that should be safe.

@tacaswell
Copy link
Member

tacaswell commented Jan 31, 2021

There are different cap styles for solid lines and dashed lines.

This is also a case where the re-scaling of the dash pattern with linewidth is not an improvement...

@oscargus
Copy link
Contributor

oscargus commented Jun 4, 2022

Zooming in gives that the zorder for the mean line indeed should be changed as well (as it is clear that there are different cap styles).

image

@oscargus oscargus added Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones! labels Jun 4, 2022
@oscargus
Copy link
Contributor

oscargus commented Jun 4, 2022

Should be a first good issue: change the default cap style and the zorder. Problems may involve testing.

@tacaswell tacaswell added this to the v3.7.0 milestone Jun 4, 2022
@wmandla
Copy link

wmandla commented Jun 23, 2022

Problems may involve testing.

I would like to make a small contribution in order to fix this issue. The solution has already been hinted above. This would be my first contribution and I am not quite clear on what is expected when testing the fix.

@wmandla wmandla mentioned this issue Jun 23, 2022
Boxplot: Median line is now bound within the box for all linewidths #23335
Closed
3 tasks
@TianzeMYou TianzeMYou mentioned this issue Dec 12, 2022
Boxplot: Median line is now bound within the box for all linewidths #24708
Closed
6 tasks
@ksunden ksunden modified the milestones: v3.7.0, v3.7.1 Feb 14, 2023
@QuLogic QuLogic modified the milestones: v3.7.1, v3.7.2 Mar 4, 2023
@QuLogic QuLogic modified the milestones: v3.7.2, v3.7.3 Jul 5, 2023
@rcomer rcomer mentioned this issue Jul 18, 2023
Boxplot: Median line too long after changing linewidth #26345
Closed
3 tasks
@kidkoder432
Copy link
Contributor

kidkoder432 commented Aug 7, 2023

There are different cap styles for solid lines and dashed lines.

Where are these defined? Maybe changing the default cap style would help.

@kidkoder432
Copy link
Contributor

kidkoder432 commented Aug 7, 2023

There are different cap styles for solid lines and dashed lines.

Where are these defined? Maybe changing the default cap style would help.

Nevermind, found it in lines.py:299

@kidkoder432 kidkoder432 mentioned this issue Aug 7, 2023
Boxplot fix median line extending past box boundaries #19409 #26462
Merged
2 tasks
@timhoffm timhoffm closed this as completed in #26462 Aug 21, 2023
@meeseeksmachine meeseeksmachine mentioned this issue Aug 21, 2023
Backport PR #26462 on branch v3.8.x (Boxplot fix median line extending past box boundaries #19409) #26568
Merged
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this issue Aug 21, 2023
@kidkoder432 @meeseeksmachine
Backport PR matplotlib#26462 : Boxplot fix median line extending past …
4ffe411
…box boundaries  matplotlib#19409
@QuLogic QuLogic modified the milestones: v3.7.3, v3.8.0 Aug 21, 2023
ksunden added a commit that referenced this issue Aug 21, 2023
…462-on-v3.8.x

Backport PR  #26462 on branch v3.8.x (Boxplot fix median line extending past box boundaries  #19409)
@ksunden ksunden mentioned this issue Sep 15, 2023
merge up v3.8.0 #26785
Merged
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

Boxplot fix median line extending past box boundaries #19409 kidkoder432/matplotlib
Boxplot: Median line is now bound within the box for all linewidths wmandla/matplotlib
7 participants
@tacaswell @QuLogic @anntzer @ksunden @oscargus @wmandla @kidkoder432

4617作文网男小孩起什么名字起名字五行木土名字农牧合作社起名梦见猴子周公解梦有关周易的书周易宝宝名字免费取名周易大师还有哪几位给自己的鸽舍起个什么名字百家姓免费起名烧烤摊起名字股票周易预测起名字什么轩起一个群名,关于朋友的邱姓男孩起名名字周易八卦算命入门抛硬币6次周易占卜男宝宝起名字典根据父母姓氏的起名给自己的瓷器店起个名字梦想三国之永恒之神破解版我要和你在一起歌名周易八卦是玄学吗老黄历免费算命生辰八字微信购物群起名字秦氏起名女孩名字起来个园林公司名字大全深圳八字算命四月出生的孩子起名三点水起名吉祥字大全属鼠人起名宜用哪些字作文淀粉肠小王子日销售额涨超10倍罗斯否认插足凯特王妃婚姻让美丽中国“从细节出发”清明节放假3天调休1天男子给前妻转账 现任妻子起诉要回网友建议重庆地铁不准乘客携带菜筐月嫂回应掌掴婴儿是在赶虫子重庆警方辟谣“男子杀人焚尸”国产伟哥去年销售近13亿新的一天从800个哈欠开始男孩疑遭霸凌 家长讨说法被踢出群高中生被打伤下体休学 邯郸通报男子持台球杆殴打2名女店员被抓19岁小伙救下5人后溺亡 多方发声单亲妈妈陷入热恋 14岁儿子报警两大学生合买彩票中奖一人不认账德国打算提及普京时仅用姓名山西省委原副书记商黎光被逮捕武汉大学樱花即将进入盛花期今日春分张家界的山上“长”满了韩国人?特朗普谈“凯特王妃P图照”王树国3次鞠躬告别西交大师生白宫:哈马斯三号人物被杀代拍被何赛飞拿着魔杖追着打315晚会后胖东来又人满为患了房客欠租失踪 房东直发愁倪萍分享减重40斤方法“重生之我在北大当嫡校长”槽头肉企业被曝光前生意红火手机成瘾是影响睡眠质量重要因素考生莫言也上北大硕士复试名单了妈妈回应孩子在校撞护栏坠楼网友洛杉矶偶遇贾玲呼北高速交通事故已致14人死亡西双版纳热带植物园回应蜉蝣大爆发男孩8年未见母亲被告知被遗忘张立群任西安交通大学校长恒大被罚41.75亿到底怎么缴沈阳一轿车冲入人行道致3死2伤奥运男篮美国塞尔维亚同组周杰伦一审败诉网易国标起草人:淀粉肠是低配版火腿肠外国人感慨凌晨的中国很安全男子被流浪猫绊倒 投喂者赔24万杨倩无缘巴黎奥运男子被猫抓伤后确诊“猫抓病”春分“立蛋”成功率更高?记者:伊万改变了国足氛围奥巴马现身唐宁街 黑色着装引猜测

4617作文网 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化