python画图 折线图 饼图 柱状图

折线图

import numpy as np
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签 plt.reParams是一个配置表
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号
plt.figure(figsize=(7, 5))
x = np.linspace(0, 2 * np.pi, 50)
y = np.sin(x)
plt.xlabel(u'自变量')
plt.ylabel(u'因变量')
plt.title(u'正弦曲线')
plt.plot(x, y, 'ro--') #红色圆圈加虚线
plt.show()

这里写图片描述
饼图

from matplotlib import pyplot as plt

#画出饼图的关键就是定义标签和每一块的颜色
labels = ['Frogs', 'Hogs', 'Dogs', 'Logs']
sizes = [15, 30, 45, 10]
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
explode = (0, 0.1, 0, 0) #突出显示

plt.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90)
plt.axis('equal')  #避免比例压缩为椭圆
plt.show()

这里写图片描述
柱状图

import numpy as np
import matplotlib.pyplot as plt
ATT_LSTM = [0.8892,0.861,0.9243]
MATT_CNN = [0.8966,0.8556,0.9316]
ATT_RLSTM = [0.8867,0.8543,0.9344]
CNN_RLSTM = [0.9016,0.8636,0.9435]
#x = ['REST','LAPT','AUTO']
x = np.arange(3)

total_width, n = 0.8, 4    # 有多少个类型,只需更改n即可
width = total_width / n
x = x - (total_width - width) / 2

plt.bar(x, ATT_LSTM, color = "red",edgecolor = "k",width=width,hatch = "/",label='ATT-LSTM ')#edgecolor柱状边框颜色,hatch填充的内容
plt.bar(x + width, MATT_CNN, color = "yellowgreen",edgecolor = "k",width=width, hatch = "+",label='MATT-CNN')
plt.bar(x + 2 * width, ATT_RLSTM , color = "lightskyblue",edgecolor = "k",width=width, hatch = "*",label='ATT-RLSTM')
plt.bar(x + 3 * width, CNN_RLSTM , color = "lightcoral",edgecolor = "k",width=width, hatch = "\\",label='CNN-RLSTM')
plt.xlabel("dataset")
plt.ylabel("accuracy")
plt.legend(loc = "best")
plt.xticks([0,1,2],['REST','LAPT','AUTO'])
my_y_ticks = np.arange(0.8, 0.95, 0.02)
plt.ylim((0.8, 0.95))
plt.yticks(my_y_ticks)
plt.show()

这里写图片描述

猜你喜欢

转载自blog.csdn.net/weixin_36372879/article/details/80900992