Python seaborn regplot删除数据点的颜色

Python seaborn regplot删除数据点的颜色,python,matplotlib,regression,seaborn,Python,Matplotlib,Regression,Seaborn,我正在分析花瓣的长度,并在花瓣的宽度和长度之间做了一个散点图。为了绘制图,我使用了以下代码: # First, we'll import pandas, a data processing and CSV file I/O library import pandas as pd # We'll also import seaborn, a Python graphing library import warnings # current version of seaborn generates

我正在分析花瓣的长度,并在花瓣的宽度和长度之间做了一个散点图。为了绘制图,我使用了以下代码:

# First, we'll import pandas, a data processing and CSV file I/O library
import pandas as pd
# We'll also import seaborn, a Python graphing library
import warnings # current version of seaborn generates a bunch of warnings that we'll ignore
warnings.filterwarnings("ignore")
import seaborn as sns
import matplotlib.pyplot as plt
import numpy
sns.set(style="dark", color_codes=True)

# Next, we'll load the Iris flower dataset, which is in the "../input/" directory
iris = pd.read_csv("Iris.csv") # the iris dataset is now a Pandas DataFrame

# Let's see what's in the iris data - Jupyter notebooks print the result of the last thing you do
print(iris.head(10))

# Press shift+enter to execute this cell
sns.FacetGrid(iris, hue="Species", size=10) \
   .map(plt.scatter, "PetalLengthCm", "PetalWidthCm") \
   .add_legend()

之后,我画了一条回归线,但在画了这条线之后,颜色就不明显了。我试图改变回归线的颜色,但这没有帮助。如何绘制回归线而不丢失不同物种的颜色

绘制包含回归线的绘图的代码为:

sns.FacetGrid(iris, hue="Species", size=10) \
   .map(plt.scatter, "PetalLengthCm", "PetalWidthCm") \
   .add_legend()
sns.regplot(x="PetalLengthCm", y="PetalWidthCm", data=iris)

petal_length_array = iris["PetalLengthCm"]
petal_width_array = iris["PetalWidthCm"]

r_petal = numpy.corrcoef(petal_length_array, petal_width_array) # bereken de correlatie

print ("Correlation is : " + str(r_petal[0][1]))

您的问题是
sns.regplot()
在具有不同颜色的点的顶部绘制相同颜色的所有点


要避免这种情况,请尝试调用
regplot(…,scatter=False)
以防止绘制单个数据点

您的问题是
sns.regplot()
在具有不同颜色的点的顶部绘制相同颜色的所有点


要避免这种情况,请尝试调用
regplot(…,scatter=False)
以防止绘制单个数据点

如果您愿意拥有多条回归线,您可以分割数据并进行过度绘制

iris = sns.load_dataset("iris")

fig, ax = plt.subplots() 
colors = ['darkorange', 'royalblue', '#555555']
markers = ['.', '+', 'x']

for i, value in enumerate(iris.species.unique()):
    ax = sns.regplot(x="petal_length", y="petal_width", ax=ax,
                     color=colors[i],
                     marker=markers[i], 
                     data=iris[iris.species == value],
                     label=value)

ax.legend(loc='best') 
display(fig) 
plt.close('all')

如果您愿意拥有多条回归线,您可以分割数据并进行过度绘制

iris = sns.load_dataset("iris")

fig, ax = plt.subplots() 
colors = ['darkorange', 'royalblue', '#555555']
markers = ['.', '+', 'x']

for i, value in enumerate(iris.species.unique()):
    ax = sns.regplot(x="petal_length", y="petal_width", ax=ax,
                     color=colors[i],
                     marker=markers[i], 
                     data=iris[iris.species == value],
                     label=value)

ax.legend(loc='best') 
display(fig) 
plt.close('all')

它没有按预期工作。regplot只考虑一种类型的数据点。你能展示一下完整的方法吗?我可能遗漏了一些东西。@jaysabir我不理解你的评论。请发布一个新问题,并对您的问题进行完整描述,包括代码和数据。我想用色调绘制regplot。就像这个问题一样。我同意@DizietAsahi,为了给你留出时间,检查它是否按预期工作。regplot只考虑一种类型的数据点。你能展示一下完整的方法吗?我可能遗漏了一些东西。@jaysabir我不理解你的评论。请发布一个新问题,并对您的问题进行完整描述,包括代码和数据。我想用色调绘制regplot。就像这个问题一样。我同意@DizietAsahi,为了给你留出时间,检查一下