Create a specific legend in Matlab
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everyone,
I have put together some experimental data that I have plotted in a rather rudimentary way using Matlab.
Here is the code in question:
%% TEST pince de 2.5 cm
y = [7.58 7.12 6.55 6.20 5.60 5.45 5.18 5.02 4.96 4.75 4.55 4.41]; % Longueur d'onde
x = [0.0755 0.0943 0.1022 0.1030 0.1187 0.1297 0.1430 0.1506 0.1634 0.1808 0.1898 0.1930]*1.5625; % Fréquence de rotation
z = [9 10 11 12 13 14 15 16 17 18 19 20]; % Nombre de volts
h = zeros(6,1);
h(1) = plot(x,y,'b')
h(2) = plot(x,y,'-o')
ylabel('\lambda (cm)')
xlabel('\Omega (Hz)')
hold on
y = [7.39 7.12 6.44 6.04 5.63 5.40 5.10 4.96 4.80 4.50 4.33]; % Longueur d'onde
x = [0.0668 0.0755 0.0943 0.1022 0.1086 0.1254 0.1349 0.1460 0.1573 0.1660 0.1828]*1.5625; % Fréquence de rotation
z = [8 9 10 11 12 13 14 15 16 17 18]; % Nombre de volts
h(3) = plot(x,y,'k')
h(5) = plot(x,y,'-o')
ylabel('\lambda (cm)')
xlabel('\Omega (Hz)')
y = [7.39 6.58 5.92 5.74 5.27 5.04 4.83 4.73 4.28 4.23]; % Longueur d'onde
x = [0.0605 0.0777 0.0856 0.0938 0.1082 0.1193 0.1300 0.1466 0.1506 0.1680]*1.5625; % Fréquence de rotation
z = [8 9 10 11 12 13 14 15 16 17]; % Nombre de volts
h(4) = plot(x,y,'r')
h(6) = plot(x,y,'-o')
ylabel('\lambda (cm)')
xlabel('\Omega R^{2}')
title('Mesure ruban rose largeur 1.5 cm avec une pince de 2.5 cm de largeur')
legend(h,'7 cm','pince de 2.5 cm','10.5 cm','12.5 cm');
grid on
hold off
%%
What I am trying to do in practice: you will note that there are 3 sets of (x,y) which each correspond to an experiment carried out for a precise experimental length. For each pair of plots (x,y) it is essential to associate a colour that allows the length in question to be distinguished in the legend (so each pair (x,y) would correspond to a colour which itself corresponds to a given length). But in addition: the three (x,y) pairs were made for another characteristic length which this time is common to them, so to notify this I wanted to draw each curve with a distinct colour but with a unique marker (typically a circle for the three pairs).
Unfortunately, I can't translate what I want into a clean and understandable legend so I'm asking for your help if possible,
I thank you in advance for your assistance--
0 commentaires
Réponses (1)
Cris LaPierre
le 11 Avr 2021
I don't follow your description completely. What should the actual legend be? Should there be 6 items in your legend? Three using lines of different color, and 3 with diferent line colors + a circle marker?
Here's what does that.
%% TEST pince de 2.5 cm
y = [7.58 7.12 6.55 6.20 5.60 5.45 5.18 5.02 4.96 4.75 4.55 4.41]; % Longueur d'onde
x = [0.0755 0.0943 0.1022 0.1030 0.1187 0.1297 0.1430 0.1506 0.1634 0.1808 0.1898 0.1930]*1.5625; % Fréquence de rotation
plot(x,y,'b','DisplayName','Name1')
hold on
plot(x,y,'-o','DisplayName','Name2')
y = [7.39 7.12 6.44 6.04 5.63 5.40 5.10 4.96 4.80 4.50 4.33]; % Longueur d'onde
x = [0.0668 0.0755 0.0943 0.1022 0.1086 0.1254 0.1349 0.1460 0.1573 0.1660 0.1828]*1.5625; % Fréquence de rotation
plot(x,y,'k','DisplayName','Name3')
plot(x,y,'-o','DisplayName','Name4')
y = [7.39 6.58 5.92 5.74 5.27 5.04 4.83 4.73 4.28 4.23]; % Longueur d'onde
x = [0.0605 0.0777 0.0856 0.0938 0.1082 0.1193 0.1300 0.1466 0.1506 0.1680]*1.5625; % Fréquence de rotation
plot(x,y,'r','DisplayName','Name5')
plot(x,y,'-o','DisplayName','Name6');
hold off
grid on
ylabel('\lambda (cm)')
xlabel('\Omega (Hz)')
title('Mesure ruban rose largeur 1.5 cm avec une pince de 2.5 cm de largeur')
legend('NumColumns',3);
Since each pair of plots contains the same data, you lines exactly overlap.
10 commentaires
Cris LaPierre
le 12 Avr 2021
Please explain what you mean by "doesn't work". Be specific about what you expected, and what it is doing instead.
Voir également
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects 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!