Lists graphically

Is there a quick way (without the overhead of using a graphical interface or graphical module) to visually display 2d and 3d lists.

For example, if I have a 2d array of zeros and ones, I would like to draw a black and white grid in accordance with this array.

I am looking for a module that allows me to do this simply. Like the simplicity of this, matplotlib allows you to draw graphs.

+6
source share
2 answers

The matshow command in matplotlib displays the matrix:

import pylab as p p.matshow(p.array([[0,1],[1,1]]),cmap="Greys") ; p.show() 

This will work for 2d lists. As for 3d lists, I'm not sure I fully understand how you plan to render them.

+7
source

Are you looking for something to run on the command line? If so, you can simply write your little function in a few lines. Something like that:

 >>> matrix = [[0,1,0],[1,1,1],[0,0,1]] >>> convert = lambda x : '■ ' if x == 1 else '□ ' >>> for row in matrix: ... print ''.join([convert(el) for el in row]) ... □ ■ □ ■ ■ ■ □ □ ■ 
+3
source

Source: https://habr.com/ru/post/893258/


All Articles