How do I put different color(maps) on a same plot ?
Ältere Kommentare anzeigen
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 Kommentare
Adam Danz
am 28 Mai 2021
We can't run your code due to missing variable definitions.
Gronaz
am 28 Mai 2021
J. Alex Lee
am 29 Mai 2021
surf() will accept a rgb color matrix as an argument after the coordinate positions, is that what you could be after?
Gronaz
am 29 Mai 2021
Walter Roberson
am 29 Mai 2021
caxis() controls the range of values that is mapped into the color map.
J. Alex Lee
am 29 Mai 2021
the color matrix would be literally RGB values...i dont know how much more control over color you could need.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Orange finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!