Matplotlib.pyplot.scatter 散点图绘制

简介: Matplotlib.pyplot.scatter 散点图绘制

Matplotlib.pyplot.plot 绘图

matplotlib.pyplot.scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, *, edgecolors=None, plotnonfinite=False, data=None, **kwargs)

属性 参数 意义
坐标 x,y 输入点列的数组,长度都是size
点大小 s 点的直径数组,默认直径20,长度最大size
点颜色 c 点的颜色,默认蓝色 'b',也可以是个 RGB 或 RGBA 二维行数组。
点形状 marker MarkerStyle 点的样式,默认小圆圈 'o'。
调色板 cmap Colormap,默认 None,标量或者是一个 colormap 的名字,只有 c 是一个浮点数数组时才使用。如果没有申明就是 image.cmap。
亮度(1) norm Normalize,默认 None,数据亮度在 0-1 之间,只有 c 是一个浮点数的数组的时才使用。
亮度(2) vmin,vmax 亮度设置,在 norm 参数存在时会忽略。
透明度 alpha 透明度设置,0-1 之间,默认 None,即不透明
线 linewidths 标记点的长度
颜色 edgecolors 颜色或颜色序列,默认为 'face',可选值有 'face', 'none', None。
plotnonfinite 布尔值,设置是否使用非限定的 c ( inf, -inf 或 nan) 绘制点。
**kwargs  其他参数。

MarkerStyle

marker description 描述
"." point
"," pixel 像素
"o" circle
"v" triangle_down 倒三角
"^" triangle_up 正三角
"<" triangle_left 左三角
">" triangle_right 右三角
"1" tri_down
"2" tri_up
"3" tri_left
"4" tri_right
"8" octagon 八角形
"s" square 正方形
"p" pentagon 五角
"P" plus (filled)
"*" star 星星
"h" hexagon1
"H" hexagon2
"+" plus +号
"x" x X 号
"X" x (filled)
"D" diamond
"d" thin_diamond
``" "`` vline
"_" hline
0 (TICKLEFT) tickleft
1 (TICKRIGHT) tickright
2 (TICKUP) tickup
3 (TICKDOWN) tickdown
4 (CARETLEFT) caretleft
5 (CARETRIGHT) caretright
6 (CARETUP) caretup
7 (CARETDOWN) caretdown
8 (CARETLEFTBASE) caretleft (centered at base)
9 (CARETRIGHTBASE) caretright (centered at base)
10 (CARETUPBASE) caretup (centered at base)
11 (CARETDOWNBASE) caretdown (centered at base)
"None", " " or "" nothing
'$...$' Render the string using mathtext.
E.g "$f$" for marker showing the
letter f.
verts A list of (x, y) pairs used for Path
vertices. The center of the marker is
located at (0, 0) and the size is
normalized, such that the created path
is encapsulated inside the unit cell.
path A ~matplotlib.path.Path instance.
(numsides, 0, angle) A regular polygon with numsides
sides, rotated by angle.
(numsides, 1, angle) A star-like symbol with numsides
sides, rotated by angle.
(numsides, 2, angle) An asterisk with numsides sides,
rotated by angle.

示例

import numpy as np
import matplotlib.pyplot as plt
# Fixing random state for reproducibility
np.random.seed(19680801)
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)  # 颜色可以随机
area = (30 * np.random.rand(N)) ** 2  # 随机大小
# x,y,s,c 的 size 需要一致
plt.scatter(x, y, s=area, c=colors, alpha=0.5)
plt.show()

多元高斯的情况

# 设置画布大小
fig = plt.figure(figsize=(8, 6))
# Generating a Gaussion dataset:
# creating random vectors from the multivariate normal distribution
# given mean and covariance
mu_vec1 = np.array([0, 0])
cov_mat1 = np.array([[1, 0], [0, 1]])
X = np.random.multivariate_normal(mu_vec1, cov_mat1, 500)
R = X ** 2
R_sum = R.sum(axis=1)
plt.scatter(X[:, 0], X[:, 1], c='green', marker='o', s=32. * R_sum, edgecolor='black', alpha=0.5)
plt.show()

make_blobs

import numpy as np
from sklearn.datasets import make_blobs  # 为了快速方便的创建数据集,此处采用 scikit-learn 里的 make_blobs
import matplotlib.pyplot as plt
# 创建一个数据集,X有两个特征,y={-1,1}
X, y = make_blobs(n_samples=500, centers=2, random_state=6)
y[y == 0] = -1
plt.scatter(X[:, 0], X[:, 1], c=y, s=50, cmap=plt.cm.Paired)
plt.xlabel("feature_1")
plt.ylabel("feature_2")
plt.show()

源码地址:https://gitee.com/VipSoft/VipPython/matplotlib/pyplot_scatter.py

https://matplotlib.org/stable/gallery/index

目录
相关文章
|
数据可视化 Python
【100天精通Python】Day62:Python可视化_Matplotlib绘图基础,绘制折线图、散点图、柱状图、直方图和饼图,以及自定义图标外观和功能,示例+代码
【100天精通Python】Day62:Python可视化_Matplotlib绘图基础,绘制折线图、散点图、柱状图、直方图和饼图,以及自定义图标外观和功能,示例+代码
192 0
|
21天前
|
Python
Matplotlib 教程 之 Matplotlib 散点图 1
通过设置参数如点的大小(`s`)、颜色(`c`)和样式(`marker`)等,可以定制图表外观。示例展示了如何用两个长度相同的数组分别表示 x 和 y 轴的值来创建基本散点图。
32 12
|
19天前
|
数据可视化 Python
Matplotlib 教程 之 Matplotlib 散点图 7
使用 Matplotlib 的 `scatter()` 方法绘制散点图。该方法接受多个参数,如 x 和 y 数据点、点的大小(s)、颜色(c)和样式(marker)等。通过示例展示了如何利用颜色数组和颜色映射 (`cmap`) 来增强图表的表现力,并使用 `colorbar()` 方法添加颜色条,使数据可视化更加直观。
28 1
|
18天前
|
数据可视化 Python
Matplotlib 教程 之 Matplotlib 散点图 9
使用Matplotlib中的`scatter()`方法绘制散点图。该方法接受多个参数,如数据点位置(x,y)、点的大小(s)、颜色(c)等,并支持多种颜色样式和配置选项。通过调整这些参数,用户可以自定义散点图的外观和表现形式,实现丰富的可视化效果。
16 0
|
20天前
|
Python
Matplotlib 教程 之 Matplotlib 散点图 4
使用 Matplotlib 的 `scatter()` 方法绘制散点图。通过设置 `x` 和 `y` 数组来定义数据点位置,还可以自定义点的大小(`s`)、颜色(`c`)、样式(`marker`)等参数。示例展示了两组不同颜色的散点图,分别使用 `hotpink` 和 `#88c999` 颜色绘制。
27 0
|
5月前
|
Python
matplotlib-散点图
matplotlib-散点图
matplotlib-散点图
|
4月前
|
Python
Python学习笔记之Matplotlib模块入门(直线图、折线图、曲线图、散点图、柱状图、饼状图、直方图、等高线图和三维图的绘制)-2
Python学习笔记之Matplotlib模块入门(直线图、折线图、曲线图、散点图、柱状图、饼状图、直方图、等高线图和三维图的绘制)
|
4月前
|
数据可视化 开发者 Python
Python学习笔记之Matplotlib模块入门(直线图、折线图、曲线图、散点图、柱状图、饼状图、直方图、等高线图和三维图的绘制)-1
Python学习笔记之Matplotlib模块入门(直线图、折线图、曲线图、散点图、柱状图、饼状图、直方图、等高线图和三维图的绘制)
|
11月前
|
数据挖掘 Python
【Python】数据分析:matplotlib散点图
【Python】数据分析:matplotlib散点图
72 0
|
数据可视化 Python
【100天精通Python】Day65:Python可视化_Matplotlib3D绘图mplot3d,绘制3D散点图、3D线图和3D条形图,示例+代码
【100天精通Python】Day65:Python可视化_Matplotlib3D绘图mplot3d,绘制3D散点图、3D线图和3D条形图,示例+代码
337 0