3
using Plots
plot(0:10,sin);
plot!(0:10,sin,seriestype = :scatter)

enter image description here In this example, the output are actually two plots. How can I save them in one file?

I searched and tried some method, but they only support one single plot and I haven't found any functions for multiple plots.

swish47
  • 31
  • 3

1 Answers1

3

This is just one figure - plot! (with a bang) mutates the figure object created in the first plot call.

Saving this is as simple as savefig("my_output.svg") - if this does not work as expected please provide more details.

Not directly related, but seeing that you are overlaying a scatter plot onto a line plot you might be interested in the linetype kwarg:

plot(0:10, sin, linetype = :scatterpath)
plot(0:10, sin, lt = :scatterpath) # short form alias

will both produce a line and scatter at the same time (with a single label and single colour).

Nils Gudat
  • 13,222
  • 3
  • 39
  • 60
  • To the same effect, a shorter keyword (and maybe easier to understand) that I use often is `m=:o` (or `m=:circle` for the nitpicker) :) – Benoit Pasquier Nov 07 '22 at 23:57