- Export the plot as SVG
plt.savefig("plot.svg")
- Open
plot.svg
with an editor and include in the definitions the following:
<defs>
<filter id="shadow">
<feOffset dx="0" dy="0"/>
<feMerge>
<feMergeNode/>
<feMergeNode in="SourceGraphic"/>
</feMerge>
</filter>
</defs>
- Then, for each group of point replace:
<g clip-path="url(#pde120285b9)">
to this:
<g filter="url(#shadow)" clip-path="url(#pde120285b9)">
The clip-path
may vary.
- Finally, use rsvg-convert to convert svg to pdf:
rsvg-convert -d 600 -p 600 -f pdf -o output.pdf input.svg
where 600x600 represents the dpi in each axis.
- For each plot that you want to rasterize use:
plt.plot(..., rasterized=True)
- Save setting dpi:
plt.savefig('dots.pdf', dpi=600)
Using these two approaches in a plot with more than 100k+ points:
1.2M original_file.pdf
160K approach_a.pdf
272K approach_b.pdf
Although the first approach (in this test) results in a smaller file, it's quite easier to use the Approach B than Approach A. Thus, Approach B will be.