Grid colormap with colorized circles

In every node in the grid (9x8) I am rotating some workpiece by 30 degrees and calculating values for every rotation (Fig.1). Each rotation values are stored in sol_mat_MAN_all, and mean values of those 12 rotations are stored in mean_man_all. For every node (plot_points) I plot scatter3 diagram with mean values, so basically one colorized dot is based on mean value of all 12 rotations.
%% PLOT COLORMAP
load sol_mat_MAN_all.mat; % Load rotation values
load plot_points.mat; %Load plot points
mean_man_all=mean(sol_mat_MAN_all,2); % Mean rotation value for each grid point
% max_man_all=max(sol_mat_MAN_all,[],2); % Max rotation value for each grid point
%Plot
scatter3(plot_points(:,1),plot_points(:,2),plot_points(:,3),50, mean_man_all,'filled'); %Plot average mean value for every point
xlabel('X [m]'); ylabel('Y [m]'); zlabel('Z [m]');
colorbar; oldcmap = colormap('jet'); colormap(flipud(oldcmap)); hold on;
What I want to do now, is separate rotations and visualize them individually, like some kind of pie chart. Instead of having one colorized dot/circle I want to have this circle cut into 12 pieces where each piece will have its own color based on its rotation value. I have tried some bubble pie plot functions (https://www.mathworks.com/matlabcentral/fileexchange/98874-bubble-pie-chart?s_tid=blogs_rc_5) but I was unable to link values with colormap. Color wheels are also interested but it seems complicated to input my own colormap and plot the whole thing correctly in the grid.
Note that first value is zero rotation (0 degrees) and starts at the right side (Fig.1). My original scatter plot is in 3D where Z-axis is fixed, but here 2D plot is more appropriate. This or something similar should be the final plot, but with correct color for each rotation:

 Accepted Answer

Something like this shouldn't be too complicated to cook up. Perhaps this is a start:
function h = cwheel(x0,y0,phi0,r,nspokes)
% CWHEEL - simple colour-wheel
%
if nargin < 5 || isempty(nspokes)
nspokes = 18;
end
if nargin < 4 || isempty(r)
r = 1;
end
phi = linspace(0,2*pi,nspokes+1);
[phi,R] = meshgrid(phi,[0 r]);
v = repmat(linspace(0,1,nspokes+1),2,1);
h = pcolor(x0+R.*cos(phi-phi0),y0+R.*sin(phi-phi0),v);
You can run this like this to get something like your second graph:
qwe = peaks(14);
[x0,y0] = meshgrid(1:14);
for i1 = 1:14,
for i2 = 1:14,
h = cwheel(x0(i1,i2),y0(i1,i2),qwe(i1,i2),0.4,12);
hold on
end
end
axis auto
colormap(hsv)
Then if you need different wheels to span different ranges you'll have to add that to the cwheel-function instead of having v span 0-1 every time. You might also prefer to have smoother colour-wheel and only plot a couple of spokes, but that's a minor adjustment (increase the number of elements in v, set shading to flat or interp and plot the spokes you want separately).
HTH

4 Comments

Thank you for your answer and sorry for my late reply. If I use your example, variable 'qwe' is defining the color, right? 'qwe' is 14x14 and x0,y0 are also 14x14. So here, there is only one color input in to the color wheel function (qwe value from the for loop). How can I input multiple color inputs for different rotations?
Maybe I am not understanding your answer correctly, but just in case I am attaching pdf document with more detailed description of my problem. Below is also your modified code for my grid in which I want to input multiple rotations but was unsuccessful.
X=1:1:8;
Y=1:1:9;
[x0, y0] = meshgrid(X, Y);
for i1 = 1:9 % Nr. of rows
for i2 = 1:8 % Nr. of columns
h = cwheel(x0(i1,i2),y0(i1,i2),sol_mat_MAN_all(i1,i2),0.4,12);
hold on
end
end
axis auto
colormap(hsv)
The way I interpreted your first question and figure was that for each point you would have a simple phase-shift of your color-wheel. So that's roughly what I implemented. The qwe-variable is then just that phase-shift of the angles in the wheel.
That's now obviously not what you want. What you want seems more like a "pcolor-plot" with pie-sliced sections of arbitrary values. That should be possible to achive. Something like this:
function h = cwheel2(x0,y0,I,r,phi0)
% CWHEEL - simple colour-wheel
%
nspokes = numel(I);
if nargin < 4 || isempty(r)
r = 1;
end
if nargin < 5 || isempty(phi0)
phi0 = 0;
end
phi = linspace(0,2*pi,nspokes+1);
[phi,R] = meshgrid(phi,[0 r]);
v = repmat(I(:)',2,1);
h = pcolor(x0+R.*cos(phi-phi0),y0+R.*sin(phi-phi0),v(:,[1:end,end]));
shading flat % if you prefer
Which you can test like this:
vals = peaks(12);
[x0,y0] = meshgrid(1:12);
clf
for i1 = 1:12,
for i2 = 1:12,
hold on
cwheel2(i1,i2,vals(i1,:),0.4,randn(1));
end
end
shading faceted
Here I simply plotted the same row of vals in each column of wheels with random phase-shifts. One point to note here is that all wheels are on the same intensity-scale, you might prefer to normalize each to a fixed intensity interval, but you can easily do that. And further change the circular wheel to an elliptical if you so prefer.
Thank you again for taking your time to post a solution. I have managed to modify your functions according to my needs and now is working great. I am posting my code and plot below:
function h = cwheel1(x0,y0,I,r)
nspokes = numel(I);
phi = linspace(0,2*pi,nspokes+1);
[phi,R] = meshgrid(phi,[0 r]);
v = repmat(I(:)',2,1);
h = pcolor(x0+R.*cos(phi),y0+R.*sin(phi),v(:,[1:end,end]));
colorbar; oldcmap = colormap('jet'); colormap(flipud(oldcmap)); hold on;
clear;clc;
load sol_mat_MAN_all.mat; % Load rotation values
X=1:1:8;
Y=1:1:9;
[x0, y0] = meshgrid(X, Y);
Grid_points = [x0(:) y0(:)];
for i1=1:72
hold on
x0=Grid_points(i1,1);
y0=Grid_points(i1,2);
cwheel1(x0,y0,sol_mat_MAN_all(i1,:),0.4);
end
Great! Happy that it helped.
When it comes to fine-tune figures like this one could take the Leonardo daVinci approach and never be sufficiently happy and continue to tinker till end of time - but that doesn't often justify the effort unless you're Leonardo. But one function you might be interested for this type of plots is rose.
All the best.

Sign in to comment.

More Answers (0)

Products

Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!