Some figures not saving as vector graphics (.svg)

Hi,
I ran into a strange problem. I'm trying to save figures in vector format to process in Adobe Illustrator. I make numerous of these plots using one script and in many cases the output to vector graphics using the .svg format works fine. Some figures, made by the same script and apart from the specific datapoints indistinguishable from other figures, do not export as proper vector graphics. In those cases I can open the output .svg file in Illustrator but the image is basically flat; i.e. I can not isolate individual elements for editing.
I have attached two figures extracted at the exact point in the script where the data is added that causes it to not save properly. I plot datapoints on a trial-trial basis, adding data from one trial, then the data from the next trial etc. Until a particular trial I can save the figure as a proper vector graphic .svg file (attached as Fig1Vector.fig). When data from the next trial is added, the output .svg file only contains a flattened image (attached as Fig2NotVector.fig).
I've been looking for differences between the two figures but I have exhausted my ideas on what could be at cause. Do any of you have any idea what could be going wrong here or any suggestions to do a successful vector image export?
Thanks in advance.
Best, Paul

 Réponse acceptée

Paul
Paul le 1 Nov 2017
Modifié(e) : Paul le 12 Sep 2023

36 votes

I figured out what the problem was. After a certain maximum of elements in the picture, Matlab's auto-renderer setting switches from using the -painters renderer to the -opengl renderer. Manually forcing the -painters renderer restores proper vector graphics output.
[2023 update] See Martin's helpful reply to this answer for the syntax to trigger the correct behavior in different Matlab versions.

16 commentaires

Well, this helped me a lot in restoring vector format. But I'm facing another problem: All my dashed lines turn into straight lines after this setup.
TheStranger
TheStranger le 10 Avr 2020
Thank you, Paul, from 2020 :)
Mengxue Cao
Mengxue Cao le 8 Août 2020
Thank you Paul! You save my day!
Zachary
Zachary le 16 Déc 2020
Thank you, Xinxing from 2020. Save my life:)
germ
germ le 17 Déc 2020
Thanks!
First of all thank you very much, also side note setting the option in the Export Setup window does not seem to do anything, but setting the flag in the print funtion works.
Yes, print function works well, please use print('-painters','-dsvg','myVectorFile') or print('-painters','-depsc','myVectorFile')
thank you in 2022
Ji Hoon Jeong
Ji Hoon Jeong le 12 Août 2022
Thank you in 2022
Thank you in 2022. I spent so many hours trying to figure out why and you saved my weekend!
Ran into the same issue. Where do you enable that manually?
Paul
Paul le 21 Jan 2023
Modifié(e) : Walter Roberson le 20 Nov 2023
Martin Jendryka
Martin Jendryka le 12 Sep 2023
Modifié(e) : Walter Roberson le 20 Nov 2023
before Matlab 2021
print(gcf,'-painter','-dsvg',[fname,'.svg']) % svg
print(gcf,'-painter','-dpdf',[fname,'.pdf']) % pdf
from Matlab 2021
print(gcf,'-vector','-dsvg',[fname,'.svg']) % svg
print(gcf,'-vector','-dpdf',[fname,'.pdf']) % pdf
Paul
Paul le 12 Sep 2023
Thanks Martin! I have edited my answer to refer to your addition.
Nikolai Kozlov
Nikolai Kozlov le 17 Mar 2026 à 9:23
Please check your syntax. It should be '-painters' with an s, AFAIK.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Printing and Saving dans Centre d'aide et File Exchange

Question posée :

le 28 Oct 2017

Commenté :

le 17 Mar 2026 à 9:23

Community Treasure Hunt

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

Start Hunting!

Translated by