目录
一、打开python
新建一个pathon项目。
二、代码
# -*- coding: utf-8 -*- import matplotlib.pyplot as plt names = ['1', '2', '3', '4', '5', '6'] x = range(len(names)) plt.rcParams['font.sans-serif'] = ['SimHei'] # 显示汉字 y_1 = [2, 3, 4, 5, 6, 1] y_2 = [3, 4, 5, 6, 1, 2] //y轴的值 y_3 = [4, 5, 6, 1, 2, 3] plt.plot(x, y_1, color='orangered', marker='o', linestyle='-', label='A') plt.plot(x, y_2, color='blueviolet', marker='D', linestyle='-.', label='B') plt.plot(x, y_3, color='green', marker='*', linestyle=':', label='C') plt.legend() # 显示图例 plt.xticks(x, names, rotation=45) plt.xlabel("X轴坐标") # X轴标签 plt.ylabel("Y轴坐标") # Y轴标签 plt.show()
三、运行结果