import matplotlib.pyplot as plt # 准备数据 x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10] # 绘制折线图 plt.plot(x, y) # 显示图形 plt.show()
    
import matplotlib.pyplot as plt
# 准备数据
x = [1, 2, 3, 4, 5]
y1 = [2, 4, 6, 8, 10]
y2 = [1, 3, 5, 7, 9]
# 绘制折线图
plt.plot(x, y1, linestyle='--', color='red', marker='o', label='Line 1')
plt.plot(x, y2, linestyle='-', color='blue', marker='s', label='Line 2')
# 添加图例、标签和标题
plt.legend()
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Plot Example')
# 显示图形
plt.show()
以上示例中,使用plot函数绘制了两条折线图,并通过linestyle、color、marker和label参数自定义了样式和图例。最后使用legend、xlabel、ylabel和title函数添加了图例、标签和标题。