5
$\begingroup$

Let's construct some data

data = Exp@Sort@RandomReal[10, 100];
col = Transpose@MapIndexed[Exp[First@#2/20] + #1 &, RandomReal[10, {100, 99}]];

The data and col look like this

g1 = ListLogLogPlot[data, Joined -> True, AspectRatio -> 1/2, 
                          ImageSize -> 300]
g2 = MatrixPlot[col, AspectRatio -> 1/2, ImageSize -> 300]

enter image description here enter image description here

I want g2 as background in g1, Show[g1,g2] can't be done.

Maybe transfer Graphics to Image and using ImageTransformation to make the g2 have a logarithmic x-axis, but I'm not familiar to Image Processing

$\endgroup$
  • $\begingroup$ You can look at Overlay to literally put one graphic on top of the other. You will have to put in some work to get a good alignment, though. $\endgroup$ – Sjoerd Smit Jul 16 '18 at 11:59
5
$\begingroup$

One possible approach is to use the MatrixPlot output as Texture in a Polygon with ImageScaled coordinates (so that its size stretches to the size of the image it sits in) and use the resulting stretchable graphics primitive as Prolog in ListLogLogPlot:

mp = MatrixPlot[col, AspectRatio -> 1/2, ImageSize -> 300, ImagePadding -> 0, 
   DataReversed -> True, Frame -> False];
bg = {Texture[mp], Polygon[{ImageScaled /@ {{0, 0}, {1, 0}, {1, 1}, {0, 1}}}, 
     VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]};
ListLogLogPlot[data, Joined -> True, AspectRatio -> 1/2, 
  ImageSize -> 300, PlotRangeClipping -> True, Prolog -> bg]

enter image description here

An alternative approach is to use the option DataRange in MatrixPlot:

mp2 = MatrixPlot[col, AspectRatio -> 1/2, ImageSize -> 300, 
      DataRange -> {{0, 5}, {0, 10}}];
ListLogLogPlot[data, Joined -> True, AspectRatio -> 1/2, 
  ImageSize -> 300,  Prolog -> mp2[[1]]]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ Cool! But the code is a little difficult to understand, some functions haven't used before. $\endgroup$ – partida Jul 16 '18 at 9:42
  • $\begingroup$ @partida, have a look at the examples in Texture, ImageScaled, and Prolog $\endgroup$ – kglr Jul 16 '18 at 10:47
  • $\begingroup$ OK, thanks for providing the information $\endgroup$ – partida Jul 16 '18 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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