Source code for radtools.decorate.array

# RAD-tools - Sandbox (mainly condense matter plotting).
# Copyright (C) 2022-2024  Andrey Rybakov
#
# e-mail: anry@uv.es, web: rad-tools.org
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

import numpy as np
from termcolor import colored

__all__ = ["print_2d_array"]






if __name__ == "__main__":
    array = [[1, 2], [3, 4], [52414345345, 6]]
    print_2d_array(array)
    array = [[0, 1.0, -0.0], [1, 1, 1]]
    print_2d_array(array)
    array = [[1, 2], [3, 4], [5, 6]]
    print_2d_array(array)
    print_2d_array(array, fmt="10.2f")
    print_2d_array(array, borders=False)
    print_2d_array(array, shift=3)
    array = [[1, 2], [3, 4], [52414345345, 6]]
    print_2d_array(array, fmt="10.2E")
    array = [[1, 2 + 1j], [3, 4], [52, 6]]
    print_2d_array(array)
    print_2d_array(array, fmt="4.2E")
    array = [[1, 2 - 1j], [3, 4], [52, 6]]
    print_2d_array(array)
    array = [[1, 1j], [3, 4], [52, 6]]
    print_2d_array(array)
    print_2d_array([])
    print_2d_array([[]])
    array = [[1, 2], [3, 4], [52414345345, 6]]
    print_2d_array(array)

    print_2d_array(array, header_row=["a", "b"])
    print_2d_array(array, header_row=["a", "adfadsasfdb"])
    print_2d_array(array, footer_row=["a", "b"])
    print_2d_array(array, header_column=["a", "b", "c"])
    print_2d_array(array, footer_column=["a", "b", "c"])
    print_2d_array(array, footer_column=["a1234234123", "b", "c"])
    print_2d_array(array, header_row=["", "a", "b"], header_column=["a", "b", "c"])
    print_2d_array(array, footer_row=["a", "b", ""], footer_column=["a", "b", "c"])
    print_2d_array(
        array,
        header_row=["", "a", "b", ""],
        header_column=["a", "b", "c"],
        footer_row=["", "a", "b", ""],
        footer_column=["a", "b", "c"],
        shift=3,
    )
    print_2d_array(
        array,
        header_row=["", "a", "b"],
        header_column=["a", "b", "c"],
        footer_row=["", "a", "b"],
    )

    print_2d_array([1, None], header_row=["a", "b"])
    print_2d_array([None, 1])
    print_2d_array([None, 1], header_row=["a", "b"])
    print_2d_array([1, None, 1], header_row=["a", "b", "c"])
    print_2d_array(
        array,
        header_row=["", "a", "b", ""],
        header_column=["a", "b", "c"],
        footer_row=["", "a", "b", ""],
        footer_column=["a", "b", "c"],
        borders=False,
    )
    array = [[1, 2], [3, 4], [5, 6 + 1j]]
    print_2d_array(array, header_row=["a", "b"], fmt="^.2f")