MATLAB Answers

different label color in plot legend

2 views (last 30 days)
DANIEL KONG LEN HAO
DANIEL KONG LEN HAO on 5 Oct 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 Comments
DANIEL KONG LEN HAO
DANIEL KONG LEN HAO on 8 Oct 2021
Alright, thank you managed to solve it using this method!

Sign in to comment.

Answers (1)

Anshika Chaurasia
Anshika Chaurasia on 8 Oct 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.

Tags

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!