【发布时间】:2020-04-28 22:42:48
【问题描述】:
我是 Matplotlib 的新手。如何防止我的图表回溯?注意我图表右上角的钩子。 X 轴是字符串,Y 轴是浮点数。
这是我的数据:
['192.168.0.1', 2.568]
['96.120.96.153', 14.139]
['96.110.232.169', 10.505]
['162.151.49.133', 11.446]
['68.86.90.225', 24.335]
['68.86.84.226', 23.631]
['68.86.83.94', 29.011]
['173.167.58.162', 35.688]
['209.58.57.17', 162.768]
['64.86.79.2', 187.42]
['64.86.21.104', 162.461]
['63.243.205.1', 166.525]
['120.29.217.66', 156.898]
['209.58.86.143', 156.785]
['120.29.217.66', 181.599]
以及对应的代码:
import matplotlib.pyplot as plt
# x axis values
a = []
# corresponding y axis values
b = []
for k in range(15):
a.append(dataArray[k][0])
b.append(dataArray[k][1])
# plotting the points
plt.plot(a, b)
# naming the x axis
plt.xlabel('Hop Addresses')
# naming the y axis
plt.ylabel('average time (ms)')
# giving a title to my graph
plt.title('Time vs. Hops')
# function to show the plot
plt.show()
【问题讨论】:
-
你能发布代码和你的价值观吗?我怀疑您的 x 值不正确。
-
没错,它们是不按顺序排列的字符串。我正在尝试绘制跟踪路由、时间与 IP 地址的关系图,所以我不希望它们按顺序排列。
-
那么,IP地址是按访问顺序排列的,但时间与其他时间无关?
-
好吧,如果它们不按顺序排列,它们会在某个时间点回到过去。有时候,在生活中你必须做出选择。
标签: python matplotlib