Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vector axes but raster points for Matplotlib scatter plots

I have a Matplotlib scatter plot with 10,000+ points that I plan to insert as a figure in a LaTeX document for publication.

Plot Example

I would like the plot points to be raster graphics (e.g. PNG) because vector graphics with that many points often causes problems for PDF readers. I would like the ticks and axes labels to be vector graphics so I don't have to worry about resolution issues for the text and lines.

Is there a simple way to get matplotlib to make parts of the plot raster graphics while keeping the axes/ticks vector graphics?

My best guess so far is to do some sort of pre-render to PNG then imshow the resulting image with appropriate axes bounds before saving to PDF.

like image 641
John Jumper Avatar asked May 30 '17 01:05

John Jumper


1 Answers

Add rasterized=True to the call to plt.scatter

See the docs here

You can control the dpi of the rasterized parts of the figure by setting dpi=300 (for example) in the call to plt.figure

like image 147
tmdavison Avatar answered Oct 06 '22 05:10

tmdavison