Background transparency is not supported for surf plots

12 次查看(过去 30 天)
Whereas the
close all
[X,Y] = meshgrid(1:0.5:10,1:20);
x=[0 10];y=2*x;
hf1=figure;plot(x,y);set(gca, 'color', 'none')
exportgraphics(hf1,'test2d.pdf','BackgroundColor','none')
Z = sin(X) + cos(Y);hf2=figure;surf(X,Y,Z);
set(gca, 'color', 'none');
exportgraphics(hf2,'test3d.pdf','BackgroundColor','none');
hf3=figure;[X,Y] = meshgrid(-8:.5:8);R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R;C = X.*Y;mesh(X,Y,Z,C)
set(gca, 'color', 'none');
exportgraphics(hf3,'test3d.pdf','BackgroundColor','none');
I do get indeed transparent figures, but wih the folloing arning
Warning: Background transparency is not supported; using white instead
However, once I insert the pdf in my latex file, the background is white.
WIll appreciate any help.

采纳的回答

Jaswanth
Jaswanth 2024-5-2
Hi Victor,
To address the issue of exporting figures to .pdf files from MATLAB while ensuring a transparent background, it's necessary to include a Name-Value Argument, ContentType, as vector in your calls to the exportgraphics function.
Kindly refer to the modified code snippet below, where ContentType has been added for clarity.
exportgraphics(hf3,'test3d_mesh.pdf','BackgroundColor','none','ContentType','vector');
Please go through the following MathWorks documentations to learn more about Name-Value Arguments in exportgraphics function mentioned above.
  1. ContentType: https://www.mathworks.com/help/matlab/ref/exportgraphics.html#mw_5bdc680e-deea-429e-b58e-24e3de1083f7:~:text=DPI%20image%20file.-,ContentType
  2. BackgroundColor: https://www.mathworks.com/help/matlab/ref/exportgraphics.html#mw_5bdc680e-deea-429e-b58e-24e3de1083f7:~:text=uint32%20%7C%20uint64-,BackgroundColor
I hope the information provided above is helpful in accomplishing your task.

更多回答(0 个)

类别

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