Reducing the size of pdf figure file in matplotlib

前端 未结 2 924
猫巷女王i
猫巷女王i 2020-12-31 16:40

In matplotlib, I am using LineCollection to draw and color the countries, where the boundaries of the counties are given. When I am saving the figu

相关标签:
2条回答
  • 2020-12-31 17:23

    I think using "rasterized = True" effectively saves the image similarly to png format. When you zoom in, you will see blurring pixels.

    If you want the figures to be high quality, my suggestion is to sample from the data and make a plot. The pdf file size is roughly the amount of data points it need to remember.

    0 讨论(0)
  • 2020-12-31 17:27

    The PDF is larger, since it contains all the vector information. By saving a PNG, you produce a rasterized image. It seems that in your case, you can produce a smaller PDF by rasterizing the plot directly:

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

    Here, x, y are some plot coordinates. You basically have to use the additionally keyword argument raterized to achieve the effect.

    0 讨论(0)
提交回复
热议问题