1 绘制折线图
1.1 折线图
import matplotlib.pyplot as plt
# 绘制折线图
plt.plot([10, 20])
# 折线图与轴命名
plt.title("Line Graph")
plt.xlabel("X axis")
plt.ylabel("Y axis")
plt.show()
OUTPUT:
1.2 多线折线图
import matplotlib.pyplot as plt
# 绘制折线图
plt.plot([10, 20, 16, 18], label='Tea')
plt.plot([2, 7, 9, 8], label='Alcohol')
plt.plot([8.8, 12.7, 11.5, 9.9], label='Milk')
plt.plot([1.3, 4.9, 6.1, 3.9, 7.9], label='Coffee')
# 多线折线图与轴命名
plt.title("Multi Line Graph")
plt.xlabel("X axis")
plt.ylabel("Y axis")
plt.legend()
plt.show()
OUTPUT:
2 绘制点状图
import matplotlib.pyplot as plt
x = [1, 2, 5, 7, 9, 11, 15, 18]
y = [2, 3, 5, 6, 10, 12, 13, 17]
# 绘制虚线图
plt.plot(x, y, label='Tea', c='teal', ls=('dashed'), lw=2.5)
# 绘制点线图
plt.plot(y, x, label='Coffee', c='red', ls=('dotted'), lw=2.5)
plt.legend()
plt.show()
OUTPUT: