# Combining ArrayPlot and Plot

I have two plots.

• plot1 is a colour graph generated using ArrayPlot.
• plot2 is a function plotted using Plot.

I want to do two things.

1. Scale the axes of plot1 to be the same as plot2 (instead of just pixel counts).
2. Overlay plot2 onto plot1.

As an example, say I have

plot1 = ArrayPlot[RandomReal[{0, 1}, {100, 100}], FrameTicks -> Automatic]


plot2 = Plot[x^2, {x, 0, Pi}, PlotRange -> {0, 2 Pi}, PlotStyle -> {Thick,Red}]


How do I scale plot1 to read x-values from 0 to $\pi$ and y-values from 0 to $2\pi$ and then overlay plot2 on top of plot1?

I'm open to suggestions on using different plotting functions if there's a more logical way of doing this.

• As always thanks very much for any help :)
– Tom
Commented Jun 30, 2014 at 15:35

Use the DataRange option of ArrayPlot. If possible, it might help to force the size of the array to have the correct aspect ratio.

plot1 = ArrayPlot[RandomReal[{0, 1}, {200, 100}],
FrameTicks -> Automatic, DataRange -> {{0, Pi}, {0, 2 Pi}}];
plot2 = Plot[x^2, {x, 0, Pi}, PlotRange -> {0, 2 Pi},
PlotStyle -> {Thick, Red}];
Show[{plot1, plot2}]