[英]plot with Matplotlib from tcp data
I am trying trying to plot something with python. 我试图用python绘制一些东西。 I have incoming data that update a float variable each iteration.
我有传入的数据,每次迭代都会更新float变量。 I would like to plot it with matplotlib with respect to time.
我想用matplotlib绘制时间。 This is where I am stuck!
这就是我卡住的地方!
import socket
import sys
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.bind(('', 5027))
socket.listen(5)
client, address = socket.accept()
print("{} connected".format( address ))
while True:
response = client.recv(512)
print(response)
print ("close")
client.close()
stock.close()
response is the string variable. 响应是字符串变量。
import matplotlib.pyplot as plt
import numpy as np
import math
body = '+1.33E+00@-6.54E+00@1.00E+00@-6.53E+00@'
one, two, three, four, five = body.split("@")
signal_1 = float(one)
signal_2 = float(two)
signal_3 = float(three)
signal_4 = float(four)
# Plot
t = 5
plt.plot(t, signal_1,t, signal_2,t, signal_3,t, signal_4,)
plt.show()
body
is the simulated signal of the response variable in the first code. body
是第一个代码中响应变量的模拟信号。 I want to plot the value of signal_1
with respect to time. 我想绘制关于时间的
signal_1
值。 Kindly assist me! 请帮助我!
Each series to plot has only one data point, eg the first one would be (5,1.33)
. 要绘制的每个序列只有一个数据点,例如第一个是
(5,1.33)
。
The plt.plot
command is a line plot. plt.plot
命令是折线图。 However, a line which connects a single point with itself remains invisible. 但是,连接单个点与自身的线仍然不可见。
A possible solution is to set a marker ( marker="o"
) to show at the respective coordinates. 一种可能的解决方案是设置一个标记(
marker="o"
)以在相应的坐标处显示。
plt.plot(t, signal_1,t, signal_2,t, signal_3,t, signal_4, marker="o")
Of course you could also choose different markers for the respecive points, 当然,您也可以为各个要点选择不同的标记,
plt.plot(t, signal_1, "ko", t, signal_2, "bs", t, signal_3, "rd", t, signal_4, "y^")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.