Grid colormap with colorized circles

12 次查看(过去 30 天)
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:

采纳的回答

Bjorn Gustavsson
Bjorn Gustavsson 2022-11-10
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 个评论
RoboTomo
RoboTomo 2022-11-18
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
Bjorn Gustavsson
Bjorn Gustavsson 2022-11-18
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Purple 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by