Matlab keeps cutting off Vector when saving to pdf, no matter what I do
90 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jonathan
el 19 de Nov. de 2024 a las 18:23
Respondida: Aastha
el 29 de Nov. de 2024 a las 10:55
Hello Everyone
I am trying to make a simple 2D figure which I can edit in Illustrator. However, no matter what I do, Matlab cuts off parts of the vector when I try to export it. Now it looks fine in the MATLAB figure viewer and even when I open it in adobe acrobat
Matlab Figure:
Acrobat, note this is just using "save as pdf", it is a little cutoff but that has never been an issue for me in the past. The important thing is that you can see that the majority of the data is viewable.
However, when I open the pdf in illustrator it cuts off the top of vector from 300 to 320 on the y-axis.
When I try bestfit or fill page, it converts the figure into a raster so I can no longer edit the data-series itself.
I have tried switching the renderers to painters, which succeeds in preserving the vectors, but now even more of the data is cutoff. Regardless of whether I use best-fit or fill page. The only thing that is consistent is that it cuts off the data at around 200
I examined the data, there are no gaps and the Y-axis data is arranged in numerical order. Yes the data is relatively large [two vectors each: 36,562 x 1 double]. But I have continued to try to graph much larger data sets with very little issue. For example I have another data set which consists of 25 vectors which are each 44,317 x 1 double, and only one of the subfigures appeared to have any problem when saving as a pdf (but that's a question for another day).
Moreover, when I change the plot limits on my problem data set to the cut off zone (y-axis 200 to 320), matlab has no problem exporting that figure. So it doesn't seem like its a problem with the data set
I have tried the exportgraphics function and the print function with no luck
fig=figure;plot(x,y)
exportgraphics(fig, 'output_matlab_ex.pdf', 'ContentType', 'vector');
print('-vector','-dpdf','myVectorFile_pdf_mlexample')
I have tried opening these figures in older versions of illustrator (2023) and Matlab (2023b) as well as most recent updated versions (Illustrator 2024 and Matlab 2024b). But no matter what I do either Matlab or Illustrator is arbitraily cutting the vector off.
Note I have also tried saving/exporting the figure as an svg, epfs, and emf file. The only one that I was able to sucessfully open in illustrator was the emf file. But still it cut off the data at around 300 on the y-axis
Any help or advice would be greatly appreciated.
0 comentarios
Respuestas (1)
Aastha
el 29 de Nov. de 2024 a las 10:55
I used the “exportgraphics” function to save the figure of dummy data as a PDF. I was able to render the PDF without the data getting cropped. The original figure and the rendered pdf look as follows:
Original figure:
The rendered pdf:
As a workaround for “exportgraphics”, you can use the “saveas” function to export the figure to a PDF. The MATLAB code below illustrates an example to do so :
% generate dummy data
x = linspace(120, 320, 20000);
scale = rand(size(x)) > 0.999;
y = ones(size(x)) * 5 + randi(20, size(x)) .* scale + randn(size(x));
x = max(120, min(320, x));
ylim([120 320]);
% Create figure
fig = figure;
plot(y, x);
set(fig, 'Renderer', 'painters');
saveas(fig, 'myfiguresaveas.pdf'); % Export the figure to PDF using exportgraphics
exportgraphics(fig, 'myfigureexportgraphics.pdf', 'ContentType', 'vector');
For more information on the “saveas” function, kindly refer to the link of MathWorks documentation mentioned below:
Hope this helps!
0 comentarios
Ver también
Categorías
Más información sobre Printing and Saving en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!