I have some plots as images. I import them in a notebook and arrange them using GraphicGrid
as follows
Now I want to label each one in the empty space of the plots, How can do that?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityUpdate Arbitrary positioning of labels
Using Inset
they can be positioned anywhere by adjusting the values of position
.
position = {0.75, 0.9}
labeled =
MapThread[
Show[{#1},
Epilog ->
Inset[Graphics[{Text[Style[#2, Blue, Bold, 25]]}],
Scaled[position]]] &, {images, labels}]
labeled // Partition[#, UpTo@3] & // Grid[#, Alignment -> Top, Frame -> All] &
Using Labeled
.
images = Table[RandomImage[RandomInteger[{1, 5}], {100, 100}], 9]
labels = "Plot " <> ToString[#] & /@ Range@Length@images
labeled = MapThread[Labeled[#1, #2, Top] &, {images, labels}]
labeled // Partition[#, UpTo@3] & // Grid[#, Alignment -> Top, Frame -> All] &
Not quite there yet, but this may give you (and others) an approach to the problem.
plotImages = (paste image here)
plotLabels = GraphicsGrid[{
{"Plot 1", "Plot 2", "Plot 3"},
{"Plot 4", "Plot 5", "Plot 6"},
{"Plot 7", "Plot 8", "Plot 9"}
},
Spacings -> {30, 20},
Alignment -> {Right, Top}
];
ImageCompose[plotImages, plotLabels, {Center, Center}]
Another imperfect solution but again, it may lead to better ones:
labelFunc[text_] :=
Graphics[{White, Opacity[0.5], Rectangle[{0, 0}, {1.5, 1}],
Text[Style[text, Black, Bold], {1.2, 0.75}, Automatic]}];
plotLabels2 = GraphicsGrid[{
{labelFunc["Plot 1"], labelFunc["Plot 2"], labelFunc["Plot 3"]},
{labelFunc["Plot 4"], labelFunc["Plot 5"], labelFunc["Plot 6"]},
{labelFunc["Plot 7"], labelFunc["Plot 8"], labelFunc["Plot 9"]}
},
Spacings -> {30, 20},
Alignment -> {Right, Top}
];
ImageCompose[plotImages, plotLabels2, {Center, Center}]
Manipulate
so you can vary the Spacings
values in realtime until you hit on something.
$\endgroup$
Epilog
). Alternatively, you could useResourceFunction["PlotGrid"]
with itsPlotLabels
option. $\endgroup$GraphicsGrid
instead ofGrid
? (I'm not sure about all the differences, but as far as I remember,GraphicsGrid
mostly makes sense with actualGraphics
objects). That being said: you should be able to add the labels to the individual images usingLabeled
prior to combining them into a grid $\endgroup$