Use colormap to color axis?

3 visualizaciones (últimos 30 días)
Roger Breton
Roger Breton el 16 de En. de 2022
Comentada: Walter Roberson el 17 de En. de 2022
From reading the documentation, it seems axes colors can only be 'uniform'.
Would there be a way to apply a colormap to an axes color property?
  2 comentarios
Roger Breton
Roger Breton el 16 de En. de 2022
Seems all I can possibly control is through the X, Y and ZColor :
set(ax, {'XColor', 'YColor', 'ZColor'}....
The default is [0.15 0.15 0.15] RGB triplet.
I don't see any 'colormap' option here... unless there is a hack? I'm about to throw the towel :(
Image Analyst
Image Analyst el 16 de En. de 2022
Why throw in the towel? Didn't my answer below do what you want?

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 16 de En. de 2022
I think you'd have to use line() to draw colored line segments along the x axis:
plot(1 : 10, 'b.-', 'LineWidth', 2, 'MarkerSize', 30);
xl = xlim()
yl = ylim()
xs = linspace(xl(1), xl(2), 200);
hold on;
colorList = turbo(length(xs));
xAxisWidth = 4;
for k = 1 : length(xs)
thisColor = colorList(k, :);
line([xs(k), xl(end)], [0, 0], 'Color', thisColor, 'LineWidth', xAxisWidth)
end
hold off;
  7 comentarios
Roger Breton
Roger Breton el 17 de En. de 2022
I have no idea where to go look for the reply, Walter.
Meanwhile, I analyse Image Analyst code. This is one of the most interesting and powerful feature of Matlab, to be able to step through the script one line at a time and to be able to inspect every value :
plot(1 : 10, 'b.-', 'LineWidth', 2, 'MarkerSize', 30);
xl = xlim();
yl = ylim();
% y = linspace(x1,x2,n) generates n points. The spacing between the points is (x2-x1)/(n-1)
% xs = linspace(xl(1), xl(2), 200);
% xs = linspace(xl(1), xl(2), 10);
xs = linspace(1, 10, 10);
hold on;
% turbo = colormap array
% colorList = turbo(length(xs)); % 10 Rangées x 3 double, RGB
colorList = winter(length(xs));
% j = colorList(1, :)
% colorList = [0.3 0.9 0.1]
xAxisWidth = 50;
% First coordinate, specified as a vector or a matrix.
% the first coordinate is x-axis position in data units
% the second coordinate is y-axis position in data units
% color = double RGB triplet
% line([xs(1), xl(end)], [0, 0], 'Color', colorList(1, :), 'LineWidth', xAxisWidth)
% line([1, 10], [0, 0], 'Color', colorList(1, :), 'LineWidth', xAxisWidth)
for k = 1 : length(xs)
fprintf('Itération = %i \n',k);
fprintf('ColorList = R%4.2f G%4.2f B%4.2f \n', colorList(k, 1), colorList(k, 2), colorList(k, 3))
thisColor = colorList(k, :);
fprintf('Line Origin (xs(k) x1(end)) = [%i, %i] \n', xs(k), xl(end));
fprintf('thisColor = [R%4.2f G%4.2f B%4.2f] \n', thisColor(1), thisColor(2), thisColor(3));
line([xs(k), xl(end)], [0, 0], 'Color', thisColor, 'LineWidth', xAxisWidth)
end
hold off;
I think it's a good idea. Trouble is to come up with the custom colormap in the first place... My next target for study. Thank you for all your help.

Iniciar sesión para comentar.

Categorías

Más información sobre Red en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by