yline disappeared after closing a saved figure when reopening
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jonas
2024-4-2
@John Pausder no, i cannot reproduce this. everything fine running on 2022a. i can see both ylines
回答(1 个)
Animesh
2024-2-28
Hey @John Pausder
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 of “yline”.
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"
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!