logo

How to Adjust the Size and Resolution of an Image in Julia 📂Julia

How to Adjust the Size and Resolution of an Image in Julia

Code

Size

  • plot(x, y, size=(600,400))

In Julia, the size of a plot is set using the size option. It must be input as a Tuple{Integer, Integer}, where each integer represents the width and height in pixels, respectively. The default value is (600,400).

using Plots

x = rand(10)

plot(x)
savefig("size_default.png")

plot(x, size=(1200,800))
savefig("size_(1200,800).png")

1800x1200 image (left), 600x400 image (right)

Resolution

  • plot(x, y, dpi=100)

The resolution of an image is set using the dpi option, with the default value being 100. It’s advisable to use about 300 for documents to be included in papers, reports, PowerPoint presentations, etc.

using Plots

x = rand(10)

plot(x)
savefig("dpi_default.png")
                              
plot(x, dpi=300) 
savefig("dpi_300.png")

dpi=100 image (top), dpi=300 image (bottom)

Also, when increasing the size, it’s necessary to increase the resolution as well to maintain the attractiveness of the image. If you save with the dpi set to 300 and the size increases to 1800x1200, but keep the dpi at the default value of 100 while increasing just the size, the image will become unattractive, so pay attention.

dpi=300, size=1800x1200 image (left), dpi=100, size=1800x1200 image (right)

Environment

  • OS: Windows11
  • Version: Julia 1.9.0, Plots v1.38.12