0

Here is my code:

import matplotlib.pyplot as plt

x_values = list(range(1,1001))
y_values = (x**2 for x in x_values)
plt.scatter(x_values,y_values,s=10)
#range of axis
plt.axis([0,1100,0,1100000])
plt.show()

Whenever i try to plot a list of numbers through scatter method in python, I always get the error that "matplotlib does not support generatore". Is there any solution?


Image of code

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69

1 Answers1

1

By doing

y_values = (x**2 for x in x_values)

you create a generator.

Make it a list and feed that:

import matplotlib.pyplot as plt

x_values = list(range(1,1001)) 
y_values = [x**2 for x in x_values]   # list - not generator
plt.scatter(x_values,y_values,s=10)

plt.axis([0,1100,0,1100000])
plt.show()

to get

graph

See:

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69