Filter löschen
Filter löschen

Custom colors on plots

8 Ansichten (letzte 30 Tage)
Edward am 28 Sep. 2013
Beantwortet: Image Analyst am 28 Sep. 2013
Hi, i'm trying to plot:
which gives me a straight line,
I also have a third array
I want to plot markers on the plot above whenever height(i) is not equal to 0.
I can do this by using:
plot(xVal,yVal,'ks','markerfacecolor',[0 0 0]);
however this only works for black/default colours. I want to be able to have different shades of blue for each marker depending on how large height(i) is for each point.
How can I get custom colors?

Akzeptierte Antwort

Image Analyst
Image Analyst am 28 Sep. 2013
You can plot them one at a time:
heightDifferences = abs(height - y);
% Find the max height difference.
% This will be put blue. Others will be less blue.
% I.e., on line = black, furthest away = pure blue.
maxHeightDiff = max(heightDifferences(height~=0));
plot(x,y,'ks','markerfacecolor',[0 0 0]);
grid on;
hold on;
for k = 1 : length(height)
if height(k) ~= 0
theColor = [0,0,heightDifferences(k)/maxHeightDiff];
plot(x(k), height(k), 'o', 'markerfacecolor', theColor,...
'MarkerSize', 15);
Or you can call scatter() and pass in the colors if you make theColor an array in the above code.

Weitere Antworten (0)


Community Treasure Hunt

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

Start Hunting!

Translated by