3

The windows for plotting shows up but nothing appears and i get this ValueError: x and y must have same first dimension

import psutil
import matplotlib.pyplot as plt
import matplotlib.animation as animation

a = [i for i in range(1000)]
ram_avaliable = []
fig, ax = plt.subplots()

def update(n):
    ram = psutil.virtual_memory()
    ram_avaliable.append(float(ram[1])/1073741824)
    print (a[n],ram_avaliable[n])
    ax.plot(a[n],ram_avaliable[n])

ani = animation.FuncAnimation(fig,update,interval=100)
plt.show()
0

1 Answer 1

1

Your code as posted runs without errors for me. The only change I had to make for points to show up was add a marker style to the plot command.

This is because when you call plot you are plotting a new line. The reason it wasn't showing up before is because the default line style is to connect points with lines - since there is only one point per plotted line, there's nothing to connect to. Changing the marker style to one that shows points fixes this, e.g.

ax.plot(a[n],ram_avaliable[n], 'ro')

causes points to be plotted in red circles.

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

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.