How to plot several sets (in different colours) with stem3-plotting function?
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jouni Lohikoski
le 20 Jan 2014
Réponse apportée : Jouni Lohikoski
le 20 Jan 2014
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 commentaires
Réponse acceptée
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')
0 commentaires
Plus de réponses (2)
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
0 commentaires
Voir également
Catégories
En savoir plus sur Line 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!