I created a two grids like this
height = 125;
cb = MatrixPlot[
Table[Mod[i + j, 2], {i, 1, 2}, {j, 1, 8}]
, ColorFunction -> "BlueGreenYellow"
, ImageSize -> {Automatic, 2*height}
]
p1 = MatrixPlot[
Table[1, {i, 1, 1}, {j, 1, 2}]
, Mesh -> True
, ColorFunction -> ColorData["DarkRainbow"]
, ImageSize -> {Automatic, height}
]
If I combine the two with Inset, I get
Graphics[{First@cb, Inset[p1, {0, 0}]}]
What should I do if I want to cover the top-left two squares of the yellow/green grid with the red grid?
(I know I could redraw the larger grid with the color of some squares changed. But I want to know how to do it with Inset.)
Update, after trying to play with the parameters of Inset, I have found some appropriate parameters that works. But this takes a lot trials.
Is there a way to keep images with their "absolute" size when using Inset?
Manipulate[ Graphics[{First@cb, Inset[p1, {x, y}, {Left, Bottom}, {Automatic, w}]}, ImageSize -> ImageDimensions[cb]], {{x, -0.1}, -0.5, 0.5}, {{y, 0.8}, 0.0, 1.0}, {{w, 1.4}, 0.5, 2}]
Answer
Maybe not an answer
I think that Inset[]
is not what you need.
This is what is happening when one resizes a graphic with some Inset[]
without the fourth argument :
If you need a layout that doesn't change when resizing, you can use the 4 arguments form, but I find it a way easier not to use Inset[]
at all :.
Like this :
height = 125;
cb = MatrixPlot[
Table[Mod[i + j, 2], {i, 1, 2}, {j, 1, 8}]
, ColorFunction -> "BlueGreenYellow"
, ImageSize -> {Automatic, 2*height}
];
p1 = MatrixPlot[
Table[1, {i, 1, 1}, {j, 1, 2}]
, Mesh -> True
, ColorFunction -> ColorData["DarkRainbow"]
, ImageSize -> {Automatic, height}
];
Graphics[{cb[[1, {1, 2}]], Translate[p1[[1, {1, 2}]], {0, 2}]}, Frame -> True]
Comments
Post a Comment