如何在 Seaborn regplot 中显示点和线的不同颜色?
matplotlibpythondata visualization更新于 2025/6/6 23:40:17
要在 Seaborn regplot 中显示点和线的不同颜色,我们可以采取以下步骤 −
设置图形大小并调整子图之间和周围的填充。
使用关键 X 轴和 Y 轴制作 Pandas 数据框。
使用回归模型绘制数字独立变量。
要显示图形,请使用 show() 方法。
示例
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 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

