different label color in plot legend
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
DANIEL KONG LEN HAO
el 5 de Oct. de 2021
Comentada: DANIEL KONG LEN HAO
el 8 de Oct. de 2021
There is a bug in MATLAB where after I have plotted my figure, the display within the legend of the plot for tidal volume displays a black line instead of a red circle that was plotted for it. Any way to solve this solution?
% Plotting the actual volume against time plot
figure(3)
hold on
plot(time,V,'b-') % Plot volume figure
plot(time,yzero,'k-') % Plot zero line
plot(time(pos),tv,'ro') % Plot tidal volume
% Labelling the figure
xlim([time(1) time(end)])
xlabel('Time (s)')
ylabel('Volume (L)')
title('Volume against time plot')
legend('Actual Volume plot','Zero Line','Tidal Volume')
hold off
3 comentarios
DGM
el 5 de Oct. de 2021
I see you're using R2018b. Your code works as-is in R2015b and R2019b for me, so idk what's up there.
Working off of Mathieu's comment, it's often helpful to explicitly specify the objects to which the legend should refer. This is generally the way I recommend. There are other ways, but iirc, this would be the most compatible with older versions.
% dummy data
time = 0:0.1:2.5;
V = 0.7*sin(1.3*time);
[tv,pos] = max(V);
yzero = zeros(size(V));
% Plotting the actual volume against time plot
%figure(3)
hold on
% store the plot object handles
h(1) = plot(time,V,'b-'); % Plot volume figure
h(2) = plot(time,yzero,'k-'); % Plot zero line
h(3) = plot(time(pos),tv,'ro'); % Plot tidal volume
% Labelling the figure
% xlim([time(1) time(end)]) % not very useful (?)
xlabel('Time (s)')
ylabel('Volume (L)')
title('Volume against time plot')
% give the handles vector to legend()
legend(h,{'Actual Volume plot','Zero Line','Tidal Volume'})
hold off
Respuestas (1)
Anshika Chaurasia
el 8 de Oct. de 2021
Hi,
I ran the above code in R2018b and it's working fine.
clc
clearvars
close all
% dummy data
time = 0:0.1:2.5;
V = 0.7*sin(1.3*time);
[tv,pos] = max(V);
yzero = zeros(size(V));
% Plotting the actual volume against time plot
figure(3)
hold on
plot(time,V,'b-') % Plot volume figure
plot(time,yzero,'k-') % Plot zero line
plot(time(pos),tv,'ro') % Plot tidal volume
% Labelling the figure
xlim([time(1) time(end)])
xlabel('Time (s)')
ylabel('Volume (L)')
title('Volume against time plot')
legend('Actual Volume plot','Zero Line','Tidal Volume')
hold off
If you are still facing the issue then share the script with us to reproduce the issue at our end.
0 comentarios
Ver también
Categorías
Más información sobre Data Distribution 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!