How to plot several sets (in different colours) with stem3-plotting function?
11 次查看(过去 30 天)
显示 更早的评论
So I have several line array A which has columns [x, y, val1, val2]. For example, I want to have a single stem3-plot, where val1s are red and val2s are blue.
stem3(A(:, 1), A(:, 2), A(:, 3), 'red') % Will plot vals1 in red.
But how to get then vals2 in colour blue to the same stem3-plot?
Tried something similar which works with 2D-stem: http://www.mathworks.se/help/matlab/ref/stem.html ("Plot Multiple Data Series"), but it didn't work
stem3(A(:, 1), A(:, 2), [A(:, 3), A(:, 4)]); "Error using stem3. The length of X must match the number of columns of Z."
stem3(A(:, 1), A(:, 2), [A(:, 3); A(:, 4)]); "Error using stem3. X and Y must be same length as Z or the lengths of X and Y must match the size of Z."
0 个评论
采纳的回答
AJ von Alt
2014-1-20
编辑:AJ von Alt
2014-1-20
You can use hold to overlay multiple plots on one set of axes. The following code demonstrates the concept using stem3 to plot the datasets.
% Random inputs
A = randn(20,3);
B = randn(20,3);
figure;
% Create a 3-D stem plot for dataset A
stem3( A(:,1) , A(:,2) , A(:,3) ,'blue')
hold on; % Activate hold
% Create a 3-D stem plot for dataset B
stem3( B(:,1) , B(:,2) , B(:,3) ,'red')
hold off %turn off hold
legend('A','B')
0 个评论
更多回答(2 个)
Bruno Pop-Stefanov
2014-1-20
If you want to plot two series in the same axes in red and in blue, use hold on like in the following:
figure;
stem3(A(:, 1), A(:, 2), A(:, 3), 'r')
hold on
stem3(A(:, 1), A(:, 2), A(:, 4), 'b')
hold off
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!