1. 程式人生 > >Python-matplotlib-入門教程(三)-線形管理

Python-matplotlib-入門教程(三)-線形管理

0.摘要

本文主要介紹使用matplotlib繪圖過程中的線形管理。

 

1.標準線形

線形 符號
實線 -
短線 --
點線 -.
虛線
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0,10,100)
y1 = x
y2 = x + 1
y3 = x + 3
y4 = x + 4

plt.plot(x,y1,linestyle='-')
plt.plot(x,y2,linestyle='--')
plt.plot(x,y3,linestyle='-.')
plt.plot(x,y4,linestyle=':')
plt.show()

 

2.線標

為了更加明顯區別線形,可以通過在線上新增標記。

標準線標:

符號 含義
. point marker
, point marker
o circle marker
v triangle_down marker
^ triangle_up marker
< triangle_left marker
> triangle_right marker
1 tri_down marker
2 tri_up marker
3 tri_left marker
4 tri_right marker
s square marker
p pentagon marker
* star marker
h hexagon1 marker
H hexagon2 marker
+ plus marker
x x marker
D diamond marker
d thin_diamond marker
| vline marker
- hline marker
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0,10,10)
y1 = x
y2 = x + 1
y3 = x + 3
y4 = x + 4

plt.plot(x,y1,marker='o')
plt.plot(x,y2,marker='^')
plt.plot(x,y3,marker='1')
plt.plot(x,y4,marker='*')
plt.show()