Dan
Dan

Reputation: 12074

Plotting the same plot twice as subplots

I want to create a plot with a couple of subplots using Plots.jl. Here's an example:

using Plots
gr()

p = plot(1:10, 1:10)
q = plot(1:10, 10:-1:1) 

plot(p, q)

enter image description here

That works exactly as expected! But say I want to use the same plot twice like so:

plot(p, p)

enter image description here

Hmmm. Only one plot. Perhaps I need to copy the plot first:

plot(p, copy(p))

but that give an error:

ERROR: MethodError: no method matching copy(::Plots.Plot{Plots.GRBackend})
Closest candidates are:
copy(::Expr) at expr.jl:36
copy(::Core.CodeInfo) at expr.jl:64
copy(::BitSet) at bitset.jl:46
...
Stacktrace:
1 top-level scope at REPL[216]:1

How can I plot the same subplot twice?

Upvotes: 1

Views: 202

Answers (1)

Bill
Bill

Reputation: 6086

You have the right idea, but try deepcopy() instead of copy(). deepcopy() often works on arbitrary objects which have no specific copy() method.

Upvotes: 1

Related Questions