matplotlib 绘制实时数据仅作为散点而不是直线进行绘制

pxyaymoc  于 2023-10-24  发布在  其他
关注(0)|答案(1)|浏览(111)

我写了下面的代码,试图更新图形时,收到的数据从Rigol浏览器。
问题是当我改变电压时,plt.plot()只显示x和y数据的变化。然而,当我改变为plt.scatter()时,它工作得很好。
你能告诉我我做错了什么吗?

import pyvisa as visa
import os
import numpy as np
import time
import matplotlib.pyplot as plt
import datetime 
from time import sleep

rm = visa.ResourceManager()
print('Connected VISA resources:')
rm.list_resources()
print(rm.list_resources())

figure, ax = plt.subplots(figsize=(10, 8))

dmm = rm.open_resource('USB0::0x1AB1::0x09C4::DM3R251100732::INSTR')
print('Instrument ID (IDN:) = ', dmm.query('*IDN?'))
print("Volts DC   = ", dmm.query(":MEASure:VOLTage:DC?"))
print("DC Current = ", dmm.query(":MEASure:CURRent:DC?"))

f = open('iLog.txt','w')
fStr = "Time, DC Current, Raw\n"
f.write(fStr)

print("Poll rate = 500mS. Will run for 24 hours collecting 172,800 readings")
print("output file = iLog.csv\n\n")
print(" Seconds Count    ", "DC Current", "Raw Meter Response", sep="\t|\t")
print("----------------------------------------------------------------------------------")

for x in range(0, 100):
    rawStr = dmm.query(":MEASure:VOLTage:DC?")
    iStr = rawStr
    rawStr = rawStr.replace ("\n", "") 
    iStr = iStr.replace("\n", "")
    iStr = iStr.replace("#9000000015", "")

    iFlt = round(float(iStr),2)
    now = datetime.datetime.now()
    print(now, iFlt ,rawStr, sep="\t|\t")
    fStr = str(now) + "," + str(iFlt) + "," + rawStr + "\n"
    f.write(fStr)

    plt.plot(now,iFlt) # plt.scatter works but not plot
    plt.gcf().autofmt_xdate()

    # figure.canvas.draw()
    # figure.canvas.flush_events()

   
  
    plt.pause(0.05)
    sleep(1)

f.close()
plt.show()

ghhaqwfi

ghhaqwfi1#

也许你的问题是,你没有绘制一条线,但一个单一的点??一个孤立的点是可见的,如果你设置一个标记样式!
如果这是问题所在,使用这样的东西应该可以解决它:

plt.plot(now,iFlt, marker="o")

相关问题