简体   繁体   中英

Seaborn boxplot and regplot shifted

When I set the boxplot and regplot in one chart, I get a shifted regression chart along the x-axis. When I plot it separately, everything is fine. How to fix it?

import seaborn as sns 
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.boxplot(x="size", y="tip", data=tips)
sns.regplot(x="size", y="tip", data=tips, scatter=False)
plt.show()

在此处输入图像描述

Package versions:
'seaborn', '0.10.0'
'matplotlib', '3.2.1'

Python: 3.7.7

I too have this problem: This is the result when running the above code

This issue is also called out on another post: Seaborn: linear regression on top of a boxplot

Package versions: 'seaborn', '0.10.1' 'matplotlib', '3.1.3'

Python: 3.7.4

My solution around this is to use the truncate parameter under seaborn.regplot . Here is my code:

import seaborn as sns 
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.boxplot(x="size", y="tip", data=tips)
sns.regplot(x="size", y="tip", data=tips, scatter=False, truncate=False)
plt.show()

This is the result .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM