# How to combine ListLogLogPlot and MatrixPlot?

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]


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

• 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. – Sjoerd Smit Jul 16 '18 at 11:59

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]


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


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