Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to stop dots being cut off at edge of grid

I have a simple grid of dots which I make with:

import numpy as np
import matplotlib.pyplot as plt

# Add blue dots
for x in np.arange(0, 10, 1):
    for y in np.arange(0, 10, 1):
        plt.scatter(x, y, color='blue', s=20)  # Adjust the size (s) as needed
       

# Customize plot
ax = plt.gca()  

ax.set(xlim=(0, 9), ylim=(0, 9), xlabel='', ylabel='')
ax.set_xticks(np.arange(0, 9.01, 1))
ax.set_yticks(np.arange(0, 9.01, 1))
ax.invert_yaxis()
ax.set_aspect('equal', adjustable='box')
ax.tick_params(left=False, bottom=False)
ax.grid()

This looks like:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The dots on the edge of the grid are cut off. How can I show them complete without changing anything else about the picture? I don’t want to extend the grid lines for example.

>Solution :

You can try turning-off the Clipping by setting clip_on to False :

for x in np.arange(0, 10, 1):
    for y in np.arange(0, 10, 1):
        plt.scatter(x, y, color='blue', s=20, clip_on=False) # << here

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading