Matrix display with text

Hi All,

is there a nice way similar to “matrix display” that could show also text.
Splitting up the list below into 5 panels isn’t a fancy way of showing results.
Preferably without using third-party plugins like Human.

[‘detail’, ‘Orginal Area’, ‘New Area’, ‘Area difference’, ‘distance’, 0.0, 858922.282672682, 858923.8709535187, ‘0.0%’, 2.5139757993742657, 1.0, 474914.8516458379, 474913.53620281606, ‘-0.0%’, 65.99713493501264, 2.0, 446538.48334372113, 446597.82309198694, ‘0.0%’, 8.090157128402202]

Best regards

String formatting, e.g.

l = ['detail', 'Orginal Area', 'New Area', 'Area difference', 'distance', 0.0, 858922.282672682, 858923.8709535187, '0.0%', 2.5139757993742657, 1.0, 474914.8516458379, 474913.53620281606, '-0.0%', 65.99713493501264, 2.0, 446538.48334372113, 446597.82309198694, '0.0%', 8.090157128402202]


nested_list = list(zip(*[iter(l)]*5))

widths = [len(x) for x in nested_list[0]]

s = ' | '.join(x for x in nested_list[0]) + '\n'

for row in nested_list[1:]:
    s += ',  '.join('%{}.{}s'.format(width,width) % x for (x, width) in zip(row, widths))
    s += '\n'

print(s)

gives:

detail | Orginal Area | New Area | Area difference | distance
   0.0,  858922.28267,  858923.8,             0.0%,  2.513975
   1.0,  474914.85164,  474913.5,            -0.0%,  65.99713
   2.0,  446538.48334,  446597.8,             0.0%,  8.090157

I like the tabulate module for printing tables:

# r: tabulate

from tabulate import tabulate


l = ['detail', 'Orginal Area', 'New Area', 'Area difference', 'distance', 0.0, 858922.282672682, 858923.8709535187, '0.0%', 2.5139757993742657, 1.0, 474914.8516458379, 474913.53620281606, '-0.0%', 65.99713493501264, 2.0, 446538.48334372113, 446597.82309198694, '0.0%', 8.090157128402202]
nested_list = list(zip(*[iter(l)]*5))

print(tabulate(
    nested_list, headers="firstrow", stralign="right",
    floatfmt=[".0f", ".1f", ".1f", "f", ".4f"]
))

  detail    Orginal Area    New Area    Area difference    distance
--------  --------------  ----------  -----------------  ----------
       0        858922.3    858923.9               0.0%      2.5140
       1        474914.9    474913.5              -0.0%     65.9971
       2        446538.5    446597.8               0.0%      8.0902
3 Likes

Awesome, thanks both of you!
100% spot on what I needed

i can not loat tabulate in ghpython scrpt in grasshopper , how can i fix this problem ?

@zahra_mahmoudi Are you using python3 in Rhino 8 and is tabulate installed in your Rhino 8 python3 installation? Did you add the r: tabulate line at the top of your script?

Here’s a native GhPython solution:


240919_PadPrintStrings_00.gh (5.4 KB)

The panel probably need to use a monospaced font for this to work (e.g. Consolas).

Edit: With justification options:


240919_PadPrintStrings_01.gh (6.0 KB)

1 Like

Nice. It is possible to add an additional input for data to be displayed? Also would be great if the with of the columns can be variable, using the maximum with of the data in each individual column instead of using the biggest width, in this case looks like all the columns are using the width of the Area difference column.


Matrix_Text_add_data_input.gh (7.5 KB)

This feels/looks a bit wonky (end-of-day here), but maybe something like this:


240919_PadPrintStrings_02.gh (8.7 KB)

Also the code assumes that all “cells” have data, should probably add some checks and such.

1 Like

Much better. Thank you and have a good evening.

1 Like