0

does anyone know how to make a grid using matplotlib which essentially looks like a chess board. It needs to have black and white squares.

Thank you for your help.

  • 1
    Does [this](https://stackoverflow.com/questions/10194482/custom-matplotlib-plot-chess-board-like-table-with-colored-cells) help you? – mosc9575 Dec 30 '20 at 16:18
  • If you plot [this array](https://stackoverflow.com/questions/2169478/how-to-make-a-checkerboard-in-numpy) with `plt.imshow()`, it'll look like a chess board. – Matt Hall Dec 30 '20 at 18:50
  • Thank you both very much for the answers. They both work. – program1232123 Dec 30 '20 at 20:13

1 Answers1

2

An easy way to do this is to set a 2d matrix with elements 0,1 for example as your chessboard. Then use imshow from matplotlib.pyplot and use the gray scale for it.

This is a simple example of a 4 squares chessboard

import matplotlib.pyplot as plt
a = [[0,1],[1,0]]
plt.imshow(a,cmap='gray')
plt.show()
  • Thanks for your answer, do you by any chance know how to get lines between the squares on the grid? – program1232123 Dec 30 '20 at 20:32
  • I never tried that myself but think there are some good advices here https://stackoverflow.com/questions/38973868/adjusting-gridlines-and-ticks-in-matplotlib-imshow – Amel Alhassan Dec 31 '20 at 22:10