Reputation: 1221
The following four lines will create a rectangular meshgrid with bottom-left corner as (-5,-5) and top-right corner as (5,5). The width of each cell in the meshgrid will be 0.55 and height will 0.5. Is it possible to just display this created mesh in python? That is, without superimposing on it any other plot of a function?
import numpy as np
x = np.arange(-5, 5, 0.55)
y = np.arange(-5, 5, 0.5)
xx, yy = np.meshgrid(x, y)
I Will be grateful for help. Thanks.
Upvotes: 4
Views: 3484
Reputation: 178
You could plot a zero matrix with pcolormesh
and show the edges.
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(-5, 5, 0.5)
y = np.arange(-5, 5, 0.5)
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.pcolormesh(x, y, np.zeros((len(y)-1, len(x)-1), edgecolor='k')
Upvotes: 0
Reputation: 69172
You can use matplotlib
's plot
to put a point at each point of the grid.
plt.plot(xx, yy, ".k")
plt.show()
Here, this is actually plotting each column as a separate plot, and would give each a separate color, which is why I set ".k"
, where the k
makes every point black. If you don't like this behavior you could do:
plt.plot(xx.flat, yy.flat, ".")
Upvotes: 7