1
$\begingroup$

I have some plots as images. I import them in a notebook and arrange them using GraphicGrid as follows enter image description here

Now I want to label each one in the empty space of the plots, How can do that?

$\endgroup$
6
  • 1
    $\begingroup$ You can label the plots before putting them into the grid (e.g. using Epilog). Alternatively, you could use ResourceFunction["PlotGrid"] with its PlotLabels option. $\endgroup$
    – Lukas Lang
    Oct 22, 2021 at 16:49
  • $\begingroup$ Thanks but none of your suggestions is not what I asked $\endgroup$
    – Wisdom
    Oct 22, 2021 at 16:54
  • 1
    $\begingroup$ Could you explain why they can't solve your problem? I reread your question, and I'm still not sure what else you could be trying to achieve $\endgroup$
    – Lukas Lang
    Oct 22, 2021 at 17:13
  • $\begingroup$ I have no access to produce images. I just already have some images. $\endgroup$
    – Wisdom
    Oct 22, 2021 at 17:32
  • 1
    $\begingroup$ Ah, I see... Then why use GraphicsGrid instead of Grid? (I'm not sure about all the differences, but as far as I remember, GraphicsGrid mostly makes sense with actual Graphics objects). That being said: you should be able to add the labels to the individual images using Labeled prior to combining them into a grid $\endgroup$
    – Lukas Lang
    Oct 22, 2021 at 17:48

2 Answers 2

2
$\begingroup$

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

enter image description here


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

enter image description here

$\endgroup$
3
  • $\begingroup$ Thanks good idea, however I can't place the labels in empty space of my plots, the previous answer seems more flexible in this sense. $\endgroup$
    – Wisdom
    Oct 22, 2021 at 19:41
  • $\begingroup$ @Wisdom Check the update. $\endgroup$ Oct 22, 2021 at 20:07
  • $\begingroup$ Great! Now your answer is better! $\endgroup$
    – Wisdom
    Oct 22, 2021 at 20:09
1
$\begingroup$

Not quite there yet, but this may give you (and others) an approach to the problem.

plotImages = (paste image here)

enter image description 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}]

enter image description here

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

enter image description here

$\endgroup$
2
  • $\begingroup$ interesting idea! thanks. However is there a way to arrange labels as they are placed in appropriate locations? for example can I adjust their spaces differently? $\endgroup$
    – Wisdom
    Oct 22, 2021 at 18:16
  • 1
    $\begingroup$ Certainly. You just need to play around with it a bit. Maybe setup a Manipulate so you can vary the Spacings values in realtime until you hit on something. $\endgroup$
    – Jagra
    Oct 22, 2021 at 18:59

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.