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()

折线图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值