Brendan Stack
Brendan Stack

Reputation: 21

'Type Error: Not implemented for this type' when trying to make a Scatter plot in matplotlib

This is my first matplotlib program, so sorry in advance if this seems like a dumb question.

I'm trying to setup a basic serial connection between an Arduino and a Raspberry Pi. I was planning on starting off with something simple, like sending numbers from the RPI to the Arduino board, having it calculate something (squaring it in my case) and sending back the numbers so the RPi could plot the values individually.

Here is my Arduino code:

void setup(){
   Serial.begin(9600);
}

void loop(){
   if(Serial.available() > 0){
      int inc = Serial.ParseInt();
      inc = pow(inc,2);
      Serial.println(inc);
   }
}

And here is my RPI code:

import serial
ser = serial.Serial('/dev/ttyACM0',9600)
import matplotlib.pyplot as plt

plt.axis([0,20,0,400])
plt.ion()
plt.show()

for i in range(20):
   ser.write(str(i))
   y=int(ser.readline())
   plt.scatte([i],[y],'bo')
   plt.draw()

Everything seems to work completely fine in the loop, but I keep getting an error message saying "Type Error: Not implemented for this type" referring to the 'plt.draw()' function

Any help would be much appreciated!

Upvotes: 2

Views: 1851

Answers (1)

Srivatsan
Srivatsan

Reputation: 9363

It is because you are calling plt.scatter with 'bo' inside.

The above works only for plt.plot !! i.e. specifying both the marker style and colour together.

Whereas for plt.scatter you should instead call it this way:

plt.scatter([i],[y],c='b',marker='o')

This will work!

Upvotes: 4

Related Questions