# Rasterizing a plot make axes ticks invisible [duplicate]

I've evaluated this code:

plot = Plot[x, {x, 0, 10}];
g = Rasterize[plot, ImageResolution -> 300];


Everything looks good except the ticks (on the axes); they are invisible! It seems that Mathematica draws ticks in a default size on the scaled image, and after the image is scaled down, they are made too small to be distinguished at all.

The more ImageResoltion I specify, the smaller the ticks are and the less pleasing the image is.

How can I get the axes ticks to look right?

-

## marked as duplicate by Alexey Popkov, Michael E2, MarcoB, Louis, RunnyKineMar 10 at 18:11

You've tried tweaking ImageResolution and RasterSize at the same time? Rasterize[Plot[x, {x, 0, 10}], ImageResolution -> 512, RasterSize -> 512] looks good to me... – J. M. Nov 18 '12 at 23:42
Well, I don't really know why and don't know whether it's intentional but simultanesous use of ImageResolution and RasterSize have no use in my case, seems that Raster Size "kills" ImageResolution. – DimG Nov 19 '12 at 0:43
Current thread with solutions for recent Mathematica versions: "Export high resolution figure causes missing ticks." – Alexey Popkov Mar 10 at 14:25

There is a hack that has some added advantages - in particular as a by-product you also get a vector graphics version of your plot that can be resized while keeping all relative sizes at the correct proportions:

plot = Plot[x, {x, 0, 10}];
h = First@ImportString[ExportString[plot, "PDF"]];

Rasterize[h, ImageResolution -> 300]


The result has all the ticks at the same relative size as in the notebook. Moreover, the intermediate graphic in h contains the plot as if it had been exported to PDF and re-imported, i.e., it's a vector graphic but structured in a way that doesn't allow Mathematica to revise its tick marks etc.

-
A great trick:) One question: what can I do with axe/ticks color intensity of rasterized version? As I see that, if, let's say, I run this code: Rasterize[ First@ImportString[ExportString[Show[plot, ImageSize -> 100], "PDF"]] , ImageResolution -> 500] I get image with preserved proportion but axe ant ticks line width is not the same proportional. If I scale the rasterized version up to 5 times I see axes and ticks with line width as If they appear on default plot output. In other words, everything is great except the fact that axes and ticks get "transparent" due to antialiasing. – DimG Nov 19 '12 at 8:52
@DimG Thanks for the accept - as to the axis thickness, the problem seems to be that the thickness of axes and frames is by default given as AbsoluteThickness[x] and the latter isn't translated correctly in the Export. But this can be fixed by explicitly adding an option AxesStyle->Thickness[n] or FrameStyle->Thickness[n] to your plot. Here, Thickness is a relative quantity that you can calculate from n = x/w where w is the width of the plot. For some reason, these relative thickness specifications are translated correctly. – Jens Nov 25 '12 at 17:52
@Jens: I used your suggestion, too, to solve a similar problem. I used FrameStyle->Thickness[0.003], FrameTicksStyle->Thickness[0.003] in my framed plot to get both the frame and the ticks in the right width. – Apatura Feb 9 '13 at 23:18

You can try to regulate ImageSize together with ImageResolution. There is one example: You get:

plot = Plot[x, {x, 0, 10}, ImageSize -> 250];
g = Rasterize[plot, ImageResolution -> #] & /@ {25, 50, 100, 200};
ImageDimensions /@ g
TableForm[Partition[g, 2]]


And yes, the quality is not as good as the vectorial form. Where we get:

I think that it's due different way Mathematica render vector and images.

-
First of all, ImageSize and ImageResolution used together at the same level have no sense (seems that ImageSize has more priority), try to change ImageResolution and you will get no difference. You would rather have said something of: Rasterize[Show[plot, ImageSize-> 500], ImageResolution -> 150] However the main problem still remains as I've described: look at the axes ticks and you will notice dramatical difference between what Mathematica draws on the screen by default and what you get after Rasterize[]. – DimG Nov 19 '12 at 0:27
I get your point. But just for curiosity, why you want that? Why use rastered form in your notebook? – Murta Nov 19 '12 at 1:15
Firstly I got this problem while Export[] (I have to make high-resolution .png for including in LaTeX). But then I found similar behaviour of Rasterize[] and since it's simpler to reproduce in Mathematica (nothing to do with creating files and littering the filesystem, everything is seen on the screen), I've chosen Rasterize[] for a question:) – DimG Nov 19 '12 at 7:39
Understand. Yes, you have to choose ImageResolution as Export argument too. – Murta Nov 19 '12 at 18:10