Size of exported SVG incorrect

24 visualizaciones (últimos 30 días)
Christian Plank
Christian Plank el 21 de Abr. de 2020
Comentada: Adam Danz el 31 de Mayo de 2023
Hi,
i have a problem exporting my figures as svg vector images. I tried the following commands to set my desired size:
set(gcf,'units','centimeters','position',[0,0,7.5,10], 'paperunits','centimeters', 'PaperSize', [7.5,10],'PaperPosition', [0,0,7.5,10]);
I want the SVG to have the width of 7.5 cm and 10 cm height. I know that scaling vectors is no problem, but i want to keep font size the same as the document size where it will be implemented, so scaling is no option.
If i open or implement the SVG image, its final size (i.e. in Inkscape) is exact 424x567 pixels or in cm 11.21833x15.00187 cm. The font size in the SVG is 15 instead of 12. The figure itself in Matlab is displayed correct, but why is the image scaled up. Also the scaling for size and font size is different.
Anybody any ideas what is wrong here?
Greetings
  4 comentarios
Timmy Ngo
Timmy Ngo el 23 de Mayo de 2020
Same problem here!
Théo ASPERT
Théo ASPERT el 3 de Sept. de 2021
Same problem, so many hours lost

Iniciar sesión para comentar.

Respuestas (2)

Simon Pfingstl
Simon Pfingstl el 12 de Nov. de 2021
Editada: Simon Pfingstl el 13 de Nov. de 2021
I think the problem comes from the display scaling.
Make sure that you set the display scaling to 100% before you start Matlab (for Windows 10: Settings -> System -> Display -> Scale and Layout -> 100%). After you have started Matlab, you can change the scaling again to your disired one.
  1 comentario
Alexander Lerch
Alexander Lerch el 21 de En. de 2022
Oh man. This was driving me crazy as I regularly switch between desks/monitors and I couldn't figure out why the figures were exported in different sizes. Thanks for the tip.

Iniciar sesión para comentar.


Adam Danz
Adam Danz el 1 de Mayo de 2020
Movida: Rik el 30 de Mayo de 2023
  2 comentarios
Christian Plank
Christian Plank el 23 de Mayo de 2020
Movida: Rik el 30 de Mayo de 2023
@Adam Danz
This can't be the case. With the code in the question, matlab produces the following svg file (header):
<svg xmlns:xlink="http://www.w3.org/1999/xlink" style="fill-opacity:1; color-rendering:auto; color-interpolation:auto; text-rendering:auto; stroke:black; stroke-linecap:square; stroke-miterlimit:10; shape-rendering:auto; stroke-opacity:1; fill:black; stroke-dasharray:none; font-weight:normal; stroke-width:1; font-family:'Dialog'; font-style:normal; stroke-linejoin:miter; font-size:12px; stroke-dashoffset:0; image-rendering:auto;" width="424" height="567" xmlns="http://www.w3.org/2000/svg"
The size of the svg is 424x567. If i correctly calculate its dpi by using the 7.5cm x 10cm defined in the matlab code, the dpi is something around 144. So the problem is clearly related to matlab putting out the wrong size i would guess...
But for now i found a dirty workaround to this problem: open the svg in a texteditor (such as notepad++) and change the width and height of the first line to your desired pixels (calculate with 96 dpi yourself) and add the viewbox command with the old values of matlabs width and height
width="283px" height="378.4458" viewBox="0 0 424 567"
Then save the file and it is displayed correctly in Inkscape / Chrome / Firefox / Latex etc. But be aware that the size and font size will not be perfectly rounded to integers.
Nevertheless i hope someone can explain to me what i am doing wrong in matlab or that the problem will be fixed in future updates, because this is a really annoying thing to handle.
Adam Danz
Adam Danz el 31 de Mayo de 2023
@Christian Plank I recommend contacting tech support to get to the bottom of this. That way the issue you're describing will reach the right channels. It would be helpful to the community to leave a comment that summarizes what you find.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by