Reducing pdf file size in matplotlib

In matplotlibI use LineCollectionfor drawing and color the countries where the borders of the counties are indicated. When I save the shape as a pdf file:

fig.savefig('filename.pdf',dpi=300)

the size of the figure is quite large. However, saving them as a png file:

fig.savefig('filename.png',dpi=300)

and then convert them to pdf using the linux command convert, the files are small. I tried to reduce the dpi, but this did not change the size of the PDF file. Is there any way that the data can be saved directly as smaller files from the matplotlib file?

+3
source share
2 answers

PDF , . PNG, . , PDF, :

plt.plot(x, y, 'r-', rasterized=True)

x, y - . raterized .

+8

, "rasterized = True" png-. , .

, , , . pdf - , .

0

All Articles