Effacer les filtres
Effacer les filtres

How to plot several sets (in different colours) with stem3-plotting function?

14 vues (au cours des 30 derniers jours)
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."

Réponse acceptée

AJ von Alt
AJ von Alt le 20 Jan 2014
Modifié(e) : AJ von Alt le 20 Jan 2014
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')

Plus de réponses (2)

Bruno Pop-Stefanov
Bruno Pop-Stefanov le 20 Jan 2014
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

Jouni Lohikoski
Jouni Lohikoski le 20 Jan 2014
Thanks you both. It ("hold") should be mentioned in the stem3 help page.

Catégories

En savoir plus sur Stem Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by