Plotting in a different process

I want to start a second Julia process with

using DistributedNext
addprocs(1)

and use a plotting library, like

@everywhere using ControlPlots

(or Plots or whatever you prefer)

How can I now create a plot in the second Julia process?

 plot(rand(3))

would create a plot in the main process. How can I create the same plot in the second process?

Well basically you need to call the plotting function on the other process.
Have a look at Distributed.remotecall and Distributed.@spawnat

So the general process should be:

  1. Add the worker with addprocs
  2. Setup the worker using e.g.
@spawnat id begin
    # setup code
    using Plots
    include("plotting_stuff.jl")
end
  1. Later call plotting functions with the data via remotecall(plottingfunc, id, args) or use @spawnat again like
@spawnat id begin
    # plotting code
    plottingfunc(data)
end

Alternatively you could setup a channel you just put data in. But that seems more complicated and more limited and I don’t really see the benefits.

1 Like

Thank you!

This works:

@spawnat 1 display(plot(rand(3)))