散点图

简介: 散点图

用两组数据构成多个坐标点,考察坐标点的分布,判断两变量之间是否存在某种关联或总结坐标点的分布模式。散点图将序列显示为一组点。值由点在图表中的位置表示。类别由图表中的不同标记表示。散点图通常用于比较跨类别的聚合数据。

简单的散点图绘制
from matplotlib import pyplot as plt
import numpy as np
# 散点  横轴和纵轴都是特征
x = np.random.normal(0, 1, 100) # 均值为0 方差为1 正态分布
y = np.random.normal(0, 1, 100)
plt.scatter(x, y)
plt.show()

网络异常,图片无法展示
|

x = np.random.normal(0, 1, 100000)
y = np.random.normal(0, 1, 100000)
plt.scatter(x, y)
plt.show()

网络异常,图片无法展示
|

x = np.random.normal(0, 1, 100000)
y = np.random.normal(0, 1, 100000)
plt.scatter(x, y,alpha=0.1)
plt.show()

网络异常,图片无法展示
|

案例:绘制机器学习中经典数据集-鸢尾花

# 加载鸢尾花数据集
from sklearn import datasets
iris = datasets.load_iris()
iris.keys()
dict_keys(['data', 'target', 'target_names', 'DESCR', 'feature_names'])
#print(iris.DESCR)
iris.feature_names
['sepal length (cm)',
 'sepal width (cm)',
 'petal length (cm)',
 'petal width (cm)']
iris.target
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])
iris.target_names
array(['setosa', 'versicolor', 'virginica'], dtype='<U10')
X = iris.data[:,:2]
y = iris.target
y
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])
# type(X)
X[:,1]
plt.scatter(X[:,0],X[:,1])


相关文章
|
15天前
|
Python
matplotlib-散点图
matplotlib-散点图
matplotlib-散点图
|
26天前
|
数据可视化 数据挖掘 Python
Matplotlib图表类型详解:折线图、柱状图与散点图
【4月更文挑战第17天】本文介绍了Python数据可视化库Matplotlib的三种主要图表类型:折线图、柱状图和散点图。折线图用于显示数据随时间或连续变量的变化趋势,适合多条曲线对比;柱状图适用于展示分类数据的数值大小和比较;散点图则用于揭示两个变量之间的关系和模式。通过示例代码展示了如何使用Matplotlib创建这些图表。
|
7月前
243Echarts - 3D 散点图(三维散点图正交投影)
243Echarts - 3D 散点图(三维散点图正交投影)
30 0
|
机器学习/深度学习 API Python
seaborn画直方图、条形图、盒图、散点图等常用图形
seaborn画直方图、条形图、盒图、散点图等常用图形
209 0
seaborn画直方图、条形图、盒图、散点图等常用图形
|
11月前
|
数据挖掘
ggplot2|从0开始绘制箱线图
ggplot2|从0开始绘制箱线图
|
11月前
|
数据挖掘
ggplot2|从0开始绘制折线图
ggplot2|从0开始绘制折线图
121 0
|
开发者 Python
matplotlib画折线图、直方图、饼图、散点图等常见图形
matplotlib画折线图、直方图、饼图、散点图等常见图形
208 0
matplotlib画折线图、直方图、饼图、散点图等常见图形
折线图
折线图
77 0
折线图
|
开发者 Python
直方图与散点图|学习笔记
快速学习直方图与散点图
151 0
直方图与散点图|学习笔记
|
API Python
Matplotlib常见绘图绘制(折线图、散点图、柱状图、直方图、饼图)
Matplotlib常见绘图绘制(折线图、散点图、柱状图、直方图、饼图)
289 0
Matplotlib常见绘图绘制(折线图、散点图、柱状图、直方图、饼图)