Shimoku docs
Search…
⌃K

Colored labels

Color and shape are great tools to convey information, so we added a flexible way to do just that with tables!
Our tables now have the option to add labels to each entry point, these labels have multiple options to define its color and shape using a comprehensive dictionary as the parameter for the s.plt.table method.
Shimoku table with colored labels

Configurations

This is a flexible feature and it can be used in simple and complex ways, so we will explain it's capabilities separated by complexity.

Basic configuration

To activate the labels you have to provide a dictionary as the parameter label columns, this dictionary has to define the color for each column that will have labels. The default colors that you can use are the following:
This colors represent abstract ideas and they can be customized for any business, they aren't linked to predefined colors.
It is highly recommended to always use the default colors
data_ = [
{'date': dt.date(2021, 1, 1), 'x': 5, 'y': 5, 'labelsA': 'A', 'labelsB': 'B'},
{'date': dt.date(2021, 1, 2), 'x': 6, 'y': 5, 'labelsA': 'B', 'labelsB': 'Z'},
{'date': dt.date(2021, 1, 3), 'x': 4, 'y': 5, 'labelsA': 'C', 'labelsB': 'W'},
{'date': dt.date(2021, 1, 4), 'x': 7, 'y': 5, 'labelsA': 'B', 'labelsB': 'T'},
{'date': dt.date(2021, 1, 5), 'x': 3, 'y': 5, 'labelsA': 'A', 'labelsB': 'Z'},
]
label_columns: Dict = {'labelsA': 'main', 'labelsB': 'active'}
shimoku.plt.table(
data=data_,
menu_path='Shimoku tables',
order=0,
label_columns=label_columns,
)
The result of executing the previous code is:
Basic labels with default colors

Variants configuration

For each color that is defined you can choose the type of variant that you want to see, the options are:
As it has been shown before the default configuration is outlined, rectangle. You can defined de the desired variant configuration by passing a tuple as a color with the color definition in the first position and then the variant options, like so:
(color_definition, variant_option_1, Optional(variant_option_2))
When executing the following code:
data_ = [
{'date': dt.date(2021, 1, 1), 'x': 5, 'y': 5, 'labelsA': 'A', 'labelsB': 'B'},
{'date': dt.date(2021, 1, 2), 'x': 6, 'y': 5, 'labelsA': 'B', 'labelsB': 'Z'},
{'date': dt.date(2021, 1, 3), 'x': 4, 'y': 5, 'labelsA': 'C', 'labelsB': 'W'},
{'date': dt.date(2021, 1, 4), 'x': 7, 'y': 5, 'labelsA': 'B', 'labelsB': 'T'},
{'date': dt.date(2021, 1, 5), 'x': 3, 'y': 5, 'labelsA': 'A', 'labelsB': 'Z'},
]
label_columns: Dict = {'x': 'main',
'y': 'active',
'labelsA': ('error', 'filled'),
'labelsB': ('caution', 'filled', 'rounded')}
shimoku.plt.table(
data=data_,
menu_path='Shimoku tables',
order=0,
label_columns=label_columns,
)
The result is:
Label variants with default colors

Custom colors configuration

Even if we recommend using the default colors there are situations in which a specific color is needed. We have three ways to define specific colors, by name of a common color, by hexadecimal notation of RGB or by list of values of RGB.
The common color list that can be used is:
The other two definitions use the RGB standards, one uses the hexadecimal representation:
#000000 - #FFFFFF
the other uses a list representation ( [R,G,B] ):
[0, 0, 0] - [255, 255, 255]
If we execute the following code:
data_ = [
{'date': dt.date(2021, 1, 1), 'x': 5, 'y': 5, 'labelsA': 'A', 'labelsB': 'B'},
{'date': dt.date(2021, 1, 2), 'x': 6, 'y': 5, 'labelsA': 'B', 'labelsB': 'Z'},
{'date': dt.date(2021, 1, 3), 'x': 4, 'y': 5, 'labelsA': 'C', 'labelsB': 'W'},
{'date': dt.date(2021, 1, 4), 'x': 7, 'y': 5, 'labelsA': 'B', 'labelsB': 'T'},
{'date': dt.date(2021, 1, 5), 'x': 3, 'y': 5, 'labelsA': 'A', 'labelsB': 'Z'},
]
label_columns: Dict = {'x': 'blue',
'y': '#00FF00',
'labelsA': ([200, 0, 0], 'filled'),
'labelsB': ('orange', 'filled', 'rounded')}
shimoku.plt.table(
data=data_,
menu_path='Shimoku tables',
order=0,
label_columns=label_columns,
)
Labels with custom colors

Multiple configurations per column

Sometimes you will need to have different colors and shapes for values in the same column, so we added two ways to handle this situation, color definition per value, or, in case of numeric values, per range of values. To define multiple colors per column you will have to use a dictionary instead of a color or variant, this dictionary will thell which values of the column will have which color.

One value one color:

Here we just define a color for each value:
label_columns = {
column_1: {
value_1_1 : color_definition_1_1,
value_1_2 : color_definition_1_2,
},
column_2: {
value_2_1 : color_definition_2_1,
value_2_2 : color_definition_2_2,
}
}

Range of values:

In this case we use a tuple to define a range of values that will have the same color configuration:
label_columns = {
column_1: {
(ini_1_1, fin_1_1) : color_definition_1_1,
(ini_1_2, fin_1_2) : color_definition_1_2,
},
column_2: {
(ini_2_1, fin_2_1) : color_definition_2_1,
(ini_2_2, fin_2_2) : color_definition_2_2,
}
}
The definitions of color admit all previous configuration options.
If we execute the following code:
from numpy import inf
data_ = [
{'date': dt.date(2021, 1, 1), 'x': 5, 'y': 5, 'labelsA': 'A', 'labelsB': 'B'},
{'date': dt.date(2021, 1, 2), 'x': 6, 'y': 5, 'labelsA': 'B', 'labelsB': 'Z'},
{'date': dt.date(2021, 1, 3), 'x': 4, 'y': 5, 'labelsA': 'C', 'labelsB': 'W'},
{'date': dt.date(2021, 1, 4), 'x': 7, 'y': 5, 'labelsA': 'B', 'labelsB': 'T'},
{'date': dt.date(2021, 1, 5), 'x': 3, 'y': 5, 'labelsA': 'A', 'labelsB': 'Z'},
]
label_columns: Dict = {
'x': {
(-inf, 4): ('warning' , 'rectangle', 'filled'),
(4, 6): ('#00AA33' , 'rectangle', 'filled'),
(6, inf): ([50, 150, 255], 'rounded' , 'filled'),
},
'y': '#00FF00',
'labelsA': ([200, 0, 0], 'filled'),
'labelsB': {
'B': 'black',
'Z': ('cyan' , 'rounded' , 'outlined'),
'W': ('#000000' , 'rectangle', 'filled' ),
'T': ([0, 255, 255], 'rectangle', 'filled' ),
}
}
shimoku.plt.table(
data=data_,
menu_path='Shimoku tables',
order=0,
label_columns=label_columns,
)
The result is:
Diferent color configurations per column
All of the functionalities described in this page can be used with suffixes
Last modified 2mo ago