Savefig in plots jl is slow when i scatter 13056 points

using Plots
scatter(rand(13056), rand(13056))
savefig("scatter_plot.png")

Option 1: Using the default savefig function

The default savefig function in the Plots package is known to be slow when saving large plots. However, there are a few ways to optimize the saving process.

using Plots
scatter(rand(13056), rand(13056))
savefig("scatter_plot.png", dpi = 300)

By specifying a higher dpi (dots per inch) value, we can improve the resolution of the saved image. However, this may also increase the file size.

Option 2: Using the GR backend

The Plots package supports multiple backends, and the default backend used for saving figures is the default backend specified in your Julia environment. However, the GR backend is known to be faster for saving large plots.

using Plots
gr()
scatter(rand(13056), rand(13056))
savefig("scatter_plot.png")

By explicitly setting the backend to GR, we can take advantage of its faster saving capabilities.

Option 3: Using the Cairo backend

Another option is to switch to the Cairo backend, which is known for its speed and high-quality output.

using Plots
cairo()
scatter(rand(13056), rand(13056))
savefig("scatter_plot.png")

The Cairo backend is optimized for saving high-resolution images and is generally faster than the default backend.

Among the three options, using the Cairo backend tends to provide the best performance and output quality. However, the choice ultimately depends on your specific requirements and preferences.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents