0
$\begingroup$

I have a .dat file named W11. Then I plotted it in Mathematica

ListPlot[{W11}
 , ImageSize -> Scaled[0.5]
 , PlotLabel -> Style["\[Alpha] = 0.5", Bold, FontSize -> 15]
 , PlotStyle -> {{Blue}}
 , PlotRange -> Automatic
 , GridLines -> {{0.3268350735*Pi}, {0}}
 , GridLinesStyle -> Directive[Thick, Gray]
 , PlotLegends -> 
  SwatchLegend[{Blue, Orange, Green, Yellow, Purple, Brown, Cyan, Red,
     Magenta}
   , {"\!\(\*SubscriptBox[\(\[Theta]\), \(1\)]\) = 0.1\[Pi]"}
   , LegendFunction -> (Framed[#, RoundingRadius -> 4, 
       FrameStyle -> Black] &)]
 , Joined -> {False}
 , Frame -> True
 , FrameStyle -> Directive[Thick, Black, Bold, FontSize -> 15]
 , Axes -> False 
 , FrameLabel -> {"\!\(\*SubscriptBox[
StyleBox[\"\[Theta]\",\nFontSize->16], \(0\)]\)", "<W>"}
 , LabelStyle -> {Black, Bold, 15}
 , FrameTicks -> {{Automatic, 
    None}, {{0, {Pi/4, Pi "/4"}, {Pi/2, Pi "/2"}, {3*Pi/4, 3*Pi "/4"},
      Pi}, None}}]

The resulting plot is shown below enter image description here

As you can see from the plot, the vertical grid line is located at $0.3268350735\pi$. I want to put a label on the grid line using Callout. I want to use the Appearance->"Balloon". Then, I want to put it at the uppermost part of the frame and at the right side of the grid line, with the arrow tip pointing, of course, to the grid line. The label inside the gridline is $\theta_{0} = 0.3268350735\pi$. I can't figure out how to implement this. I hope someone could help me with this. Thanks!

$\endgroup$

2 Answers 2

3
$\begingroup$

Define a second dataset with a single element with a Callout wrapper with desired options, and set its style to None in ListPlot:

callout = Callout[{0.3268350735*Pi, 1.7}, 
   HoldForm[Subscript[θ, 0] == 0.3268350735 π], 
   Appearance -> "Balloon", 
   LeaderSize -> {40, 45 Degree, 40}, 
   LabelStyle -> 16];
ListPlot[{W11, {callout}}, 
 PlotStyle -> {Automatic, None}, 
 GridLines -> {{0.3268350735*Pi}, {0}}, 
 GridLinesStyle -> Directive[Thick, Gray], 
 Frame -> True]

enter image description here

where I used W11 from @rhermans's answer.

To place the label outside the frame, you need to add additional options (PlotRangeClipping, PlotRange, ImagePadding):

callout = Callout[{0.3268350735*Pi, 2.1}, 
   HoldForm[Subscript[θ, 0] == 0.3268350735 π], 
   Appearance -> "Balloon", LeaderSize -> {20, 45 Degree, 20}, 
   LabelStyle -> 16];
ListPlot[{W11, {callout}}, 
 PlotStyle -> {Automatic, None}, 
 GridLines -> {{0.3268350735*Pi}, {0}}, 
 GridLinesStyle -> Directive[Thick, Gray],
 Frame -> True, 
 ImageSize -> 500,
 PlotRange -> {0, 2.1},  
 PlotRangeClipping -> False, 
 ImagePadding -> {{Automatic, Automatic}, {Automatic, Scaled[.075]}}]

enter image description here

$\endgroup$
1
$\begingroup$
W11 = N@{Table[x, {x, 0, π, π/100}], 
     Sort@RandomReal[2, {101}]}\[Transpose];

putcallout[trace_, value_, label_String, position_] := 
 MapAt[Callout[#, label, position] &, trace, 
  Position[trace, First@Nearest[trace[[All, 1]], value]][[1, 1]]]

putcallout[W11, 0.3268350735*Pi,
  "\!\(\*SubscriptBox[\(θ\), \(0\)]\)=0.3268350735π", {0.5 \
π, 1.7}]

ListPlot[
 putcallout[W11, 0.3268350735*Pi, 
  "\!\(\*SubscriptBox[\(θ\), \(0\)]\)=0.3268350735π", {0.5 \
π, 1.7}]
 , ImageSize -> Scaled[0.5]
 , PlotLabel -> Style["α = 0.5", Bold, FontSize -> 15]
 , PlotStyle -> {{Blue}}
 , PlotRange -> Automatic
 , GridLines -> {{0.3268350735*Pi}, {0}}
 , GridLinesStyle -> Directive[Thick, Gray]
 , PlotLegends -> SwatchLegend[
   {Blue, Orange, Green, Yellow, Purple, Brown, Cyan, Red, Magenta}
   , {"\!\(\*SubscriptBox[\(θ\), \(1\)]\) = 0.1π"}
   , LegendFunction -> (Framed[#, RoundingRadius -> 4, 
       FrameStyle -> Black] &)
   ]
 , Joined -> {False}
 , Frame -> True
 , FrameStyle -> Directive[Thick, Black, Bold, FontSize -> 15]
 , Axes -> False
 , FrameLabel -> {"\!\(\*SubscriptBox[StyleBox[\"θ\",\n\
FontSize->16], \(0\)]\)", "<W>"}
 , LabelStyle -> {Black, Bold, 15}
 , FrameTicks -> {{Automatic, 
    None}, {{0, {Pi/4, Pi "/4"}, {Pi/2, Pi "/2"}, {3*Pi/4, 3*Pi "/4"},
      Pi}, None}}
 (*,Epilog\[Rule]{Point[ Callout[{0.3268350735*Pi,0},"www"]]}*)
 ]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.