Чтобы установить цвет для некоторых определенных квадратов на сетке, сначала вам нужно убедиться, что data
для этих мест отличается от других.Например, если вы хотите, чтобы цвет первая строка первых двух столбцов и вторая строка первых двух столбцов , вы бы сделали следующее:
# Your data variable starts of having 1's at every location.
# To be able to see different colors, change the data
# at those locations. Here we set the data to 2. It could be
# any number different from 1.
data[0][0] = 2
data[0][1] = 2
data[1][0] = 2
data[1][1] = 2
Вышеприведенное помогает вам изменить цвета для определенных квадратов в сетке.
Если вы хотите указать цвета, отображаемые в вашей сетке, вы должны указать их в аргументе colors вmatplotlib.colors.ListedColormap(colors, name='from_list', N=None)
.
# In this case, 'w' or white will be used for all the 1's in data.
# 'b' or blue will be used for all the 2's and 'r' or red for all the 3's.
# If you want to add new data, you can make it use new colors by adding
# more colors to the colors list.
# If you add new data but not new colors, the last color will be selected
# for the new data.
my_cmap = mpl.colors.ListedColormap(['w', 'b', 'r'])
Ссылка: ListedColorMap
Ссылка: цвета - Matplotlib