필터 지우기
필터 지우기

yline disappeared after closing a saved figure when reopening

조회 수: 5 (최근 30일)
John Pausder
John Pausder 2024년 2월 19일
댓글: Jonas 2024년 4월 2일
Hi, I am creating a figure with multiple axis (such as subplot but manually). Part of the figure are also multiple xlines. When creating the figure with my script everything seems to work fine. I also save the figure and let the script close it automatically. When reopening the saved *.fig file the xlines disappeared and I have no clue what to try next.
fh = struct([]); % figurehandler which holds 4 axies all similar built like ax3
fh(k1).fh = figure; % k1 is a counter in a for loop
fh(k1).ax3 = axes(fh(k1).fh);
fh(k1).ax3.Position = [0.06,0.25,0.7,0.2];
fh(k1).ax3.YLim = [-1 1];
grid(fh(k1).ax3,"on");
hold(fh(k1).ax3, "on");
fh(k1).ax3.XLim = [-0.01 inf];
yyaxis(fh(k1).ax3,"left");
hold(fh(k1).ax3, "on");
linkaxes([fh(k1).ax, fh(k1).ax3], "x");
yline(fh(k1).ax3, [value1_std -value1_std],"--b","DisplayName","Value1");
yyaxis(fh(k1).ax3,"right");
hold(fh(k1).ax3, "on"); % added the holds to make sure nothing will be overwritten
yline(fh(k1).ax3, [value2_std -value2_std],"--", "Color",[0.8500, 0.3250, 0.0980],"DisplayName","Value2");
hold([fh(k1).ax,fh(k1).ax2,fh(k1).ax3,fh(k1).ax4], "off");
%saveas(fh(k1).fh,fullfile(savefolder,{sprintf('Step%d.fig', k1)})); %
%tried this but causes the same issue
savefig(fh(k1).fh,fullfile(savefolder,{sprintf('Step%d.fig', k1)}));
print(fh(k1).fh,fullfile(savefolder,{sprintf('Step%d', k1)}),"-dpng","-r400");
close(fh(k1).fh);
However when saving the figure as png the lines are there, as they were when i created the plot. Both ylines disappeared
  댓글 수: 5
John Pausder
John Pausder 2024년 3월 21일
@Jonas as have you been able to recreate the issue? When I run your code snipped and place a breakpoint just before closing the fig, I can see the ylines. Yet, as I reopen the saved figure they are gone just as I described..
Jonas
Jonas 2024년 4월 2일
@John Pausder no, i cannot reproduce this. everything fine running on 2022a. i can see both ylines

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

답변 (1개)

Animesh
Animesh 2024년 2월 28일
I have been encountering a similar issue while working with “xline and “yyaxis. The only workaround I can think of is to use “line” instead ofyline”.
Here is something you can do to replicate the similar behaviour using “line”:
% Left Y-axis
yyaxis(fh(k1).ax3, "left");
hold(fh(k1).ax3, "on");
% Draw a line at y = 0.5 using the `line` function
x_values = fh(k1).ax3.XLim; % Use current x-axis limits
line(x_values, [0.5 0.5], 'LineStyle', '--', 'Color', 'b', 'Parent', fh(k1).ax3, 'DisplayName', 'Value1');
% Right Y-axis
yyaxis(fh(k1).ax3, "right");
hold(fh(k1).ax3, "on");
% Draw a line at y = 5 using the `line` function
line(x_values, [5 5], 'LineStyle', '--', 'Color', [0.8500, 0.3250, 0.0980], 'Parent', fh(k1).ax3, 'DisplayName', 'Value2');
You can refer the following MathWorks documentation for more information on "line"
  댓글 수: 1
John Pausder
John Pausder 2024년 3월 21일
편집: John Pausder 2024년 3월 21일
Thank you @Animesh. I also used another workaround by creating a vecotor with the length of the represented data, just as one value and plotted this. I think yours is the better option.
c_std_vec = zeros(length(data(datastart:dataend)) ,2);
c_std_vec(:,1) = data.std;
c_std_vec(:,2) = - data.std;
plot(fh(k1).ax3, timedata(datastart:dataend), c_std_v

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

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by