matplotlib


import matplotlib.pyplot as plt


# num=8000
# x=range(num)
# y1=[x*2 for x in range(num)]
# y2=[x*4 for x in range(num)]
# #plt.figure(figsize=(30,20),dpi=100)
# plt.plot(x,y1,)
# plt.plot(x,y2)
# plt.title('haha')
# plt.show()
import pandas as pd
# 定义读取函数
def readexcel():
    datas=pd.read_excel('/Users/lifei/Downloads/aa.xlsx', sheet_name='Sheet1',engine='openpyxl')
    datas=datas.to_dict(orient='records')
# 遍历记录
    times = []
    inbounds = []
    outbounds = []
    for item in datas:
        time=item.get('Date')
        print(str(time))
        if '2022-04-' not in str(time):
            continue

        inbound=(item.get('Inbound')-item.get('inbound2'))/1000000.00

        outbound = (item.get('Outbound') - item.get('outbound2'))/1000000.00
        if inbound<0:
            inbound=0
        if outbound<0:
            outbound=0
        inbounds.append(inbound)
        outbounds.append(outbound)
        times.append(time)

    plt.plot(times,inbounds)
    plt.plot(times,outbounds)
    plt.title('bei jing yi dong liuqiang tongji')
    #plt.figure(figsize=(800,300))
    plt.show()



# 调用函数
if __name__=='__main__':
    readexcel()

画拓扑

import networkx as nx
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']='SimHei'

G=nx.Graph()
G.add_edge('bj','wh')
G.add_edge('wh','gz')
G.add_edge('gz','sh')
G.add_edge('bj','xz')
G.add_edge('sh','xz')
G.add_edge('wh','xz')
G.add_edge('bj','北京')


pos = nx.spring_layout(G)
nx.draw_networkx_labels(G, pos, font_color='r')
nx.draw_networkx_edges(G, pos)
nx.draw_networkx_nodes(G, pos, node_size=20 ,node_color='blue')
plt.axis('off')

plt.show()

注:上述代码中对中文的支持解决,参考链接https://blog.csdn.net/fwj_ntu/article/details/105598145

posted @ 2022-04-12 07:43  lifei888  阅读(30)  评论(0)    收藏  举报