0

Hi everybody I am trying to do something easy in Python but for me, nothing seems to be easy. What I want to do is to plot a grid of nxn automatically that is when I change the numbers in (make) for instance (4,4) to plot a 4X4 grid if I write (10,10) to plot a 10X10 grid, and so on. My code is below. Any help, please

import matplotlib.pyplot as plt

import numpy as np

def make(X,Y):

    x, y = np.indices((X,Y))


    sqr = (x==0) & (y==0)


    for i in range (X):
         for j in range (Y):
         
              sqr = (x==i) & (y==j) 
          
          
    plt.show()
    plt(sqr)

make(10,10)
  • Do you have an example of the expected output (manually)? – miquelvir Mar 26 '21 at 11:47
  • well, I don't know how to add a picture in my comment. I just want to have a plot with a grid. When I choose (3,3) to get a 3X3 grid of 9 squares for (4,4) a 4X4 grid of 16 squares, for (3,4) a 3x4 Grid with 12 squares, and so on – Aggelos Vassilakos Mar 26 '21 at 12:20
  • 1
    but what is a "square"? is it a 0? or do you want to have an actual grid using matplotlib? – miquelvir Mar 26 '21 at 12:25
  • Yes, exactly I want an actual grid using matplotlib. Sorry for my ignorance but I have started to learn Python 3 months ago so I am not familiar with it – Aggelos Vassilakos Mar 26 '21 at 12:45
  • This question has already been answered [here](https://stackoverflow.com/questions/8209568/how-do-i-draw-a-grid-onto-a-plot-in-python) – miquelvir Mar 26 '21 at 12:47

0 Answers0