필터 지우기
필터 지우기

Opening Livescript Plot in Figure Window Loses xline

조회 수: 32 (최근 30일)
Don Kalinich
Don Kalinich 2024년 7월 3일 13:32
답변: Garmit Pant 2024년 7월 4일 9:41
When I run this code in a script or livescript
% assign data
x = 0:10;
y1 = 0:0.2:2;
y2 = [0 0 0 0 0 1 1 1 1 1 1 ];
% plot y1
plot(x,y1)
% plot y2
hold on
yyaxis right
plot(x,y2)
% add an xline
xline(5)
I get the above plot. However, when I open the plot in a figure window it does not have the xline.
Thanks in advance for the help.
  댓글 수: 2
Taylor
Taylor 2024년 7월 3일 15:43
I've reproduced this behavior and alerted development of the bug. Please note that I could not reproduce the issue with R2024a, so updating to the latest version will solve this if you're able to do so.
Don Kalinich
Don Kalinich 2024년 7월 3일 18:07
I installed 2024a. I get the same result that I got in 2023b.

댓글을 달려면 로그인하십시오.

채택된 답변

Garmit Pant
Garmit Pant 2024년 7월 4일 9:41
Hello Don Kalinich
The issue that you have encountered is persistent in R2024a as well. The issue is not limited to the “xline” function but all the decorative objects for graphs like “ConstantLine” and “ConstantRegion” objects.
As a possible workaround, you can plot the line using the data rather than a decorative object. The following code snippet will help you add the vertical line to the graph.
% assign data
x = 0:10;
y1 = 0:0.2:2;
y2 = [0 0 0 0 0 1 1 1 1 1 1 ];
figure
% plot y1
plot(x,y1)
% plot y2
hold on
yyaxis right
plot(x,y2)
plot([5 5], ylim, 'k--') % 'k--' makes the line black and dashed
hold off
I hope you find the above explanation and suggestion useful!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by