How to create a color-coded categorical tile chart
Show older comments
Context: I'm working with a M-by-3 dataset that I've categorized into 4 different groups. As part of the visualization of this data, I'm creating a MechE-style 4 view drawing
Problem: In creating the "side" view, I want to have a visualization of which of the 4 groups (color-coded red, green, yellow, and orange) is most prevalent in any given 2-D grid section. I've got my majority vote mask, but...
Question: What is the best graphics function to create a tiled view of categorical data, akin to binscatter or histogram2(__, 'DisplayStyle','tile') but with the colors of each tile defined by a categorical mask?
datO = [[1000000.*rand(4000,1)],[10000.*rand(4000,1)],[250 + 500.*rand(4000,1)]]; %dummy data
%dummy logical masks for categorization
LG = false(4000,1); LG([1:4:4000]) = true;
LO = false(4000,1); LO([2:4:4000]) = true;
LY = false(4000,1); LY([3:4:4000]) = true;
LR = false(4000,1); LR([4:4:4000]) = true;
xbins = [min(datO(:,1)):12500:max(datO(:,1))]; ybins = [min(datO(:,3)):12:max(datO(:,3))]; %hist bins
x1 = zeros(numel(xbins)-1,numel(ybins)-1,4); %preallocation for best practice
x1(:,:,1) = histcounts2(datO(LG,1),datO(LG,3),xbins,ybins); %Green counts
x1(:,:,2) = histcounts2(datO(LO,1),datO(LO,3),xbins,ybins); %orange counts
x1(:,:,3) = histcounts2(datO(LY,1),datO(LY,3),xbins,ybins); %yellow counts
x1(:,:,4) = histcounts2(datO(LR,1),datO(LR,3),xbins,ybins); %red counts
[~,x2] = max(x1,[],3); x2(~any(x1,3)) = 0; %majority category by bin & recover empty bins
%Now how best to plot this? AFAIK, I cannot directly control the tile
%colors in histogram2 or binscatter.
Accepted Answer
More Answers (0)
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!