I have coordinates of some points that I need to plot and then convert plot to black & white bitmap:

```
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from PIL import Image

plt.scatter(x,y)
plt.tight_layout()
fig1 = plt.gcf()
plt.show()

```

[![enter image description here](https://i.stack.imgur.com/awkQx.png)](https://i.stack.imgur.com/awkQx.png)

```
type(fig1)
matplotlib.figure.Figure

```

How to get from this figure black & white bitmap as numpy array similar to this one:

```
side = 5
image = np.random.choice([0, 1], size=side*side,  p=[.1, .9])
image = image.reshape(side,side)
image = np.expand_dims(image, axis=-1)
print("image.shape: ",image.shape)
plt.imshow(image, cmap=plt.get_cmap('gray'))

image.shape:  (5, 5, 1)

```

[![enter image description here](https://i.stack.imgur.com/Usc7u.png)](https://i.stack.imgur.com/Usc7u.png)

```
print(image.reshape(side,side))

[[1 1 1 0 1]
 [1 1 1 1 1]
 [1 0 1 1 0]
 [1 1 1 1 0]
 [1 1 1 1 1]]

```

**Update 1**

I need also to get resulting bitmap as a numpy array. How to get it?

In case I use solution given by Zephyr:

```
fig, ax = plt.subplots(figsize = (5,5))
ax.hist2d(x, y, cmap = 'Greys', cmin = 0, cmax = 1)
plt.show()

```

I get image different from the scatter plot. And they should be similar:

[![hist2d solution](https://i.stack.imgur.com/8R8bK.png)](https://i.stack.imgur.com/8R8bK.png)

[![Scatter plot](https://i.stack.imgur.com/FP5iE.png)](https://i.stack.imgur.com/FP5iE.png)