Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I understand that Mathematica has a bug when exporting images. The ticks are scaled not correctly when exporting at high resolution. For example: when you do:

Export["xx.png", plot, ImageResolution -> 360];

The image looks good, but all the frame ticks are all gone. When you do

Export["xx.png", plot, ImageResolution -> 100];

The ticks are there, but the resolution of the image is not good enough.

I tried the trick of using ImportString and ExportString:

ImportString[ExportString[plot, "PDF"]

It works, but creates another problem: the PlotRangeClipping option is missing, and the figure has plot lines sticking out all the way to the boundary of the image, not the boundary of the axes.

Can someone provide an easy and relatively universal workaround?

share|improve this question
1  
See here: stackoverflow.com/questions/8805451/… – Szabolcs Jun 23 '14 at 22:33
    
Do you need it to be a rasterized image? If not, you can probably export it as a vector graphic (.pdf or .eps) which can scale to whatever size you need later, and then you don't need to define a resolution on export. – ThomasH Jun 24 '14 at 8:31
    
Hi. Exporting it as a vector graphic .pdf or .eps does work. However, neither of these are friendly with Microsoft, so I can't easily put them in the context. – Jun Yang Jun 24 '14 at 15:24
2  
Adding "PNG" to export doesn't have any effect. – mikemtnbikes Jan 15 at 20:48
2  
The PNG exporter is not scaling the ticks so they end of too small to see. A work-around is to export in PDF and convert the PDF image to PNG in an external app. I did the conversion in OS X's Preview app and got good results. – m_goldberg Jan 16 at 1:09

UPDATE

Starting from Mathematica version 9 one can use comparatively simple workaround suggested by Jens. For previous versions the only known workaround is providing manual Ticks specifications, see below.


Original answer

This problem is described here as well.

Slava Nadvorny suggests using manual Ticks specifications. In this case they will scale with ImageResolution.

The CustomTicks package will make it considerably easier to create manual tick specifications.

share|improve this answer
2  
BTW I believe this is a bug. Why don't you ask support at wolfram.com about it? If more people complain there's higher chance that it'll be fixed. – Szabolcs Jun 23 '14 at 22:35
5  
I envy your optimism... – Jens Jun 24 '14 at 3:17

OK, I'll just put up this work-around - it's not perfect because the scaling of the ticks has never worked properly, to my knowledge:

list = {{{10., 5.}, {40., 20.}, {160., 80.}}, {{10., 1.83772}, {40., 
     13.6754}, {160., 67.3509}}, {{10., 8.16228}, {40., 
     26.3246}, {160., 92.6491}}};

myPlot = ListPlot[list, Frame -> True, 
   FrameLabel -> {"Sample Size n", "Number of Successes: k "}, 
   FrameTicksStyle -> Directive[Large, FontSize -> 12], 
   ImageSize -> 6*72];

Export["plot.png", Style[myPlot, Magnification -> 1], 
 ImageResolution -> 360, ImageSize -> 6*72]

plot

This doesn't display very well at the small ImageSize that was specified in the question, so I tripled that size. You can adjust the Magnification to vary the relative size of the ticks. For this image size, a value of 1 seems to work best. It's counter-intuitive, but you have to include the Style command even though it seems to do nothing.

For a smaller image size, you should choose a larger value, e.g., Magnification -> 2 to get the ticks to be visible.

share|improve this answer
    
(+1) Quite unexpectedly but it works (versions 9.0.1 and 10.3.1)! Actually ImageResolution does nothing here as well as RasterSize: the final size (in the sense of resolution of generated raster image) is determined by the ImageSize option of Export. This option controls the pixel size of the plot in versions 9.0.1 and 10.3.1 but unfortunately does nothing in version 8.0.4. – Alexey Popkov Feb 16 at 7:25
    
@AlexeyPopkov You're right - I copied the ImageResolution option from the question... – Jens Feb 16 at 7:45
    
I joined others in voting to close this as a duplicate. Assuming you do not disagree with that closure, do you think this should be merged, which will move your answer to that question? – Mr.Wizard Feb 16 at 14:37
    
@Mr.Wizard Of course, that's fine. – Jens Feb 16 at 15:15

The following workaround can be seen as an alternative to simpler and more reliable (but in some situations not appropriate) workaround suggested by Jens. It is not perfect because in addition to being significantly more complicated it has several limitations due to abundance of bugs in Export-related functionality:

  • ImageSize must be specified in Export explicitly, it is not sufficient to provide it inside of Graphics expression

  • Scaled font size specification for tick mark labels must be provided via the FrameTicksStyle option in order to the default ImagePadding -> All behaving properly

  • The font size of PlotLabel must be absolute because specifying it as Scaled reveals a bug

  • I'm sure there also are other situations when handling of Scaled font size is broken and absolute font size must be specified

  • The distance between the tick mark labels and the frame gets smaller when you increase ImageSize and there is no proper way to control this distance

The following is a way to generate scalable tick marks and tick mark labels for all types of plots using only built-in (but undocumented) functions of version 10. Please note that it works correctly only for version 10 and already includes a fix for this bug (tested with versions 10.2 and 10.3.1):

data = Array[# &, 600];

linearFrameTicks = {
   {Most /@ Charting`ScaledTicks[{Identity, Identity}][##] &, 
    Most /@ Charting`ScaledFrameTicks[{Identity, Identity}][##] &}, 
   {Most /@ Charting`ScaledTicks[{Identity, Identity}][##] &, 
    Most /@ Charting`ScaledFrameTicks[{Identity, Identity}][##] &}};
p1 = Show[ListPlot[data, Frame -> True, FrameStyle -> Thickness[.003], 
    FrameTicksStyle -> Directive[FontSize -> Scaled[.02], Thickness[.003]]], 
   FrameTicks -> linearFrameTicks, PlotLabel -> "Linear FrameTicks", 
   LabelStyle -> FontSize -> 40, ImageSize -> 1000];
Export["p1.png", p1, ImageSize -> 1000]

p1

linearLogFrameTicks = {
   {Most /@ Charting`ScaledTicks[{Log, Exp}][##] &, 
    Most /@ Charting`ScaledFrameTicks[{Log, Exp}][##] &}, 
   {Most /@ Charting`ScaledTicks[{Identity, Identity}][##] &, 
    Most /@ Charting`ScaledFrameTicks[{Identity, Identity}][##] &}};
p2 = Show[ListLogPlot[data, Frame -> True, FrameStyle -> Thickness[.003], 
    FrameTicksStyle -> Directive[FontSize -> Scaled[.02], Thickness[.003]]], 
   FrameTicks -> linearLogFrameTicks, PlotLabel -> "LinearLog FrameTicks", 
   LabelStyle -> FontSize -> 40, ImageSize -> 1000];
Export["p2.png", p2, ImageSize -> 1000]

p2

logLinearFrameTicks = {
   {Most /@ Charting`ScaledTicks[{Identity, Identity}][##] &, 
    Most /@ Charting`ScaledFrameTicks[{Identity, Identity}][##] &}, 
   {Most /@ Charting`ScaledTicks[{Log, Exp}][##] &, 
    Most /@ Charting`ScaledFrameTicks[{Log, Exp}][##] &}};
p3 = Show[ListLogLinearPlot[data, Frame -> True, FrameStyle -> Thickness[.003], 
    FrameTicksStyle -> Directive[FontSize -> Scaled[.02], Thickness[.003]]], 
   FrameTicks -> logLinearFrameTicks, PlotLabel -> "LogLinear FrameTicks", 
   LabelStyle -> FontSize -> 40, ImageSize -> 1000];
Export["p3.png", p3, ImageSize -> 1000]

p3

logLogFrameTicks = {
   {Most /@ Charting`ScaledTicks[{Log, Exp}][##] &, 
    Most /@ Charting`ScaledFrameTicks[{Log, Exp}][##] &}, 
   {Most /@ Charting`ScaledTicks[{Log, Exp}][##] &, 
    Most /@ Charting`ScaledFrameTicks[{Log, Exp}][##] &}};
p4 = Show[ListLogLogPlot[data, Frame -> True, FrameStyle -> Thickness[.003], 
    FrameTicksStyle -> Directive[FontSize -> Scaled[.02], Thickness[.003]]], 
   FrameTicks -> logLogFrameTicks, PlotLabel -> "LogLog FrameTicks", 
   LabelStyle -> FontSize -> 40, ImageSize -> 1000];
Export["p4.png", p4, ImageSize -> 1000]

p4

share|improve this answer

It is doof but it is working (I had the same problem):

Export["p5.png", 
 Import[Export["p5.pdf", p5, ImageSize -> 360, 
   ImageResolution -> 1000]], ImageResolution -> 1000]

where p5 the name of your plot

share|improve this answer

I finally create a rasterized eps file with sufficent quality for my needs without losing the ticks. Maybe can be helpful even for other file formats outputs.

Try this double rasterization, where you can increase the ImageResolution value, but I do not recomend to increase the RasterSize beyond 515 or the ticks will disappear:

myPlot

Rasterize[%, "Graphics", RasterSize -> 500];

Rasterize[%, "Graphics", ImageResolution -> 350]

Export["myPlot.eps", %]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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