Matplotlib教程
程序员文章站
2022-03-26 18:38:12
...
sudo apt-get install python3-pip
# python 3+ 请复制以下在 terminal 中执行
$ sudo apt-get install python3-matplotlib
# python 2+ 请复制以下在 terminal 中执行
$ sudo apt-get install python-matplotlib
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-3, 3, 50)
y1 = 2*x + 1
y2 = x**2
plt.figure()
#set x limits
plt.xlim((-1, 2))
plt.ylim((-2, 3))
# set new sticks
new_sticks = np.linspace(-1, 2, 5)
plt.xticks(new_sticks)
# set tick labels
plt.yticks([-2, -1.8, -1, 1.22, 3],
[r'$really\ bad$', r'$bad$', r'$normal$', r'$good$', r'$really\ good$'])
# set line syles
l1, = plt.plot(x, y1, label='linear line')
l2, = plt.plot(x, y2, color='red', linewidth=1.0, linestyle='--', label='square line')
plt.legend(loc='upper right')
plt.show()
cd catkin_ws
cd src
chmod +x figure1.py
python figure1.py
上一篇: matplotlib教程之基础
下一篇: 创建Bitmap时设置背景为透明