import numpy as np
import matplotlib.pyplot as plt
#创建新图片,设定图片尺寸
fig = plt.figure(figsize=(6,3))
x = np.linspace(-9,9,201)
y = np.sin(x)
#设置坐标轴范围
plt.xlim((-9, 9))
plt.ylim((-1.2, 1.2))
#设置坐标轴刻度
x_ticks = range(-8,9,2)
y_ticks = range(-1,2,1)
plt.xticks(x_ticks)
plt.yticks(y_ticks)
plt.plot(x,y,color='blue')
#加入参考线
plt.axhline(y=0, c="gray", ls="--", lw=1.5)
plt.axvline(x=0, c="gray", ls="--", lw=1.5)
plt.show()
![](https://img2020.cnblogs.com/blog/271257/202102/271257-20210213163310500-987934453.png)
import numpy as np
import matplotlib.pyplot as plt
x = [0,0,1,1]
y = [0,1,0,1]
plt.figure(figsize=(3,3))
#给点打上标签
txt = [1,2,4,3]
for i in range(4):
plt.annotate(txt[i],xy=(x[i],y[i]),xytext=(x[i]+0.05,y[i]-0.035))
#画箭头
plt.arrow(0,0,0.5,1,
length_includes_head=True,
head_width=0.05,
head_length=0.1,
fc='black',
ec='black')
plt.xlim((-0.2, 1.2))
plt.ylim((-0.2, 1.2))
x_ticks = [0,1]
y_ticks = [0,1]
plt.xticks(x_ticks)
plt.yticks(y_ticks)
# 设定点的颜色和大小
plt.scatter(x,y,c=[1,2,3,4],s=[20,40,80,160])
plt.show()
![](https://img2020.cnblogs.com/blog/271257/202103/271257-20210316163519364-2041046322.png)
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-6,6)
plt.figure(figsize=(9,2.6))
# 添加子图
plt.subplot(131)
plt.plot(x,x)
# 添加子图
plt.subplot(132)
plt.plot(x,x**2)
# 添加子图
plt.subplot(133)
plt.plot(x,x**3)
plt.show()
![](https://img2020.cnblogs.com/blog/271257/202102/271257-20210213162828582-1759892240.png)