# Non vector graphics display in a notebook

When I generate multiple scatter plots with a large number of points and display them as output, the notebook becomes very sluggish (I assume that this is because each plot has a huge number of points and the system has trouble with the graphics memory or something similar).

I would like to know if it is possible to set things up in such a way that the displayed figures are some sort of png but not vector graphics.

To be clearer: I wish to automatically replace the standard plot output with something like its screenshot. This is just about what I see in the notebook and has nothing to do with the nature of the Graphics object.

I looked around but couldn't find how to do it or whether it is possible.

Thanks! Enrico

• An alternative to a scatter plot for some cases is SmoothDensityHistogram – mikado Oct 23 '18 at 20:21

I wish to automatically replace the standard plot output with something like its screenshot.

Take a look at $Post: $Post = Replace[g : (_Graphics | _Graphics3D) :> Image[g]]


will convert any returned graphics or 3D graphics into an image.

Note this only works if the output is exactly a Graphics, and doesn't look inside. So it would rasterize Plot[x, {x,-2,2}] but not {Plot[x,{x,-2,2}]. To catch the latter, change the Replace above to a ReplaceAll

• You could add Legended as well. Personally I use something like im = Image[Rasterize[#, "Image", ImageResolution -> 2*72], Magnification -> 1/2] &; to get a nice retina rendering. – Szabolcs Nov 22 '18 at 22:19

You can set the $DisplayFunction (default setting for the option DisplayFunction in graphics functions) to Rasterize: $DisplayFunction = Rasterize[#, RasterSize -> 100] &;

{Plot[Sin[x], {x, -2, 2}],
Histogram3D[RandomVariate[NormalDistribution[0, 1], {500, 2}]],
BarChart[RandomInteger[10, {5, 3}]]}


• (+1) It sometimes work with Legended too, what is pleasant (but undocumented). – Alexey Popkov Nov 23 '18 at 13:24

I think you can do what you ask for with the following:

data = RandomVariate[BinormalDistribution[0.5], 1000000];
Image[ListPlot[data]]


Rasterize is an option. For example:

Rasterize[Plot[Sin[x], {x, -2, 2}], RasterSize -> 50]


gives a very coarse plot while

Rasterize[Plot[Sin[x], {x, -2, 2}], RasterSize -> 500]


gives better resolution.