Message Boards Message Boards

GROUPS:

Avoid problems with ticks when exporting Plot to pdf?

Posted 2 months ago
616 Views
|
5 Replies
|
2 Total Likes
|

I have a simple but strange problem: I’m using plot (see example attached) and want to export it to pdf (also attached) to get a vector image. There are a few problems with the plot:

  1. The upper x-axis does not show the same number of ticks as the lower x-axis (number of minor ticks is not the same). I would like to have the lower number of ticks being present also for the upper axis, so that the axes appear the same.

  2. When I export the plot to pdf the ticks on the right-handed side are too thin. I fiddled around with that but found no proper solution.

Does anyone can help me with that? The problem has only appeared in Mathematica 11 and was not present in the previous version.

Thank you,

Markus

Attachments:
5 Replies

Markus,

The automatic frameticks on the right and top do not match the bottom and left. You can leave them off with

Plot[Sin[x], {x, 0, 2*\[Pi]}, Frame -> True, ImageSize -> 300, 
 FrameStyle -> Directive[Black, Thickness[0.003]], 
 FrameTicks -> {{Automatic, None}, {Automatic, None}}, 
 LabelStyle -> Directive[Black, 10], FrameLabel -> {"x", "sin[x]"}, 
 PlotStyle -> Directive[Thickness[0.003], Purple]]

or you can specify them in FrameTicks. I suggest that you make a function to make the FrameTicks such as

ticker[min_, max_, major_, minor_] := 
 Map[{#, #, {0.02, 0}} &, Range[min, max, major]]~Join~
  Map[{#, ""} &, Subdivide[min, max, minor*(max - min)]]

This will put major ticks spaced between "min" and "max" divided up by "major" (major is in actual units) and then add minor, unlabeled ticks with each integer divided by "minor" (minor is an integer such as 4 meaning 4 ticks per integer value).

For example:

Plot[Sin[x], {x, 0, 2*\[Pi]}, Frame -> True, ImageSize -> 300, 
 FrameStyle -> Directive[Black, Thickness[0.003]], 
 FrameTicks -> {{ticker[-1, 1, 0.5, 4], 
    ticker[-1, 1, 0.5, 4]}, {ticker[0, 6, 1, 4], ticker[0, 6, 1, 4]}},
  FrameTicksStyle -> Directive[Black, 10], 
 LabelStyle -> Directive[Black, 10], FrameLabel -> {"x", "sin[x]"}, 
 PlotStyle -> Directive[Thickness[0.003], Purple]]

Gives

enter image description here

Naturally you can edit the function ticker to alter the style of the minor and major ticks such as length

Regards,

Neil

Hi Neil.

The second one is a nice solution, thank you. Still having problems with the pdf export. Wasn't there in my previous Mathematica version.

Best,

Markus

Markus,

I do not see the PDF export problem. It seems to work on my system (when I specify the ticks). Can you elaborate?

Regards,

Neil

Exporting a Plot (if you are correct in it not working), should be a no-brainer in 2019...

it worked in older versions. it should still work unless:

(1) recently damaged by wolfram employees

(2) your pdf exporter is recently damaged by (adobe) employees

i have a problem never solved of grid box lines being way out of proportion when (printed to ps or pdf) that wolfram just can't solve. it used to work.

i investigated the .ps code and found each region in a PostScript is exactly specified (inch and dot) in units, but that the wolfram code has used units referring to front end usage (which the old wolfram exporter did not do)

One could comment "technology isn't going that direction", we need nVidia 3d and breaking 2d graphics isn't a concern, and people don't print they cloud to iphone. but i feel these are excuses for altering code without first understanding it.

Instructions to remove basic line information from saved plots just cannot pass without some scrutiny.

Dear John. See the pdf in the first post and you see that pdf has problems on the right-handed side. Suggestions for solving this issue appreciated. M

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract