Message Boards Message Boards

0
|
16179 Views
|
14 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Add text to graphics?

Hello there! I am trying to make some plots for a paper, and I want to make them as simple and elegant as possible. I managed to do some things, but I also want to add some text boxes (without using the editing tool) at any arbitrary position, similar in behavior like this:

PlotLegends -> Placed[{"Exp."}, {0.15, 0.75}]

How can I put some boxes in the plots? I want one somewhere in the top right, and a second one in the bottom right. I also want to make the ticks a little bit longer (I tried to use some Tick related options but I got no results.

Thank you in advance!!

p1 = Plot[x^2 + 2 x + 1, {x, 6, 50}, PlotStyle -> {Thick, Black}, 
   Axes -> False, Frame -> True, 
   FrameLabel -> {"I [\[HBar]]", "E [MeV]"}, 
   LabelStyle -> { Bold, FontSize -> 15, Black}, GridLines -> None, 
   PlotStyle -> {{Black, Thick}}, 
   PlotLegends -> Placed[{"Th."}, {0.15, 0.75}], ImageSize -> Large, 
   PlotRange -> Automatic];
p2 = Plot[x^2 - x + 5, {x, 6, 50}, PlotStyle -> {Thick, Black}, 
   Axes -> False, Frame -> True, 
   FrameLabel -> {"I [\[HBar]]", "E [MeV]"}, 
   LabelStyle -> { Bold, FontSize -> 15, Black}, GridLines -> None, 
   PlotStyle -> {{Black, Thick}}, 
   PlotLegends -> Placed[{"Exp."}, {0.15, 0.75}], ImageSize -> Large, 
   PlotRange -> Automatic];
Show[p1, p2]
POSTED BY: Robert Poenaru
14 Replies

I think there is a way to get Epilogs from older plots, See GetEpilog in the notebook attached - near the end.

Attachments:
POSTED BY: Hans Dolhaine
Posted 2 years ago

This really works. Thanks so much.

POSTED BY: a a
Posted 8 years ago

To place text in your Graph, consider using Epilog and Inset:

Show[p1, p2, 
 Epilog -> {Inset[
    Framed[Style["Top Right", 20], Background -> White], {45, 2300}], 
   Inset[Framed[Style["Bottom Right", 20], Background -> White], {45, 
     300}]}]

My Plot

POSTED BY: Kyle Martin

Works like a charm. Thank you very much Kyle ;)

POSTED BY: Robert Poenaru
Posted 2 years ago

is it possible to put epilog in plots rather than in show?

POSTED BY: a a
Posted 2 years ago

Yes. Why don't you try it, or check the documentation?

POSTED BY: Rohit Namjoshi
Posted 2 years ago

yes, but only the 1st epilog will be retained, how to resolve this?

POSTED BY: a a
Posted 2 years ago

Show inherits options from the first element. There is no way to change that behavior. One option is to use the Wolfram Function Repository function CombinePlots. E.g.

combinePlots = ResourceFunction["CombinePlots"];

p1 = Plot[Sin[x], {x, 0, 2 Pi},
  Frame -> True,
  Epilog -> Inset[Framed["Plot 1"], Scaled[{0, 1}], ImageScaled[{0, 1}]]]

p2 = Plot[Cos[x], {x, 0, 2 Pi},
  Frame -> True,
  Epilog -> 
   Inset[Framed["Plot 2"], Scaled[{1, 0}], ImageScaled[{1, 0}]]]

combinePlots[{p1, p2}]

enter image description here

POSTED BY: Rohit Namjoshi
Posted 2 years ago

enter image description here thank you, but after hiding plot1 and plot2 I got this

POSTED BY: a a
Posted 2 years ago

I have no idea what you mean by "after hiding plot1 and plot 2". You post an image that is of very little value. Post code that can be copied, pasted, and evaluated so that the people you are asking for help from can reproduce the problem.

POSTED BY: Rohit Namjoshi
Posted 2 years ago

combinePlots = ResourceFunction["CombinePlots"];

p1 = Plot[Sin[x], {x, 0, 2 Pi},
  Frame -> True,
  Epilog -> Inset[Framed["Plot 1"], Scaled[{0, 1}], ImageScaled[{0, 1}]]];

p2 = Plot[Cos[x], {x, 0, 2 Pi},
  Frame -> True,
  Epilog -> 
   Inset[Framed["Plot 2"], Scaled[{1, 0}], ImageScaled[{1, 0}]]];

combinePlots[{p1, p2}]
POSTED BY: a a
Posted 2 years ago
Plot[
   {x^2 + 2 x + 1, x^2 - x + 5}, {x, 6, 50},
   Axes -> False, Frame -> True,
   FrameLabel -> {"I [\[HBar]]", "E [MeV]"},
   PlotStyle -> {Black, Thick},
   ImageSize -> Large,
   PlotRange -> Automatic,
   PlotLegends -> Placed[{"Th.", "Exp."}, {0.15, 0.75}],
   Epilog -> {
     Inset[Framed[Style["Top Right", 20], Background -> White], {45, 2300}],
     Inset[Framed[Style["Bottom Right", 20], Background -> White], {45, 300}]
   }
 ]
POSTED BY: Hans Milton
Posted 2 years ago

Thank you, this of course works, but I want to define a function to plot things with text as in the OP, then show various such functions together.

POSTED BY: a a

Also, any other useful tips about making cool plots in Mathematica are welcome :)

POSTED BY: Robert Poenaru
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract