3
$\begingroup$

I seem to have a problem with the export of plots to PDF when using the FrameTicks option.

Using the example from the documentation:

fticks2[min_, max_] := 
   Table[If[EvenQ[i], {i, i, {.1, 0}, Red}, {i, i, {.05, 0}, Blue}],{i,
   Ceiling[min], Floor[max], 1}]

pltest = Graphics[Circle[{0, 0}, 2], 
                  Frame -> True, 
                  FrameTicks -> fticks2];

Leads to the (expected) display on the screen:

enter image description here

However, exporting the graphics as a PDF file via

Export["test.pdf", pltest, "PDF"];

fails on Mac OS X 10.12.6 (MMA 11.2.0.0) as it produces just the circle - no frame, no ticks, no tags:

enter image description here

Answers to similar versions of this question suggested setting

FrameTicks-> True

However, this doesn't work in this case, as setting FrameTicks to True overrides the fticks2 function.

The only workaround that I have found so far is to use the Rasterize-function, but this is a it clumsy.

Any ideas for a better fix?

$\endgroup$

1 Answer 1

3
$\begingroup$

I think Mathematica uses a different kernel to export graphics to PDF, and this kernel knows nothing about the function fticks2. Here are a couple workarounds.

Pure function

Instead of using a function with downvalues, you can use a pure function. For example:

ft = Function[
    {min, max},
    Table[
        If[EvenQ[i],{i,i,{.1,0},Red}, {i,i,{.05,0},Blue}],
        {i, Ceiling[min], Floor[max]}
    ]
];

Here's a side-by-side comparison of fticks2 and ft:

GraphicsRow[{
    First @ ImportString @ ExportString[
        Graphics[Circle[{0,0}, 2], Frame->True, FrameTicks->fticks2],
        "PDF"
    ],

    First @ ImportString @ ExportString[
        Graphics[Circle[{0,0}, 2], Frame->True, FrameTicks->ft],
        "PDF"
    ]
}]

enter image description here

Explicit ticks

The alternative is to feed the plot range to your ticks functions:

First @ ImportString @ ExportString[
    Graphics[Circle[{0,0}, 2], Frame->True, FrameTicks->{fticks2[-2,2], fticks2[-2,2]}],
    "PDF"
]

enter image description here

$\endgroup$
1
  • $\begingroup$ Ok, that works well. Now I have to learn about the difference between f[x_ y_]:=.... and f= Function[{x,y},....]. $\endgroup$ Mar 7, 2018 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.