方法 | 含义 |
plt.title("Matplotlib demo") | 设置显示框的标题为 Matplotlib demo |
plt.xlabel("X") | 设置X轴名称为X |
plt.ylabel("Y") | 设置Y轴名称为Y |
fig = plt.figure(figsize=(100,100)) | 设置绘制图例的窗口大小 |
ax1 = fig.add_subplot() | 设置图例的(行,列,当前为第几个) |
plt.show() | 把图例显示出来 |
plt.plot(step,a,'red',label="ACK2",'ob') | “ob”表示使用离散的点来显示图例 |
ax1.plot(step,a,'red',label="ACK2") | step是横坐标参数,a是纵坐标参数,“red”是颜色,label是折线名称 |
from matplotlib import pyplot as plt ###a,b,c是存储数据的列表,step是图例的横坐标的显示 ###创建绘图窗口,并设置窗口大小 fig = plt.figure(figsize=(100,100)) ###绘制第一张图,将画面分割为8行1列选第一个,(行,列,第几) ###为空则默认只有一张图 ax1 = fig.add_subplot() ###设置折线颜色与折线显示 ax1.plot(step,a,'red',label="ACK2") ax1.plot(step,b,"blue",label="ACK1") ax1.plot(step,c,"green",label="ACK3") ###将图例中的折线解释放置在图例右上方 ax1.legend(loc= "upper right") ###设置图例X轴名称 ax1.set_xlabel('number') ###设置图例Y轴名称 ax1.set_ylabel('bandwidth_reality') ###显示绘制的折线图 plt.show()
import requests import json import urllib3 import time from log import * from matplotlib import pyplot as plt urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) login_json = {"username":"admin","password":"Passok"} ip = "192.168.0.30" config = {} a = [] b = [] c = [] txt1 = "" txt2 = "" txt3 = "" txt = "" step = [] session = requests.session() login = session.post(url="https://192.168.0.30/login",json=login_json,verify=False) i = 0 log_add_C30("","w") log_add_C31("","w") log_add_C32("","w") log_add_sum("","w") while i < 240: i += 1 step.append(i) get = session.get(url="https://192.168.0.30/rest/v2/interfaces/C30?depth=1",verify=False) config = json.loads(get.text) a.append(int(config["statistics"]["tx_mbps"])) txt1 = str(config["statistics"]["tx_mbps"]) log_add_C30(txt1,"a") log_add_C30("n","a") get = session.get(url="https://192.168.0.30/rest/v2/interfaces/C31?depth=1",verify=False) config = json.loads(get.text) b.append(int(config["statistics"]["tx_mbps"])) txt2 = str(config["statistics"]["tx_mbps"]) log_add_C31(txt2,"a") log_add_C31("n","a") get = session.get(url="https://192.168.0.30/rest/v2/interfaces/C32?depth=1",verify=False) config = json.loads(get.text) c.append(int(config["statistics"]["tx_mbps"])) txt3 = str(config["statistics"]["tx_mbps"]) log_add_C32(txt3,"a") log_add_C32("n","a") txt = "ACK1:"+txt1 +", ACK2:"+ txt2 +", ACK3:"+ txt3 + "n" log_add_sum(txt,"a") time.sleep(1) ###创建绘图窗口,并设置窗口大小 fig = plt.figure(figsize=(100,100)) ###绘制第一张图,将画面分割为8行1列选第一个,(行,列,第几) ax1 = fig.add_subplot() ###设置折线颜色与折线显示 ax1.plot(step,a,'red',label="ACK2") ax1.plot(step,b,"blue",label="ACK1") ax1.plot(step,c,"green",label="ACK3") ###将图例中的折线解释放置在图例右上方 ax1.legend(loc= "upper right") ###设置图例X轴名称 ax1.set_xlabel('number') ###设置图例Y轴名称 ax1.set_ylabel('bandwidth_reality') plt.show() 绘制出的结果