Home>
1

I want to extract values ​​from a file in which experimental data is recorded and display them as a graph.

2 Stumble points

The number of elements in the list is about 25620, and the graph is not displayed.

The code is shown below

import numpy as np
import matplotlib.pyplot as plt

time_1 = []
cwnd_1 = []
#Open the file.
with open ('tcpout.txt') as f:
    lines = f.readlines ()

# Extract the line I want to graph in the text file.
l_1 = [line for line in lines if '5001 32' in line]
#Extract the required values ​​for the graph from the extracted rows.
for line in l_1:
    line_split = line.split ("")
    time_1.append (line_split [0])
    cwnd_1.append (line_split [6])
print (len (time_1))
print (len (cwnd_1))
#List graphing. I want to graph it with a scatter plot.
plt.title ("track cwnd")
plt.xlabel ("Time")
plt.ylabel ("cwnd")
plt.scatter (time_1, cwnd_1)
plt.show ()
Current status

The graphs displayed in the above program when the number of elements is 3 and when the number of elements is 25620 are shown below. The top is 3 and the bottom is 25620. If the number of elements is large, the graph will not be displayed as shown in the figure.
How can I display it?
We would like to ask the experts for their help.

Also, since I could not paste the text file to get the value, a part of the contents of the text file is shown below.
A file with tens of thousands of lines of such data.

132.449678731 100.64.0.1: 5001 100.64.0.2: 60424 56 0xe4249c61 0xe4249c61 10 2147483647 29312 3939 28960
132.451673233 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daa2b72 0x6da9ed3a 11 2147483647 29056 4578 29312
132.451782187 100.64.0.1: 5001 100.64.0.2: 60424 1480 0xe4249c61 0xe4249c61 10 2147483647 29312 3939 31872
132.453574989 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daa2b72 0x6da9f2e2 12 2147483647 31872 4496 29312
132.453611768 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daa4212 0x6da9f88a 13 2147483647 34816 4662 29312
132.453665328 100.64.0.1: 5001 100.64.0.2: 60424 1480 0xe4249c61 0xe4249c61 10 2147483647 29312 3939 37760
132.455576619 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daa4212 0x6da9fe32 14 2147483647 37760 4810 29312
132.455622855 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daa58b2 0x6daa03da 15 2147483647 40576 5188 29312
132.455659654 100.64.0.1: 5001 100.64.0.2: 60424 1480 0xe4249c61 0xe4249c61 10 2147483647 29312 3939 43520
132.457787236 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daa58b2 0x6daa0982 16 2147483647 43520 5520 29312
132.457846988 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daa6f52 0x6daa0f2a 17 2147483647 46336 6086 29312
132.459445006 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daa6f52 0x6daa14d2 18 2147483647 49280 6584 29312
132.459453782 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daa6f52 0x6daa1a7a 19 2147483647 52224 7219 29312
132.460760400 100.64.0.1: 5001 100.64.0.2: 60424 1480 0xe4249c61 0xe4249c61 10 2147483647 29312 3939 55040
132.462204295 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daa9142 0x6daa2022 20 2147483647 55040 7777 29312
132.462220184 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daa9c92 0x6daa25ca 21 2147483647 57984 8122 29312
132.462223811 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daa9c92 0x6daa2b72 22 2147483647 60928 8426 29312
132.462313259 100.64.0.1: 5001 100.64.0.2: 60424 1480 0xe4249c61 0xe4249c61 10 2147483647 29312 3939 63744
132.463578439 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daa9c92 0x6daa311a 23 2147483647 63744 8451 29312
132.463592575 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daab8da 0x6daa36c2 24 2147483647 66688 8643 29312
132.463620518 100.64.0.1: 5001 100.64.0.2: 60424 1480 0xe4249c61 0xe4249c61 10 2147483647 29312 3939 69504
132.465613391 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daac9d2 0x6daa3c6a 25 2147483647 69504 8812 29312
132.465684163 100.64.0.1: 5001 100.64.0.2: 60424 1480 0xe4249c61 0xe4249c61 10 2147483647 29312 3939 72448
132.466932161 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daacf7a 0x6daa4212 25 25 72448 9213 29312
132.466959202 100.64.0.1: 5001 100.64.0.2: 60424 1480 0xe4249c61 0xe4249c61 10 2147483647 29312 3939 78208
132.469737756 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daacf7a 0x6daa4d62 25 25 78208 9708 29312
132.469812266 100.64.0.1: 5001 100.64.0.2: 60424 1480 0xe4249c61 0xe4249c61 10 2147483647 29312 3939 84096
132.471593813 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daae61a 0x6daa58b2 25 25 84096 10748 29312
132.471628128 100.64.0.1: 5001 100.64.0.2: 60424 1480 0xe4249c61 0xe4249c61 10 2147483647 29312 3939 89856
132.476697992 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daaf16a 0x6daa6402 25 25 89856 11457 29312
132.476915269 100.64.0.1: 5001 100.64.0.2: 60424 1480 0xe4249c61 0xe4249c61 10 2147483647 29312 3939 95616
132.478702961 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6daaf712 0x6daa6f52 25 25 95616 13205 29312
132.478762763 100.64.0.1: 5001 100.64.0.2: 60424 1480 0xe4249c61 0xe4249c61 10 2147483647 29312 3939 110080132.480604904 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6dab1902 0x6daa8b9a 25 25 110080 16157 29312
132.480715862 100.64.0.1: 5001 100.64.0.2: 60424 1480 0xe4249c61 0xe4249c61 10 2147483647 29312 3939 115840
132.481991792 100.64.0.2: 60424 100.64.0.1: 5001 32 0x6dab1eaa 0x6daa96ea 25 25 115840 16985 29312
132.482042226 100.64.0.1: 5001 100.64.0.2: 60424 1480 0xe4249c61 0xe4249c61 10 2147483647 29312 3939 121728
Postscript

Even if the number of elements is 25620, it will be displayed after waiting for a long time.
However, I am concerned that the processing is heavy. Is there any way to make the process lighter?

Final version of the program
import numpy as np
import matplotlib.pyplot as plt

time_1 = []
cwnd_1 = []
#Open the file.
with open ('tcpout.txt') as f:
    lines = f.readlines ()

# Extract the line I want to graph in the text file.
l_1 = [line for line in lines if '5001 32' in line]
#Extract the required values ​​for the graph from the extracted rows.
for line in l_1:
    line_split = line.split ("")
    time_1.append (float (line_split [0]))
    cwnd_1.append (int (line_split [6]))
print (type (time_1 [1]))
print (type (cwnd_1 [1]))
print (len (time_1))
print (len (cwnd_1))
#List graphing. I want to graph it with a scatter plot.
plt.title ("track cwnd")
plt.xlabel ("Time")
plt.ylabel ("cwnd")
plt.plot (time_1, cwnd_1,'.')
# plt.scatter (time_1, cwnd_1)
plt.show ()
  • Answer # 1

    From experience, it seems that 25620 is not so many.
    Since there are many elements, it is unlikely that it will not work.

    For example

    plt.scatter (time_1, cwnd_1)->plt.plot (time_1, cwnd_1,'.')


    Try as.

    print (type (time_1), type (cwnd_1))


    Make sure that it is the intended type.
    It may be good to take a look.

    If the cause is a large number of elements

    plt.scatter (time_1 [: 20], cwnd_1 [:20])


    If you plot only 20 pieces, it should work.
    Please try this as well.