Issue
I have to generated thousands of X, Y pairs that are evenly spaced and I'm trying to find a simple way of doing this in Python. I've created two lists for X and Y values and I'm trying to merge these into a list to create a visual similar to the colored plot, however, I'm not fully understanding how to join the lists in an array and my code is resulting in the black and white plot of points. Clearly I'm missing something in the joining but I can't figure it out.
x = np.arange(0, 100, 5)
y = np.arange(0, 100, 5)
test=np.column_stack((x,y))
plt.plot(x, y, 'o', color='black');
Current outcome:
Desired outcome (numbers are are different by I'm trying to generate a similar xy grid):
Solution
People often reach for numpy.meshgrid()
and friends for this. A basic example:
import matplotlib.pyplot as plt
import numpy as np
x, y = np.meshgrid(
np.arange(0, 100, 5),
np.arange(0, 100, 5),
sparse=False)
plt.scatter(x, y, c=x+y, s=70)
Answered By - Mark
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.