Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8485569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:41:06+00:00 2026-06-10T20:41:06+00:00

This a very strange problem, where one thing seems to affect a totally different

  • 0

This a very strange problem, where one thing seems to affect a totally different other a lot.

I have an external device (connected through a COM port), that constantly sends the value of a sensor (10 bit sensor = 0-1023).

The code I’m writing takes this data and draws it in a chart.

At present there is a line at the bottom commented out (plt.draw()). Like this, the chart is obviously not drawn properly. In this state though, the input from the serial port is fine, it is as you would expect.

The problem comes when you uncomment that line to allow the chart to be drawn. When you do this, suddenly, the input just comes in as one seemingly random value, and doesn’t change as expected. This random value is printed and logged on the chart.

Here’s the code.

import serial
import matplotlib.pyplot as plt
from collections import deque 

size=50
plt.ion()
q=deque([0]*size)

ser=serial.Serial('COM3',57600)
lastbyte=None

line,= plt.plot(range(0,size),list(q))

if ser.isOpen():
  while True:
     x=ser.readline()
     try:
       x=int(x)
     except ValueError:
       x=0

     if x!=lastbyte:
       print x,
       lastbyte=x

     q.append(x)
     q.popleft()
     d=list(q)

     plt.axis([size,0,0,1024])

     line.set_ydata(d[::-1])

#    plt.draw()                  THIS LINE
ser.close()
plt.ioff()

So is there anything to do with the way I’ve used matplotlib that could mess up the input?

I have tested this extensively with different way to get and process the data, but it alway comes down to the plt.draw() messing it up.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:41:08+00:00Added an answer on June 10, 2026 at 8:41 pm

    After almost giving up on it, the problem’s been fixed!

    I’d noticed that the external device was sending data faster than my program could recieve it, and after fixing this, it worked!

    Magic!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Starting from Android 3.2 I have this strange problem. It's very easy to reproduce:
I have a very strange problem in a Flex 3.4 Datagrid. One of the
I have a very strange problem. The following code gives different results when compiled
This is a very strange problem, and I just hope that I can clearly
This problem is very strange and I'm hoping someone can help me. For the
it is very strange, because this error doesn't happen all the time... I have
This is a very strange problem. I've got a rails app in which I
I have encountered a very strange problem in using jQuery load() . I used
I am seeing a very strange problem on one of my production boxes. We
I have a very strange problem,I don't know whether it is awkward to normal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.