Hi Usman,
I understand that you would like to create polygons on a plot, with each polygon being coloured according to its weight, and obtaining these colours from a predefined colour scheme.
To apply a colour gradient to the faces of polygons created with the “mapshow” command in MATLAB based on weight values, you can use the “FaceColor” property of the polygons. Here's how you can do it:
xbox = [0 0 8.46 8.46; 0 0 8.46666667 8.466667; 0 0 8.46666667 8.466667; 0 0 8.46666667 8.466667];
ybox = [0 5 5 0; 5 10 10 5; 10 15 15 10; 15 20 20 15];
clim([min(weight), max(weight)]);
normalized_color = (color_value - min(weight)) / (max(weight) - min(weight));
color_index = round(normalized_color * (size(cmap, 1) - 1)) + 1;
polygon_color = cmap(color_index, :);
polygon = mapshow(xbox(i, :), ybox(i, :), 'DisplayType', 'polygon', 'LineStyle', 'none');
set(polygon, 'FaceColor', polygon_color);
title('Polygon Color Gradient Based on Weight');
To know more you can refer to the following documentation links:
I hope it helps to resolve your query!