matplotlib作图
作者:互联网
import matplotlib.pyplot as plt
def autolabel(rects):
for rect in rects:
height = rect.get_height()
plt.text(rect.get_x()+rect.get_width()/2.-0.25, 1.01*height, '%s' % float(height), ha='left')
name_list = ['1', '2', '3', '4']
num_list = [0.0801, 0.1327, 0.1416, 0.1643]
colors = ['c', 'g', 'y', 'r']
autolabel(plt.bar(range(len(num_list)), num_list,width=0.6,color=colors ,alpha=0.5,tick_label=name_list))
plt.ylabel('Influence', fontsize=12)
plt.xlabel('Method', fontsize=12)
plt.show()
柱状图
import json
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
str = '100000'
with open('/mnt/sda1/wxl/RL4IM-Contingency-main/results/rl4im/sacred/51/eval_episode_rewards.json','r') as fp:
print(type(fp))
loaded_json=json.load(fp)
for key in loaded_json:
if key== str:
temp = loaded_json[key] #99*20
temp2 = np.average(temp,1) #99*1
x = np.zeros(99,)
for i in range(99):
x[i] = i*20+20
with open('/mnt/sda1/wxl/RL4IM-Contingency-main/results/rl4im/sacred/50/eval_episode_rewards.json','r') as fp:
print(type(fp))
loaded_json=json.load(fp)
for key in loaded_json:
if key== str:
temp = loaded_json[key] #99*20
temp3 = np.average(temp,1) #99*1
x = np.zeros(99,)
for i in range(99):
x[i] = i*20+20
with open('/mnt/sda1/wxl/RL4IM-Contingency-main/results/rl4im/sacred/41/eval_episode_rewards.json','r') as fp:
print(type(fp))
loaded_json=json.load(fp)
for key in loaded_json:
if key== str:
temp = loaded_json[key] #99*20
temp4 = np.average(temp,1) #99*1
x = np.zeros(99,)
for i in range(99):
x[i] = i*20+20
with open('/mnt/sda1/wxl/RL4IM-Contingency-main/results/rl4im/sacred/60/eval_episode_rewards.json','r') as fp:
print(type(fp))
loaded_json=json.load(fp)
for key in loaded_json:
if key== str:
temp = loaded_json[key] #99*20
temp5 = np.average(temp,1) #99*1
x = np.zeros(99,)
for i in range(99):
x[i] = i*20+20
plt.figure()
plt.title('Validation Graph #1', fontsize=15)
plt.ylabel('Expected Influence', fontsize=12)
plt.xlabel('Train steps', fontsize=12)
plt.plot(x.T, temp2.T,label = 'x1',linestyle="-")
plt.plot(x.T, temp3.T,label = 'x2',linestyle="--")
plt.plot(x.T, temp4.T,label = 'x3',linestyle=":")
plt.plot(x.T, temp5.T,label = 'x4',linestyle="-.")
plt.ylim((0.10,0.19))
plt.xlim((20,1200))
#plt.legend(loc='lower right')
plt.show()
折线图
标签:plt,20,作图,matplotlib,99,json,key,loaded 来源: https://blog.csdn.net/bjyxszd0805x1005/article/details/122268199