woz523
woz523

Reputation: 117

Matplotlib y axis is not ordered

I'm getting data from serial port and draw it with matplotlib. But there is a problem. It is that i cannot order y axis values.

import matplotlib.pyplot as plt
import matplotlib.animation as animation
from deneme_serial import serial_reader

collect = serial_reader()


fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
xs=[]
ys=[]

def animate(i, xs, ys):
    xs = collect.collector()[0]
    ys = collect.collector()[1]
    ax.clear()
    ax.plot(xs)
    ax.plot(ys)
    axes=plt.gca()

    plt.xticks(rotation=45, ha='right')
    plt.subplots_adjust(bottom=0.30)
    plt.title('TMP102 Temperature over Time')
    plt.ylabel('Temperature (deg C)')

ani = animation.FuncAnimation(fig, animate, fargs=(xs,ys), interval=1000)
plt.show()

Below graph is result of above code

https://i.sstatic.net/ug15d.png

Upvotes: 1

Views: 562

Answers (1)

Steven Cunningham
Steven Cunningham

Reputation: 21

This happened to me following the same tutorial.

My issue was the variables coming from my instrument were strings. Therefore, there is no order. I changed my variables to float and that fixed the problem

xs.append(float(FROM_INSTRUMENT))

Upvotes: 1

Related Questions