如何在Seaborn regplot中分别显示点和线的不同颜色?

如何在Seaborn regplot中分别显示点和线的不同颜色?

要在Seaborn regplot中显示不同颜色的点和线,请执行以下步骤:

  • 设置图形大小并调整子图之间和周围的填充。

  • 使用关键X轴和Y轴创建Pandas dataframe。

  • 使用回归模型绘制数值独立变量。

  • 为了显示图形,请使用 show() 方法。

阅读更多:Python 教程

示例

import pandas
import matplotlib.pylab as plt
import seaborn as sns
import numpy as np

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

df = pandas.DataFrame({"X-Axis": [np.random.randint(5) for i in range(10)], "Y-Axis": [np.random.randint(5) for i in range(10)]})
sns.regplot(x='X-Axis', y='Y-Axis', data=df, scatter_kws={"color": "red"}, line_kws={"color": "green"})

plt.show()
Python

输出

如何在Seaborn regplot中分别显示点和线的不同颜色?

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册