0

Hi I am trying to make a scatter plot and annotate data points with real value of each point but just the yLabel value it mean take real value of the point and plot it near to the point

python code

import serial # import Serial Library
import time #import time 
import numpy  # Import numpy
import matplotlib.pyplot as plt #import matplotlib library
from drawnow import *


temperature= []
vitesse= []
charge= []
current= []

arduinoData = serial.Serial('com5', 9600) #Creating our serial object named       arduinoData
plt.ion() #Tell matplotlib you want interactive mode to plot live data
cnt=0



def makeFig(): #Create a function that makes our desired plot

plt.subplot(2,2,1)
plt.title('Live Streaming Temperature Sensor Data')
plt.ylabel('Temperature C')
plt.grid(True)
plt.plot(temperature, 'ro-')

plt.subplot(2,2,2)
plt.title('Live Streaming Speed Sensor Data')
plt.ylabel('Speed KM/H')
plt.grid(True)
plt.plot(vitesse, 'bo-')

plt.subplot(2,2,3)
plt.title('Live Streaming SOC Sensor Data')
plt.ylabel('Battery Charge %')
plt.grid(True)
plt.plot(charge, 'go-')

plt.subplot(2,2,4)
plt.title('Live Streaming Current Sensor Data')
plt.ylabel('Current A')
plt.grid(True)
plt.plot(current, 'yo-')




while True: # While loop that loops forever
while (arduinoData.inWaiting()==0): #Wait here until there is data
    pass #do nothing
arduinoString = arduinoData.readline() #read the line of text from the  serial port
dataArray = arduinoString.split(';')   #Split it into an array called  dataArray
temp = float (dataArray[0])
vite = float (dataArray[1])
char = float (dataArray[2])
curr = float (dataArray[3])
temperature.append(temp)                     #Build our temperature array by  appending temp readings
vitesse.append(vite)                     #Build our vitesse array by appending temp readings
charge.append(char)                     #Build our charge array by appending temp readings
current.append(curr)                     #Build our current array by appending temp readings
drawnow(makeFig)                       #Call drawnow to update our live graph
plt.pause(0.00001)
cnt=cnt+1
if(cnt>50):
    temperature.pop(0)
    vitesse.pop(0)
    charge.pop(0)
    current.pop(0)

any ideas ?????

2 Answers 2

1

use the annotate() function to create labels attached to specific points in your plot.

see http://matplotlib.org/users/annotations_intro.html

and http://matplotlib.org/examples/pylab_examples/annotation_demo2.html

Sign up to request clarification or add additional context in comments.

3 Comments

please give me an exemple because im new with python
because it's a live plot
I can't because you haven't provide your entire code. the annotate() should go in your drawnow() function
0

If I understood what you were looking for, you should use plt.ticklabel_format(useOffset=False) at the end of every subplot. So that, you are going to fix the y scale. Use plt.ylim(m,n) to set the limits of the y axe, where "m" is the beggining of the axe and "n" is the end.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.