![27d35a3b3b03a14b6ec2d7034ab3ef2a.png](https://img-blog.csdnimg.cn/img_convert/27d35a3b3b03a14b6ec2d7034ab3ef2a.png)
强化学习实验中的绘图技巧-使用seaborn绘制paper中的图片
使用seaborn绘制折线图时参数数据可以传递ndarray或者pandas,不同的源数据对应的其他参数也略有不同.
1. ndarray
先看一个小例子
def getdata():
basecond = [[18, 20, 19, 18, 13, 4, 1],
[20, 17, 12, 9, 3, 0, 0],
[20, 20, 20, 12, 5, 3, 0]]
cond1 = [[18, 19, 18, 19, 20, 15, 14],
[19, 20, 18, 16, 20, 15, 9],
[19, 20, 20, 20, 17, 10, 0],
[20, 20, 20, 20, 7, 9, 1]]
cond2 = [[20, 20, 20, 20, 19, 17, 4],
[20, 20, 20, 20, 20, 19, 7],
[19, 20, 20, 19, 19, 15, 2]]
cond3 = [[20, 20, 20, 20, 19, 17, 12],
[18, 20, 19, 18, 13, 4, 1],
[20, 19, 18, 17, 13, 2, 0],
[19, 18, 20, 20, 15, 6, 0]]
return basecond, cond1, cond2, cond3
数据维度都为(3,7)或(4, 7)
第一个维度表示每个时间点采样不同数目的数据(可认为是每个x对应多个不同y值)
第二个维度表示不同的时间点(可认为是x轴对应的x值)
data = getdata()
fig = plt.figure()
xdata = np.array([0, 1, 2, 3, 4, 5, 6])/5
linestyle = ['-', '--', ':', '-.']
color = ['r', 'g', 'b', 'k']
label = ['algo1', 'algo2', 'algo3', 'algo4']
for i in range(4):
sns.tsplot(time=xdata, data=data[i], color=color[i], linestyle=linestyle[i], condition=label[i])
sns.tsplot 用来画时间序列图
time参数表示对应的时间轴(ndarray),即x轴,data即要求绘制的数据,上述