①:matplotlib在一张图上画出两折线图
import matplotlib.pyplot as plt
x=[10,20,30,40,50,60]
y=[29,3,45,76,23,89]
x1=[15,25,35,45,55,65]
y1=[9,7,55,66,33,99]
plt.figure()
plt.title('TEST1')
plt.plot(x,y,label='data1',linewidth=1,color='r',marker='o',linestyle='dotted')
plt.plot(x1,y1,label='data2',linewidth=1,color='b',marker='*',linestyle='dashed')
plt.legend()#给label用的
plt.xlabel('data')
plt.ylabel('result')
plt.show()
其中基本的是:
plt.plot(x,y,label=‘data1’,linewidth=3,color=‘r’,marker=‘o’)
label:用于做标注
一:**legend()**的参数有:
0: ‘best’
1: ‘upper right’
2: ‘upper left’
3: ‘lower left’
4: ‘lower right’
5: ‘right’
6: ‘center left’
7: ‘center right’
8: ‘lower center’
9: ‘upper center’
10: ‘center’
二:color
b: blue
g: green
r: red
c: cyan
m: magenta
y: yellow
k: black
w: white
三:marker的取值
‘.’: point marker
‘,’: pixel marker
‘o’: circle marker
‘v’: triangle_down marker
‘^’: triangle_up marker
‘<’: triangle_left marker
‘>’: triangle_right marker
‘1’: tri_down marker
‘2’: tri_up marker
‘3’: tri_left marker
‘4’: tri_right marker
‘s’: square marker
‘p’: pentagon marker 五边形
‘*’: star marker
‘h’: hexagon1 marker
‘H’: hexagon2 marker
‘+’: plus marker
‘x’: x marker
‘D’: diamond marker
‘d’: thin_diamond marker
‘|’: vline marker
‘_’: hline marker
四:linestyle的取值有
-, solid
–, dashed
-., dashdot
:, dotted
‘’, ’ ', None
引用:学习资料
②:
import os
import matplotlib.pyplot as plt
%matplotlib inline #注意:用pycharm就不用这句,jupyter才要
y=[]
str=['D:\master_project\.idea\/0.98goalstep.txt','D:\master_project\.idea\\0.98QLstep.txt']
for i in range(2):
with open(str[i],'r') as f:
content=f.read()
y.append(eval(content))#将str变成list
print('i',i,y[i],type(y[i]))
x=[i for i in range(40)]#我的y[0]也是40个数据
plt.figure()
plt.title('RSRL Vs QL when e-greed=0.9')
plt.plot(x,y[0],label='RSRL',linewidth=1,color='r',marker='o',linestyle='dotted')
plt.plot(x,y[1],label='QL',linewidth=1,color='b',marker='*',linestyle='dashed')
plt.legend()#给label用的
plt.xlabel('Episode')
plt.ylabel('Step')
plt.show()