Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
    
As always thanks very much for any help :) –  TomJS Jun 30 at 15:35

1 Answer 1

up vote 6 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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