Python画图matplotlib细致完整知识点整理--plot函数

这周学习了Python画图工具发现plot()里面有很多参数所以决定整理总结一下

先上一个简单的图像

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 1.2, 0.1)
y = 2 * x + 1
z = x ** 2

# 创建画布
plt.figure(figsize=(8, 6))
# 设定字体
plt.rcParams['font.sans-serif'] = 'SimHei'
# 曲线
plt.plot(x, z, markersize=5, marker='o', color='green', markerfacecolor='blue', linestyle='dashed', linewidth=1, markeredgecolor='m')
plt.plot(x, y, markersize=5, marker='o', color='green', markerfacecolor='blue', linestyle='dashed', linewidth=1, markeredgecolor='m')
plt.title('lines')
plt.xticks([0, 0.2, 0.4, 0.6, 0.8, 1, 1.1, 1.2]) # 刻度
plt.xlabel('x轴')
plt.ylabel('y轴')
plt.show()

重点介绍plot函数的几个参数

color:控制线条颜色

控制选择线条的颜色

 

Python画图matplotlib细致完整知识点整理--plot函数_第1张图片

Python画图matplotlib细致完整知识点整理--plot函数_第2张图片

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 1.2, 0.1)
y = 2 * x + 1
z = x ** 2

# 创建画布
plt.figure(figsize=(8, 6))
# 设定字体
plt.rcParams['font.sans-serif'] = 'SimHei'
# 曲线
plt.plot(x, z, color='firebrick')
plt.plot(x, y, color='slateblue')
plt.show()

Python画图matplotlib细致完整知识点整理--plot函数_第3张图片

linestyle:线条风格

Python画图matplotlib细致完整知识点整理--plot函数_第4张图片

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 1.2, 0.1)
y = 2 * x + 1
z = x ** 2

# 创建画布
plt.figure(figsize=(8, 6))
# 设定字体
plt.rcParams['font.sans-serif'] = 'SimHei'
# 曲线
plt.plot(x, z, linestyle=':')
plt.plot(x, y, linestyle='-.')
plt.show()

Python画图matplotlib细致完整知识点整理--plot函数_第5张图片

marker:标记风格

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 vline
"_" 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.

 

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 1.2, 0.1)
y = 2 * x + 1
z = x ** 2

# 创建画布
plt.figure(figsize=(8, 6))
# 设定字体
plt.rcParams['font.sans-serif'] = 'SimHei'
# 曲线
plt.plot(x, z, markersize=10, marker='*')
plt.plot(x, y, markersize=10, marker=0)
plt.show()

Python画图matplotlib细致完整知识点整理--plot函数_第6张图片

markerfacecolor:标记点颜色

设定画图中点的颜色

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 1.2, 0.1)
y = 2 * x + 1
z = x ** 2

# 创建画布
plt.figure(figsize=(8, 6))
# 设定字体
plt.rcParams['font.sans-serif'] = 'SimHei'
# 曲线
plt.plot(x, z, markersize=10, marker='*', markerfacecolor='lawngreen')
plt.plot(x, y, markersize=10, marker='o', markerfacecolor='navy')
plt.show()

Python画图matplotlib细致完整知识点整理--plot函数_第7张图片

markersize:标记尺寸

设定图中标记点的大小

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 1.2, 0.1)
y = 2 * x + 1
z = x ** 2

# 创建画布
plt.figure(figsize=(8, 6))
# 设定字体
plt.rcParams['font.sans-serif'] = 'SimHei'
# 曲线
plt.plot(x, z, markersize=10, marker='*', markerfacecolor='lawngreen')
plt.plot(x, y, markersize=5, marker='*', markerfacecolor='navy')
plt.show()

Python画图matplotlib细致完整知识点整理--plot函数_第8张图片

linewidth:线条宽度

设定线条的宽度

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 1.2, 0.1)
y = 2 * x + 1
z = x ** 2

# 创建画布
plt.figure(figsize=(8, 6))
# 设定字体
plt.rcParams['font.sans-serif'] = 'SimHei'
# 曲线
plt.plot(x, z, linewidth=0.5)
plt.plot(x, y, linewidth=2)
plt.show()

Python画图matplotlib细致完整知识点整理--plot函数_第9张图片

markeredgecolor:点边框颜色

设定点的边框的颜色

Python画图matplotlib细致完整知识点整理--plot函数_第10张图片

 

 

 

你可能感兴趣的:(Python画图matplotlib细致完整知识点整理--plot函数)