【Matplotlib】数据点的标记样式

发布时间:2024-03-03 17:01

目录

  • matplotlib.markers 中所有的标记
  • 代码实例
    • 1. 导入包
    • 2. 生成随机数
    • 3. 画图

matplotlib.markers 中所有的标记

marker symbol description
\".\" \"m00\" point
\",\" \"m01\" pixel
\"o\" \"m02\" circle
\"v\" \"m03\" triangle_down
\"^\" \"m04\" triangle_up
\"<\" \"m05\" triangle_left
\">\" \"m06\" triangle_right
\"1\" \"m07\" tri_down
\"2\" \"m08\" tri_up
\"3\" \"m09\" tri_left
\"4\" \"m10\" tri_right
\"8\" \"m11\" octagon
\"s\" \"m12\" square
\"p\" \"m13\" pentagon
\"P\" \"m23\" plus (filled)
\"*\" \"m14\" star
\"h\" \"m15\" hexagon1
\"H\" \"m16\" hexagon2
\"+\" \"m17\" plus
\"x\" \"m18\" x
\"X\" \"m24\" x (filled)
\"D\" \"m19\" diamond
\"d\" \"m20\" thin_diamond
`\" \"` \"m21\"
\"_\" \"m22\" hline
0 (TICKLEFT) \"m25\" tickleft
1 (TICKRIGHT) \"m26\" tickright
2 (TICKUP) \"m27\" tickup
3 (TICKDOWN) \"m28\" tickdown
4 (CARETLEFT) \"m29\" caretleft
5 (CARETRIGHT) \"m30\" caretright
6 (CARETUP) \"m31\" caretup
7 (CARETDOWN) \"m32\" caretdown
8 (CARETLEFTBASE) \"m33\" caretleft (centered at base)
9 (CARETRIGHTBASE) \"m34\" caretright (centered at base)
10 (CARETUPBASE) \"m35\" caretup (centered at base)
11 (CARETDOWNBASE) \"m36\" caretdown (centered at base)
\"None\", \" \" or \"\" nothing
\'$...$\' \"m37\" 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 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.

代码实例

1. 导入包

import matplotlib.pyplot as plt
import random

2. 生成随机数

random.seed(2022)
y = [random.gauss(0, 1) for i in range(10)]
x = range(10)
print(y)
# [-1.059911532796699, -0.21343209892227447, -0.13048724278481846, 0.3292493351854598, 
# 0.5945395388166395, -2.772070654427417, -1.2083544534018353, 0.7418635616787197, 
# 0.7416186001053393, -1.8432987685720519]

3. 画图

fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(12, 6))

ax1.plot(x, y, marker=\'.\', color=\'r\') # marker=\'.\'
ax2.plot(x, y, marker=\',\', color=\'g\') # marker=\',\'
ax3.plot(x, y, marker=\',\', color=\'b\') # marker=\'1\'
ax4.plot(x, y, marker=\'D\', color=\'pink\') # marker=\'D\'

\"【Matplotlib】数据点的标记样式_第1张图片\"

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号