How to plot several sets (in different colours) with stem3-plotting function?
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jouni Lohikoski
el 20 de En. de 2014
Respondida: Jouni Lohikoski
el 20 de En. de 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 comentarios
Respuesta aceptada
AJ von Alt
el 20 de En. de 2014
Editada: AJ von Alt
el 20 de En. de 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 comentarios
Más respuestas (2)
Bruno Pop-Stefanov
el 20 de En. de 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 comentarios
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!