一个图里面画多个图
# -*- coding: utf-8 -*-
"""
画图
"""
import os
import matplotlib.pyplot as plt
def draw_img(data):
"""
画图,可以画单个图,多个图,
:param data:
{
'rss(M)': {'new': [1,2,3], 'old': [2,3,4]},
'vsz(M)': {'new': [1,2,3], 'old': [2,3,4]},
'cpu(%)': {'new': [1,2,3], 'old': [2,3,4]}
}
:return:
"""
plt.figure(figsize=(30, 20))
pic_num = len(data)
pic_index = 0
for k, v in data.items():
pic_index += 1
pic_position = pic_num * 100 + 10 + pic_index
tmp_pic = plt.subplot(pic_position)
plt.sca(tmp_pic)
plt.grid(ls='--')
plt.xlabel("time(s)")
plt.ylabel(k)
legend = []
for k1, v1 in v.items():
plt.plot(range(1, len(v1) + 1), v1, label=k1, linewidth=1)
plt.ylim([0, max(v1) * 1.01])
legend.append(k1)
plt.legend(legend, loc=0)
pic_path = os.getcwd() + '/perf.png'
plt.savefig(pic_path, bbox_inches='tight')
draw_img({
'rss(M)': {'new': [1,2,3], 'old': [2,3,4]},
'vsz(M)': {'new': [1,2,3], 'old': [2,3,4]},
'cpu(%)': {'new': [1,2,3], 'old': [2,3,4]}
})
效果: