missing parts of a figure when converting to pdf
조회 수: 8 (최근 30일)
이전 댓글 표시
When I use exportgraphics (or print) to convert a matlab .fig file to a .pdf file, the markers near the yaxes missing.
The .fig looks like this
And the .pdf produced looks like this
The following are the code producing the .fig
f1 = figure;
f1.Position = [400, 300, 650, 450];
yyaxis left
f1_p1 = plot(ana_nl_rng, ana_w1_dl_vec, "--", "LineWidth", 1.1, "Color", "#0072BD");
hold on
f1_p2 = plot(sim_nl_rng, sim_w1_dl_vec, "x", "MarkerSize", 7.0, "LineWidth", 0.8, "Color", "#0072BD");
f1_p3 = plot(ana_ns_rng, ana_w1_ds_vec, "-.", "LineWidth", 1.1, "Color", "#D95319");
f1_p4 = plot(sim_ns_rng, sim_w1_ds_vec, "o", "MarkerSize", 7.0, "LineWidth", 0.8, "Color", "#D95319");
ylim([0, 30]);
set(gca,'YColor','k');
ylabel("$D^{(\phi)}$", "Interpreter", "latex", "FontSize", 14, "Rotation", 0, ...
'Units', 'normalized', 'Position', [-0.08, 0.53, 0.5]);
yyaxis right
f1_p5 = plot(ana_nl_rng, ana_nl_rng .* ana_w1_dl_vec + ana_ns_rng .* ana_w1_ds_vec, "-", "LineWidth", 1.1, ...
"Color", "#EDB120");
f1_p6 = plot(sim_nl_rng, sim_nl_rng .* sim_w1_dl_vec + sim_ns_rng .* sim_w1_ds_vec, "+", "MarkerSize", 7.0, ...
"LineWidth", 0.8, "Color", "#EDB120");
set(gca,'YColor','k');
ylabel("$\hat{D}$", "Interpreter", "latex", "FontSize", 14, "Rotation", 0, ...
'Units', 'normalized', 'Position', [1.09, 0.6, 0.5]);
ylim([120, 200]);
yticks(120:20:200);
xlim([5, 100]);
xticks([5, 10:10:100]);
xlabel("$n^{(LB)}$", "Interpreter", "latex", "FontSize", 15);
set(gca,'XTickLabel', get(gca,'XTickLabel'), 'FontSize', 14);
f1_ax1 = axes("Position", get(gca,"Position"), "Visible", 'off');
legend(f1_ax1, [f1_p1, f1_p2], ["Analysis", "Simulation"], "FontSize", 12);
f1_ax2 = axes("Position", get(gca,"Position"), "Visible", "off");
legend(f1_ax2, [f1_p3, f1_p4], ["Analysis", "Simulation"], "FontSize", 12);
f1_ax3 = axes("Position", get(gca,"Position"), "Visible","off");
legend(f1_ax3, [f1_p5, f1_p6], ["Analysis", "Simulation"], "FontSize", 12);
I added some arrows and textboxes manually afterwards, and I used the exportgraphics function to produce the .pdf
exportgraphics(f1, "./pdfs/dr_vs_n_fix_w_1.pdf")
Can anyone help me figure out what's the problem? Thank you!
댓글 수: 2
Jan
2022년 7월 30일
편집: Jan
2022년 7월 31일
What happens, if you create the axes with an disabled clipping?
axes('Clipping', 'off')
@Jie Zhang: Please use flags to inform admins and editors about inappropriate contributions, e.g. rudeness or off-topic messages. Thanks! I've posted this comment as an answer also, such that it can be marked as a solution.
Walter Roberson
2022년 7월 30일
You could experiment with https://www.mathworks.com/help/matlab/ref/matlab.graphics.axis.axes-properties.html#budumk7_sep_shared-Layer setting the axes 'Layer' property to 'bottom' . It should be 'bottom' by default, but it just might make a difference, maybe.
You could also use xlim and ylim to make the axes slightly bigger so that the end points are inside the drawing area.
채택된 답변
Jan
2022년 7월 31일
Copied from my suggestion in the comments:
Disable the clipping of the axes object:
axes('Clipping', 'off')
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
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!