Scatter plots, pdf and rasterization (Tiago Pereira)

I have had a similar problem to you. If you save a plot in vector (svg)
format then turn it into a pdf then all parts of the plot are saved as
individual layers and the file can take a long time to load -- say from
within in a LaTex pdf. One option is to save the file in a raster
format (*.jpg, *.png etc). Then you may use a program like Inkscape to
open the file, where you can then save a copy of it as a pdf. This
process produces publication quality plots. The plot detail can then be
improved by simply increasing the figure dpi when it is initially saved
using Matplotlib.

Adam

···

On Thu, 2009-04-02 at 01:45 +0000, matplotlib-users-request@lists.sourceforge.net wrote:

Send Matplotlib-users mailing list submissions to
  matplotlib-users@lists.sourceforge.net

To subscribe or unsubscribe via the World Wide Web, visit
  https://lists.sourceforge.net/lists/listinfo/matplotlib-users
or, via email, send a message with subject or body 'help' to
  matplotlib-users-request@lists.sourceforge.net

You can reach the person managing the list at
  matplotlib-users-owner@lists.sourceforge.net

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Matplotlib-users digest..."

Today's Topics:

   1. Scatter plots, pdf and rasterization (Tiago Pereira)

----------------------------------------------------------------------

Message: 1
Date: Thu, 02 Apr 2009 12:43:39 +1100
From: Tiago Pereira <tiagomdp@...287...>
Subject: [Matplotlib-users] Scatter plots, pdf and rasterization
To: matplotlib-users@lists.sourceforge.net
Message-ID: <49D4184B.5030003@...287...>
Content-Type: text/plain; charset="iso-8859-1"

Hi,

I have a recurrent problem when trying to put some plots in pdf format.
Searching in this mailing list and google I haven't been able to find a
reasonable answer to this problem, and was wondering if someone could
point me in the right direction.

The problem is the following. When saving to pdf matplotlib saves as a
vectorial pdf -- which is great. However I have some scatter plots that
have a lot of points (~ 400.000, see attached example in png). When I
save this into pdf the file is massive and takes a lot of time to open
in a reader. Since I don't really need the vectorial data for this
scatter plot, I was wondering if there was a way to still save as pdf
but keep the plot itself as a raster, instead of the full data. Why save
as pdf? Because I'd still like to have the scalable fonts. This is for a
publication, so it's much more harmonious to have the latex bits in the
plot as pdf.

I have developed an intermediate solution. I have done a high-resolution
2D histogram of the data and using imshow and a suitable colormap,
plotted that. For example in the blue points in the example I can get a
very good match on the screen. However I can only plot one set of data.
If I want to use other data in a different colour this doesn't work,
since another imshow will cover the original data. Unless there is the
option to have a transparent colour in the colormap, which I doubt.

Do you have any ideas on how I could rasterize a plot and still save it
as pdf?

Thanks!

Tiago
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example.png
Type: image/png
Size: 52041 bytes
Desc: not available

------------------------------

------------------------------------------------------------------------------

------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

End of Matplotlib-users Digest, Vol 35, Issue 3
***********************************************