필터 지우기
필터 지우기

Use colormap to color axis?

조회 수: 5 (최근 30일)
Roger Breton
Roger Breton 2022년 1월 16일
댓글: Walter Roberson 2022년 1월 17일
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
Roger Breton
Roger Breton 2022년 1월 16일
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 2022년 1월 16일
Why throw in the towel? Didn't my answer below do what you want?

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2022년 1월 16일
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
Roger Breton
Roger Breton 2022년 1월 17일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by