a heatmap about who dominate the election (democrat or republican) and how much percentage they win at the cell in matlab

Here is the code to create a heatmap in MATLAB that shows the dominance of Democrats or Republicans in an election along with the percentage of votes they received in each cell:

main.m
% Create dummy election data
democrat_votes = [55 62 33 76 89; 36 41 57 62 44; 78 63 58 49 57; 44 51 72 39 66];
republican_votes = [45 38 67 24 11; 64 59 43 38 56; 22 37 42 51 43; 56 49 28 61 34];

% Calculate percentage of votes for each party
total_votes = democrat_votes + republican_votes;
democrat_percent = democrat_votes ./ total_votes * 100;
republican_percent = republican_votes ./ total_votes * 100;

% Set up plot
figure
hold on
colormap(flipud(jet))

% Plot Democrat percentages
democrat_heatmap = heatmap(democrat_percent);
title('Dominance of Democrats in Election')
xlabel('District')
ylabel('Precinct')
colorbar;
democrat_heatmap.ColorLimits = [0 100];

% Overlay Republican percentages
republican_heatmap = heatmap(republican_percent);
republican_heatmap.ColorLimits = [0 100];
republican_heatmap.Colormap = autumn;
alpha(republican_heatmap, 0.5);

% Add labels and legend
legend({'Democrats', 'Republicans'})
927 chars
31 lines

This will create a heatmap that shows the dominance of Democrats in the election, with cells shaded according to the percentage of votes received. Republican dominance is also shown with a translucent overlay. The democrat_votes and republican_votes arrays can be replaced with your own data.

gistlibby LogSnag