Mathematica Asked by axsvl77 on April 13, 2021
Using the following code, I make a simple graph that is exported to pdf:
format = AxesStyle -> {{Thickness[.01], Arrowheads[{0.0, 0.05}]}, { Arrowheads[{0.0, 0.05}]} }
graph = ListLinePlot[Table[{t, 2*t}, {t, 0, 100}], format, AspectRatio -> .2]
Export[StringJoin[NotebookDirectory[], "ext.pdf"], graph];
When I look at the graph, it cuts of the end of one of the arrows:
The y axis is ok – but the x axis is not. The end of the arrow has been clipped. It seems to be related to increasing the thickness of the axis.
For what its worth, the in-notebook display of the graph has complete arrows. It is only the exported version that is clipped.
I want both axes thick, and I want the whole arrow, and I want it in PDF. How to do this?
Please note that it didn’t have this problem in Mathematica 11.3; it is only after I upgraded that this problem has arisen. I’m using 12.1
Edit: The reason I want it in pdf is not because I like the file format, but because I want it in a vector graphic that works with Latex. The output should have the resolution of a high quality vector graphic, without the arrow chopped.
Add a little padding in a Show
and export it as SVG. If you look at the SVG it's still broken. But then reimport it using ResourceFunction["SVGImport"]
, then export it back out again as PDF. This seems to magically work and the PDF has the full arrow ... don't ask me why though:
svgi = ResourceFunction["SVGImport"]
format = AxesStyle -> {{Thickness[.01], Arrowheads[{0.0, 0.05}]}, {Arrowheads[{0.0, 0.05}]}}
graph = ListLinePlot[Table[{t, 2*t}, {t, 0, 100}], format, AspectRatio -> .2]
Export["ext.svg", Show[graph, PlotRangePadding -> {Automatic, 2}]];
result = svgi["ext.svg"]
Export["ext1.pdf", Show[result, PlotRangePadding -> {Automatic, 2}]]
Answered by flinty on April 13, 2021
The cut off in the head of the arrow appeared due to the assigned thickness of the axes, to check this we can change the position of the arrow and examine it closely as follow:
format = AxesStyle -> {{Thickness[0.02],
Arrowheads[{{0.09, 0.8}}]}, {Arrowheads[{0.0, 0.05}]}};
graph = ListLinePlot[Table[{t, 2*t}, {t, 0, 100}], format,
AspectRatio -> .2]
Export[StringJoin[NotebookDirectory[], "ext.pdf"], graph];
I used a pdf editor to check the head of the arrow, and this cut off is increased with increasing the thickness of the axes. So, the simple solution is to avoid assign specific thickness and instead impose it like this-:)
format = AxesStyle -> {{Arrowheads[{0.0, 0.05}]}, {Arrowheads[{0.0,
0.05}]}};
graph = ListLinePlot[{Table[{t, 0}, {t, -3, 100}],
Table[{t, 2*t}, {t, 0, 100}]}, format, AspectRatio -> .2,
PlotStyle -> {Directive[Gray, Thickness[0.01]], Blue}]
Export[StringJoin[NotebookDirectory[], "ext.pdf"], graph];
Answered by valar morghulis on April 13, 2021
Export to PDF - scaling grids of plots and text size should answer this question already.
lots = GraphicsGrid[
Table[With[{a = RandomInteger[{1, 17}],
b = RandomInteger[{1, 17}]},
ParametricPlot[Sin[t^2] {Cos[a t], Sin[b t]}, {t, 0, 2 [Pi]},
PlotRange -> {{-1, 1}, {-1, 1}}, Frame -> True,
ImageSize -> Scaled[1]]], {15}, {7}]];
Export["lots.pdf", lots]
The main problem is to use the right font. Mathematica is publication-ready, but are all the other programs especially for publication-ready for their task. The main problem is to determine the operating system one is on.
Otherwise, the Mathematica documentation is genial: PDF.
You are to work publication-ready responsible to match the fonts. That is true on all operating systems and everywhere. So match the font Mathematica uses in the graphics to the ones available to the pdf display program set on the local machine.
Scaled
is really nice built-in otherwise.
There are features like pdf font embedding.
Another workaround is to export the graphics to SVG and convert the svg externally to pdf.
SVG is mightier in Mathematica.
ExportString[Graphics[{Red, Disk[]}], "SVG"]
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="360pt"
height="359pt" viewBox="0 0 360 359" version="1.1">
<g id="surface79">
<path style="
stroke:none;fill-rule:evenodd;fill:rgb(99.998474%,0%,0%);fill-opacity:
1;" d="M 351.820312 179.210938 C 351.820312 133.511719 333.664062
89.679688 301.347656 57.363281 C 269.03125 25.046875 225.203125
6.894531 179.5 6.894531 C 133.796875 6.894531 89.96875 25.046875
57.652344 57.363281 C 25.335938 89.679688 7.179688 133.511719
7.179688 179.210938 C 7.179688 224.914062 25.335938 268.746094
57.652344 301.0625 C 89.96875 333.378906 133.796875 351.53125 179.5
351.53125 C 225.203125 351.53125 269.03125 333.378906 301.347656
301.0625 C 333.664062 268.746094 351.820312 224.914062 351.820312
179.210938 Z M 351.820312 179.210938 "/>
</g>
</svg>
You can inspect the output to SVG in Mathematica.
format = AxesStyle -> {{Thickness[.01],
Arrowheads[{0.0, 0.05}]}, {Arrowheads[{0.0, 0.05}]}}
graph = ListLinePlot[Table[{t, 2*t}, {t, 0, 100}], format,
AspectRatio -> .2]
ExportString[
ListLinePlot[Table[{t, 2*t}, {t, 0, 100}], format,
AspectRatio -> .2], "SVG"]
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="360pt"
height="88pt" viewBox="0 0 360 88" version="1.1">
<path style="fill:none;stroke-width:1.6;stroke-linecap:square;stroke-
linejoin:miter;stroke:rgb(36.84082%,50.67749%,70.979309%);stroke-
opacity:1;stroke-miterlimit:3.25;" d="M 94 83.515625 L 100.609375
82.234375 L 103.910156 81.59375 L 113.824219 79.671875 L 117.128906
79.035156 L 120.433594 78.394531 L 123.734375 77.753906 L 136.953125
75.191406 L 140.253906 74.550781 L 143.558594 73.910156 L 146.863281
73.273438 L 153.472656 71.992188 L 156.773438 71.351562 L 169.992188
68.789062 L 173.296875 68.152344 L 176.597656 67.511719 L 189.816406
64.949219 L 193.117188 64.308594 L 196.421875 63.667969 L 199.726562
63.03125 L 206.335938 61.75 L 209.636719 61.109375 L 222.855469
58.546875 L 226.160156 57.910156 L 229.460938 57.269531 L 242.679688
54.707031 L 245.980469 54.066406 L 249.285156 53.425781 L 252.589844
52.789062 L 259.199219 51.507812 L 262.5 50.867188 L 275.71875
48.304688 L 279.023438 47.667969 L 282.324219 47.027344 L 295.542969
44.464844 L 298.84375 43.824219 L 302.148438 43.183594 L 305.453125
42.546875 L 315.367188 40.625 L 318.667969 39.984375 L 328.582031
38.0625 L 331.886719 37.425781 L 335.1875 36.785156 L 348.40625
34.222656 L 351.707031 33.582031 L 355.011719 32.941406 L 358.316406
32.304688 L 368.230469 30.382812 L 371.53125 29.742188 L 381.445312
27.820312 L 384.75 27.183594 L 388.050781 26.542969 L 401.269531
23.980469 L 404.570312 23.339844 L 407.875 22.699219 L 411.179688
22.0625 L 421.09375 20.140625 L 424.394531 19.5 "
transform="matrix(1,0,0,1,-74,-13)"/>
<path style="fill:none;stroke-width:3.441624;stroke-linecap:butt;
stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-
miterlimit:3.25;" d="M 87.117188 83.515625 L 415.660156 83.515625 "
transform="matrix(1,0,0,1,-74,-13)"/>
<path style="fill:none;stroke-width:0.03;stroke-linecap:square;stroke-
linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-
miterlimit:3.25;" d="M 87.117188 83.515625 Z M 87.117188 83.515625 "
transform="matrix(1,0,0,1,-74,-13)"/>
<path style="fill:none;stroke-width:1;stroke-linecap:butt;stroke-
linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-
miterlimit:3.25;" d="M 94 84.890625 L 94 31.679688 "
transform="matrix(1,0,0,1,-74,-13)"/>
<path style="fill:none;stroke-width:0.03;stroke-linecap:square;stroke-
linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-
miterlimit:3.25;" d="M 94 84.890625 Z M 94 84.890625 "
transform="matrix(1,0,0,1,-74,-13)"/>
<path style="fill-rule:nonzero;fill:rgb(0%,0%,0%);fill-opacity:1;
stroke-width:0.03;stroke-linecap:square;stroke-linejoin:miter;stroke:
rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:3.25;" d="M
89.472656 33.265625 L 89.988281 33.015625 L 91.222656 32.460938 L
91.964844 32.167969 L 92.714844 31.914062 L 93.414062 31.738281 L 94
31.679688 L 94.53125 31.738281 L 95.21875 31.914062 L 95.996094
32.167969 L 96.785156 32.460938 L 98.136719 33.015625 L 98.710938
33.265625 L 94 16.058594 Z M 89.472656 33.265625 "
transform="matrix(1,0,0,1,-74,-13)"/>
And correct smaller deviation from the intent by hand after some experience is accumulated.
Converting SVG to PDf is safe since both standards are compatible. SVG is subset of the HTML5 language specification and therefore on the internet high level most advanced standard. PDF is only supported up to version 1.5 by Mathematica. There is already 1.7 published. The Adobe Systems version PDF 1.7 is the basis for this ISO 32000 edition as the newest valid standard since 2008, so very aged. SVG is too part of XML specification for example used by Word or OpenOffice.
Both pdf and svg can be viewed in the browser.
svg can be imported in many pdf editors as well. Compared to all Rasterizers this remain vector grafics and can be enlarged as the rest of an pdf without pixelation and other image distorsions. This is the official Adobe page for SVG: enter link description here. SCG is open source and complete part of Mathematica.
A tip is drag the output of the graphics input into the second field of the Export
built-in for best results.
Answered by Steffen Jaeschke on April 13, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP