# How to save a plot as a jpeg file?

**URL:** <https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005>\
**Category:** New to Julia\
**Tags:** question, io, gmt\
**Created:** [November 5, 2021, 1:31pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005 "2021-11-05T13:31:20Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [November 5, 2021, 1:31pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/1 "2021-11-05T13:31:20Z")

</div>

In Matlab, if you want to save your plot (“h” is the figure handle) as a jpg file with a resolution of 600pixel. Below is all it takes:

```julia
File_W = "/path/test.jpg";
exportgraphics(h, File_W, 'Resolution', 600);

```

Does Julia offer such a solution as well? BTW, I’m making these plots using the GMT.jl package.

As a Matlab person, I find it very interesting that the GMT.jl package does not use any kind of figure handle. Is this a Julia thing? Then how do you refer to a figure when you try to save it in an automatic fashion?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [November 5, 2021, 1:41pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/2 "2021-11-05T13:41:43Z")

</div>

I don’t know anything about GMT, but it seems to have pretty extensive documentation which discusses outputformats [here](https://www.generic-mapping-tools.org/GMT.jl/dev/modules/#The-output-format), giving the example

```julia
psconvert(in_memory=true, adjust=true, format=:f, out_name="myfig.pdf")

```

As for not having an explicit figure object, that’s not a Julia thing, at least not for the two most widely used plotting packages Plots and Makie. Both allow plotting with or without assigning the plot/figure object explicitly (in Plots it would be something like `myplot = plot(x, y)` and in Makie I believe it’s `myfig, myaxis = plot(x, y)`)

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [November 5, 2021, 1:45pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/3 "2021-11-05T13:45:54Z")

</div>

Many thanks for pointing the right direction! I’ll check out the GMT.jl documentation then.

I thought this would be a generic Julia function like in Matlab, but it seems to be package specific.

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [November 5, 2021, 1:58pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/4 "2021-11-05T13:58:24Z")

</div>

Unfortunately, it is a solution for Windows only! This is absurd, because I can manually save them as a jpeg file without any issues on my Mac.

Does anyone have a solution for Mac users? I plan to make ~400 of such plots. Manually saving them will be impossible.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [November 5, 2021, 3:15pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/5 "2021-11-05T15:15:50Z")

</div>

Linking [this post by](https://discourse.julialang.org/t/gmt-jl-errors-when-trying-to-plot-problem-with-png/47860/2) @joa-quim.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [November 5, 2021, 3:25pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/6 "2021-11-05T15:25:48Z")

</div>

> [@leon](#):
>
> Unfortunately, it is a solution for Windows only! This is absurd, because …

😲😲😲 ??? Where did you get that idea? Doesn’t the documentation say that one can either use `fmt=:jpg` or `savefig="myPlot.jpg"`

---

<div class="post-metadata">

**Author:** ![j\_u](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_u/32/219081_2.png) [@j\_u](https://discourse.julialang.org/u/j_u)\
**Post date:** [November 5, 2021, 3:37pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/7 "2021-11-05T15:37:39Z")

</div>

> [@leon](#):
>
> I find it very interesting that the GMT.jl package does not use any kind of figure handle. Is this a Julia thing?

As I understand it, `GMT.jl` is a Julia wrapper around `GMT` which is written in C / C++ and uses PostScript ([Generic Mapping Tools - Wikipedia](https://en.wikipedia.org/wiki/Generic_Mapping_Tools)).

I am relatively new to Julia. What I found is that the Julia Plotting World is very colorful and even packages like `Gadfly` and `Makie` that I understand are written fully in Julia are handling the same things slightly different. So in general, you have to familiarize yourself with each package and learn some of their intricacies. As a side not, you may also take a look at `Plots.jl` which is doing some kind of “integration” over various plotting backends, and is providing a common interface.

I do not know if `GMT` is better or worse to above mentioned packages, what I think is that it is handling things very different to `Gadfly` and `Makie` under the hood as I understand due to its C / C++ origin. As for PostScipt, some time ago, you could hardly go any better than using it in the professional printing world, however, this might have changed over the recent years. Even though, I guess PostScript might offer some advantages. Please see [How to create layouts in Julia plotting packages? - #11 by joa-quim](https://discourse.julialang.org/t/how-to-create-layouts-in-julia-plotting-packages/70586/11)

Im not sure if I fully understand what you want to do. As for know I am assuming you want to save a plot. If so, I understand the option `savefig="figname"` should be working: [What is your favorite mapping package? - #22 by joa-quim](https://discourse.julialang.org/t/what-is-your-favorite-mapping-package/70509/22)

EDIT: I just spotted the question was answered by @joa-quim

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [November 5, 2021, 3:55pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/8 "2021-11-05T15:55:50Z")

</div>

I was referring to the `psconvert` as mentioned by another member:  
[https://www.generic-mapping-tools.org/GMT.jl/dev/modules/#The-output-format](https://www.generic-mapping-tools.org/GMT.jl/dev/modules/#The-output-format)

Glad to hear this can be done as simple as:  
either use `fmt=:jpg` or `savefig="myPlot.jpg"`

Just tested it and it works like a charm!

Many thanks as always!

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [November 5, 2021, 4:01pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/9 "2021-11-05T16:01:31Z")

</div>

Quoting from that link.

> An interesting alternative is to set **FMT=“”** , that is to not specify any image format. This will result in _NOT_ saving any file on disk but to keep the PS figure internally stored in the program’s memory. In other words, the figure is built and kept in memory only. This allows converting to another format directly without the use of an intermediary disk file.  
> …  
> The issue with this solution, that could be implemented internally without user intervention, is that it currently only works on Windows.

It’s `fmt=""` that only works on Windows. Isn’t that clear form the text?

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [November 5, 2021, 4:07pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/10 "2021-11-05T16:07:20Z")

</div>

Similar as in [How to create layouts in Julia plotting packages? - #2 by aramirezreyes](https://discourse.julialang.org/t/how-to-create-layouts-in-julia-plotting-packages/70586/2)  
The question about how to do something related to plotting in julia doesnt make a lot of sense. Every package has different design and implementations. So, like in the other thread how do you save a figure will be different depending on the package. So no, not a julia thing.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [November 5, 2021, 4:13pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/11 "2021-11-05T16:13:14Z")

</div>

> [@aramirezreyes](#):
>
> So, like in the other thread how do you save a figure will be different depending on the package

But in practice they tend to be very similar 🙂

---

<div class="post-metadata">

**Author:** ![j\_u](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_u/32/219081_2.png) [@j\_u](https://discourse.julialang.org/u/j_u)\
**Post date:** [November 5, 2021, 4:18pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/12 "2021-11-05T16:18:07Z")

</div>

> [@joa-quim](#):
>
> But in practice they tend to be very similar 🙂

However, it would be probably potentially extremally useful to have a concise, very short tutorial about the basic, most commonly used functions and workflows of the GMT.jl, on the GMT.jl welcome page, especially that the documentation is so extensive. This is of course written with a big smile. 🙂

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [November 5, 2021, 4:22pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/13 "2021-11-05T16:22:10Z")

</div>

Yes, I understand that. But I struggle to on the same time add more in depth documentation to many modules that are lacking them, more examples, etc.  
Do you think porting the GMT [tutorial](https://docs.generic-mapping-tools.org/dev/tutorial.html) to GMT.jl syntax would fill that gap?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [November 5, 2021, 4:22pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/14 "2021-11-05T16:22:11Z")

</div>

@joa-quim, searching the GMT.jl doc for `savefig`, there was only one hit and the place seemed crowded. Maybe including some simple example as you provided here?

_NB: and sorry if overlooked something in the good docs provided_

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [November 5, 2021, 4:34pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/15 "2021-11-05T16:34:00Z")

</div>

> [@joa-quim](#):
>
> Do you think porting the GMT [tutorial](https://docs.generic-mapping-tools.org/dev/tutorial.html) to GMT.jl syntax would fill that gap?

That would be awesome.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [November 5, 2021, 4:38pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/16 "2021-11-05T16:38:19Z")

</div>

> [@rafael.guerra](#):
>
> Maybe including some simple example as you provided here?

When I search for `savefig` in the examples of the `doc` subdirectory, I find several occurrences. But yep, should add more and specially also inform that `figname` or only `name` are synonyms of `savefig`.

---

<div class="post-metadata">

**Author:** ![j\_u](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_u/32/219081_2.png) [@j\_u](https://discourse.julialang.org/u/j_u)\
**Post date:** [November 5, 2021, 4:41pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/17 "2021-11-05T16:41:05Z")

</div>

> [@joa-quim](#):
>
> Yes, I understand that. But I struggle to on the same time add more in depth documentation to many modules that are lacking them, more examples, etc.  
> Do you think porting the GMT [tutorial](https://docs.generic-mapping-tools.org/dev/tutorial.html) to GMT.jl syntax would fill that gap?

Frankly, I was thinking about something simpler, like a “two-pager summary”.

Very basic things, opening the file (what are supported formats), making a plot (what are basic plot options), saving a figure (what are supporting output formats) and for example a basic semi-advanced topics like how to make a plot with use of more than one file, how to make a stack of two plots. It would be great to see the examples of corresponding code and output figures.

Something that would make an entry barrier for a new GMT.jl user lower and rally not longer than two pages. I think that is is always great to type a web page address of a new package and be able to do some basics after a short read. Later the user, can always get more knowledge about the package and do more advanced things after reading the full documentation.

Edit: I just spotted [Some examples · GMT](https://www.generic-mapping-tools.org/GMT.jl/dev/examples/). I was thinking about this kind of thing but I was looking for it directly at the main github webpage ([GitHub - GenericMappingTools/GMT.jl: Generic Mapping Tools Library Wrapper for Julia](https://github.com/GenericMappingTools/GMT.jl)).

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [November 5, 2021, 4:51pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/18 "2021-11-05T16:51:20Z")

</div>

> [@j\_u](#):
>
> like a “two-pager summary”

Thanks for this suggestion. I’ll start wondering on the design of that in the _betweens_ of my (but not only me) 4 disciplines this semester. But I’ll have to make tinny figures so that they all fit in those two pages 😆

---

<div class="post-metadata">

**Author:** ![j\_u](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_u/32/219081_2.png) [@j\_u](https://discourse.julialang.org/u/j_u)\
**Post date:** [November 5, 2021, 4:54pm UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/19 "2021-11-05T16:54:56Z")

</div>

> [@joa-quim](#):
>
> I’ll start wondering on the design of that in the _betweens_ of my (but not only me) 4 disciplines this semester.

Just the basics. Two pager. I know THE GMT.JL is a specialized package, used predominantly by very well educated people, however, with full respect, there is usually, no need for consultations outside teaching hours. 🙂

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [November 6, 2021, 11:27am UTC](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005/20 "2021-11-06T11:27:09Z")

</div>

@joa-quim, do you know how I could change the resolution of such maps? For example, may I set it as 600 pixel like in my Matlab example?

I tried to use the `resolution=:full` argument, but got the below error:  
`the following options were not consumed in grdimage => [:resolution]`

I also noticed the `dpi` option, should I use it only on the last plotting command? I have many `grdimage` plotting commands, plus `scatter`, and `text`.

[Next page](https://discourse.julialang.org/t/how-to-save-a-plot-as-a-jpeg-file/71005.md?page=2)
