0

I could create a white rectangle (square) window in a black meshgrid using the following piece of code:

import numpy as np
import pylab as plt
x = np.zeros(127)
y = np.zeros(127)
x[50:70] = 1
y[50:70] = 1
X, Y = np.meshgrid(x, y)
grating = X*Y
plt.imshow(X*Y)

Utilizing a similar idea, how to plot a circle at the center with some radius?

Mr. T
  • 11,960
  • 10
  • 32
  • 54
  • Matplotlib can, of course, directly [draw circles](https://stackoverflow.com/a/9216646/8881141). But I assume you want to create a numpy array with such a shape [as is shown here](https://stackoverflow.com/a/10032271/8881141). – Mr. T Jan 07 '22 at 13:27
  • I don't wish to just plot the circle. As one can see in my code above, I wish to save it as a 2-D variable and then apply some transformation onto it. – Subrahmanya K N Jan 07 '22 at 13:38
  • Thank you @Mr.T, with some tweaking the approach mentioned in the above link solves my problem. – Subrahmanya K N Jan 07 '22 at 14:17
  • Actually, I would use `np.where` like `filled_circle = np.where(circle < r**2, 1, 0)` but you see the general approach. – Mr. T Jan 07 '22 at 14:25

0 Answers0