Changing the marker type for the nth entry in plot

5 vues (au cours des 30 derniers jours)
Louis
Louis le 1 Juil 2015
Commenté : Louis le 1 Juil 2015
I've been working on a project where we are changing 2 variables and the outputs are T values and Y values. Here's pretty much what the data looks like.
T1 = [1;3;5;7];
T2 = [0.9;2.7;5;6.8];
T3 = [1;2.9;5.1;7];
Y1 = [1;2;1;2];
Y2 = [4;5;6;4];
Y3 = [7;8;7;7];
figure;
hold on;
plot(T1,Y1,':');
plot(T2,Y2,'-.');
plot(T3,Y3,'--');
As you can see all the X values pretty much line up around 1,3,5, and 7. I want each plot to not only have a unique line, but to have the nth entry to be a certain marker style, so all second entries (around X=3) to have a square marker for example. So you should be able to identify a point by its line style and marker style. Therefore, I would like the legend to have a label for each line style and marker style. So something like this:
legend('line style 1','line style 2','line style 3','marker style 1','marker style 2','marker style 3','marker style 4');
Thanks

Réponse acceptée

Brendan Hamm
Brendan Hamm le 1 Juil 2015
You would have to accomplish this as a second plot, since each Line has a MarkerStyle associated with all of the data points. To do this for the 3rd entry:
T1 = [1;3;5;7];
T2 = [0.9;2.7;5;6.8];
T3 = [1;2.9;5.1;7];
Y1 = [1;2;1;2];
Y2 = [4;5;6;4];
Y3 = [7;8;7;7];
figure;
ax = axes;
hold on;
plot(T1,Y1,':');
plot(T2,Y2,'-.');
plot(T3,Y3,'--');
ax.ColorOrderIndex = 1; % Return to the previous color index
n = 3; % The nth element should be plotted as a square
plot(T1(n),Y1(n),'s');
plot(T2(n),Y2(n),'s');
plot(T3(n),Y3(n),'s');
  1 commentaire
Louis
Louis le 1 Juil 2015
Great idea - this even makes the legend very easy to set.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by