![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/242258/image.png)
why 'colormap' did not change the color of my plots?
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
prasanth s
el 11 de Oct. de 2019
example:
figure, plot(rand(5))
colormap hot
above code did not change the color of plot.
0 comentarios
Respuesta aceptada
Adam Danz
el 11 de Oct. de 2019
Editada: Adam Danz
el 11 de Oct. de 2019
If you want to change the color of the lines based on a colormap, you can apply those colors to the "ColorOrder" property of the axes.
figure
h = plot(rand(5));
% Create a colormap based on the number of lines in your plot
cmap = hot(numel(h)); %you can use any colormap here
% Apply the colors to the lines
set(gca, 'ColorOrder', cmap)
Alternatively, you can apply the colors to the color handles of line objects,
set(h,{'Color'}, mat2cell(cmap,ones(numel(h),1),3))
Note that if your really want to use "hot", you'll end up with yellow and white lines wich are difficult or impossible to see against the default white axis. In that case you can change the axis colors to some other dark color.
set(gca, 'Color', [.2 .2 .2])
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/242258/image.png)
0 comentarios
Más respuestas (1)
Sulaymon Eshkabilov
el 11 de Oct. de 2019
Hi,
in order to get the colormap effect, the plot has to be 3D (like mesh, surf, etc), e.g.:
H=figure,
[x, y] = meshgrid(linspace(0, 13), linspace(-pi, pi));
Z = exp(cos(x)+sin(y));
mesh(x,y,Z);
colormap(H, hot)
%% An alternative colormap
H=figure,
[x, y] = meshgrid(linspace(0, 13), linspace(-pi, pi));
Z = exp(cos(x)+sin(y));
mesh(x,y,Z);
colormap(H, jet)
Good luck
1 comentario
Adam Danz
el 11 de Oct. de 2019
2D plots can use colormaps, too.
imagesc()
scatter()
etc...
Ver también
Categorías
Más información sobre Orange en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!