4
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ As always thanks very much for any help :) $\endgroup$
    – Tom
    Jun 30, 2014 at 15:35

1 Answer 1

8
$\begingroup$

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}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.