How do I put different color(maps) on a same plot ?
古いコメントを表示
I was wondering if it were possible to have different surface colors on the same plot. For instance, if I want to highlight a ribbon around a sphere with a specific colormap, and have the sphere be unicolor, having it as a reference. I'll put a bit of code to illustrate what I'm trying to do :
% Create the sphere
[X,Y,Z] = sphere;
% Scale it
X = Param.radius * X;
Y = Param.radius * Y;
Z = Param.radius * Z;
% Plot it
sph = surf(SphereAxis, X, Y, Z);
% Esthetics
colormap(cmap);
shading interp;
set(sph, 'FaceColor', [1, 0.85, 0.85]);
lighting gouraud;
daspect([1 1 1]); % change here
alpha 0.2;
light;
view([45 20]);
% colormap(cmap);
hold on;
% Add another plot to it afterwards :
% For instance
% su = surf(SphereAxis, squeeze(U(1, :, :)), squeeze(U(2, :, :)), squeeze(U(3, :, :)));
% Plot.plotreferences.D3.p1 = su;
% shading interp;
% colormap(su, cmap);
On each try of the colormap function, the sphere wouldn't take the desired color and have the colormap color instead. The last one (last line) didn't work because I can't refer a plot handle to a colormap. Is there another function that does what I want to do ? Ideally, I would like to color the plot that I add onto the sphere with respect to a certain function (e.g an energy density function) is there a neat way to achieve something like that ?
EDIT :
Runnable code :
figure('units', 'normalized', 'Outerposition', [0.2 0.2 0.6 0.6]);
cmap = winter;
%% First subplot : sphere alone
subplot(1, 2, 1)
ax1 = gca;
% Create the sphere
[X,Y,Z] = sphere;
sph = surf(ax1, X, Y, Z);
shading interp;
set(sph, 'FaceColor', [1, 0.85, 0.85]);
lighting gouraud;
daspect([1 1 1]); % change here
alpha 0.2;
light;
view([45 20]);
%% Define the ribbon :
N = 100;
el = linspace(-0.5, 0.5, N);
az = linspace(-pi, pi, N);
[A, E] = meshgrid(az, el);
R = ones(size(A));
[Xrib, Yrib, Zrib] = sph2cart(A, E, R);
%% second plot : ribbon and sphere
subplot(1, 2, 2)
ax2 = gca;
% Create the sphere
[X,Y,Z] = sphere;
sph = surf(ax2, X, Y, Z);
shading interp;
set(sph, 'FaceColor', [1, 0.85, 0.85]);
lighting gouraud;
daspect([1 1 1]); % change here
alpha 0.2;
light;
view([45 20]);
hold on;
colormap(cmap);
rib = surf(ax2, Xrib, Yrib, Zrib);
shading interp;
I think I identified the problem : when removing the last line it seems to do what I would want. Unfortunately, I would still like to have the shading feature in my plot. Is there a way to go around it and keep it nevertheless ?
Thank you for your time !
6 件のコメント
Adam Danz
2021 年 5 月 28 日
We can't run your code due to missing variable definitions.
Gronaz
2021 年 5 月 28 日
J. Alex Lee
2021 年 5 月 29 日
surf() will accept a rgb color matrix as an argument after the coordinate positions, is that what you could be after?
Gronaz
2021 年 5 月 29 日
Walter Roberson
2021 年 5 月 29 日
caxis() controls the range of values that is mapped into the color map.
J. Alex Lee
2021 年 5 月 29 日
the color matrix would be literally RGB values...i dont know how much more control over color you could need.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Orange についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!