简体   繁体   中英

Differentiate data points with color in a 3D stem plot Matlab

Say I have a matrix (named as data) with multiple rows and columns. I am plotting using stem3 to get a 3D view.

    col1 col2 col3
row1
row2
row3
...

col1 and col2 are used as x and y axes. col3 is used as z axis.

stem3(data(:,1),data(:,2),data(:,3),'red')

在此处输入图片说明

Is there a way that I can manipulate the color of those data points, in which the data points with value greater than the height 500 are blue, while the rest remain red? Thanks for your help!

The easiest thing is going to be to simply create two different stem3 plots. You will create one that only shows the values that are greater than your cutoff (500) and make it blue. Then you'll create one that is all the others using red markers.

% Logical array to determine which population each point belongs to
isAbove = data(:,3) > 500;

stem3(data(isAbove,1), data(isAbove,2), data(isAbove,3), 'b');

hold on

stem3(data(~isAbove,1), data(~isAbove,2), data(~isAbove,3), 'r');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM