简体   繁体   中英

Plot Network statistics using matplotlib

I try to use matplotlib to print network statistics. I want to look it like line graphs created with excel.

Excel:

Excel 网络统计

Matplotlib

[ matplotlib][1]

My very simple code:

import matplotlib.pyplot as plt
import numpy as np

x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59])
y = np.array(['0.00', '0.00', '0.00', '0.12', '0.00', '0.00', '0.00', '14.75', '108.56', '78.91', '508.15', '79.66', '147.84', '199.87', '14.02', '10.05', '3411.12', '19735.23', '19929.51', '18428.82', '21727.14', '19716.41', '20295.20', '20283.08', '20088.10', '20155.81', '20108.67', '19954.45', '20316.46', '20045.77', '20233.71', '19981.40', '20230.02', '20099.69', '20000.23', '20234.06', '19763.92', '20458.40', '19626.22', '20542.25', '19821.72', '20443.78', '20109.41', '19918.96', '20223.37', '19933.64', '20023.73', '19655.67', '19890.94', '20590.04', '20158.37', '20001.59', '20011.48', '19785.95', '20550.63', '19687.02', '20025.00', '20478.25', '20124.66', '20148.08'])
plt.plot(x, y)
plt.xticks(x)
plt.show()

Your y is string type. Try y=y.astype(float) before plot, then you get the expected:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM