9
$\begingroup$

Consider the following plot:

Show[LogLogPlot[{x, x^2, x^1.5, 5/x}, {x, 0.5, 3}, 
  PlotRange -> {{0.5, 3}, {0.5, 10}}, Frame -> True, 
  FrameStyle -> Directive[Black, 25],
  PlotStyle -> {{Thick, Blue}, {Thick, Red}, {Thick, 
     Darker@Darker@Green}, {Thick, Blue}, {Thick, Blue, 
     Dashing[0.02]}, {Thick, Darker@Darker@Green, Dashing[0.02]}}, 
  ImageSize -> Large, FrameLabel -> {"x", "f(x)"}, 
  PlotLegends -> 
   Placed[{Style["Curve 1", 21], Style["Curve 2", 21], 
     Style["Curve 3", 21]}, {0.83, 0.15}], 
  Filling -> {1 -> {{4}, Directive[Blue, Opacity[0.1]]}, 
    4 -> {Top, Directive[Gray, Opacity[0.1]]}, 
    5 -> {Top, Directive[Gray, Opacity[0.1]]}}], 
 Graphics[{Text[Style["Domain 1", 20, Darker@Blue], 
    Scaled[{0.3, 0.5}]], 
   Text[Style["Domain 2", 22, Darker@Blue], Scaled[{0.7, 0.7}]]}]]

The result is

enter image description here

Could you please tell me how to rotate the legend "Domain 2" to make it collinear to the blue line?

P.S. Without the deformation of the text.

$\endgroup$
3
  • 3
    $\begingroup$ Rotate[Text[Style["Domain 2", 22, Darker@Blue], Scaled[{0.45, 0.8}]], -45 Degree] $\endgroup$
    – Bob Hanlon
    May 25, 2020 at 22:15
  • 2
    $\begingroup$ @BobHanlon : unfortunately the rotated text is deformed (this seems to be due to LogLog scaling). $\endgroup$ May 25, 2020 at 22:40
  • 2
    $\begingroup$ how about Text[Style["Domain 2", 22, Darker@Blue], Scaled[{0.5, 0.75}], Left, {3, -1}]? $\endgroup$
    – kglr
    May 25, 2020 at 22:54

3 Answers 3

2
$\begingroup$

1. You can use the fourth argument of Text to control the direction of text:

LogLogPlot[{x, x^2, x^1.5, 5/x}, {x, 0.5, 3}, 
 PlotRange -> {{0.5, 3}, {0.5, 10}}, Frame -> True, 
 FrameStyle -> Directive[Black, 25], 
 PlotStyle -> {{Thick, Blue}, {Thick,Red}, {Thick, Darker@Darker@Green}, {Thick, Blue}},
 ImageSize -> Large, FrameLabel -> {"x", "f(x)"}, 
 PlotLegends -> Placed[{Style["Curve 1", 21], Style["Curve 2", 21], 
    Style["Curve 3", 21]}, {0.83, 0.15}], 
 Filling -> {1 -> {{4}, Directive[Blue, Opacity[0.1]]}, 
   4 -> {Top, Directive[Gray, Opacity[0.1]]}}, 
 Epilog -> {Text[Style["Domain 1", 20, Darker@Blue], Scaled[{0.3, 0.5}]], 
   Text[Style["Domain 2", 22, Darker@Blue], Scaled[{0.5, 0.75}], Center, {3, -1}]}]

enter image description here

2. You can have the text orientation determined by the curve it is associated with using a custom arrowhead:

LogLogPlot[{x, x^2, x^1.5, 5/x}, {x, 0.5, 3}, 
  PlotRange -> {{0.5, 3}, {0.5, 10}}, Frame -> True, 
  FrameStyle -> Directive[Black, 25], 
  BaseStyle -> Arrowheads[0], 
  PlotStyle -> {{Thick, Blue}, {Thick, Red}, {Thick, Darker @ Darker @ Green}, 
     {Thick, Blue, Arrowheads[{{Automatic, .5, 
       Graphics[Text[Style["Domain 2", 22, Darker@Blue], {0, 0}, {0, -1}]]}}]}}, 
  ImageSize -> Large, FrameLabel -> {"x", "f(x)"}, 
  PlotLegends -> Placed[{Style["Curve 1", 21], Style["Curve 2", 21], 
     Style["Curve 3", 21]}, {0.83, 0.15}], 
  Filling -> {1 -> {{4}, Directive[Blue, Opacity[0.1]]}, 
    4 -> {Top, Directive[Gray, Opacity[0.1]]}}, 
  Epilog -> {Text[Style["Domain 1", 20, Darker@Blue], Scaled[{0.3, 0.5}]]}] /. 
  Line -> Arrow

enter image description here

$\endgroup$
11
$\begingroup$
LogLogPlot[{x, x^2, x^1.5, 5/x}, {x, 0.5, 3},
 PlotRange -> {{0.5, 3}, {0.5, 10}},
 Frame -> True,
 FrameStyle -> Directive[Black, 25],
 PlotStyle -> {
   {Thick, Blue},
   {Thick, Red},
   {Thick, Darker@Darker@Green},
   {Thick, Blue},
   {Thick, Blue, Dashing[0.02]},
   {Thick, Darker@Darker@Green, Dashing[0.02]}},
 ImageSize -> Large,
 FrameLabel -> {"x", "f(x)"},
 PlotLegends -> Placed[{Style["Curve 1", 21], Style["Curve 2", 21],
    Style["Curve 3", 21]}, {0.83, 0.15}],
 Filling -> {1 -> {{4}, Directive[Blue, Opacity[0.1]]},
   4 -> {Top, Directive[Gray, Opacity[0.1]]},
   5 -> {Top, Directive[Gray, Opacity[0.1]]}},
 Epilog -> {Text[Style["Domain 1", 20, Darker@Blue], 
    Scaled[{0.3, 0.5}]],
   Inset[
    Graphics[
     Rotate[
      Text[Style["Domain 2", 22, Darker@Blue], Scaled[{0.45, 0.8}]],
      -20 Degree]],
    Scaled[{0.5, 0.6}]]}]

enter image description here

$\endgroup$
6
$\begingroup$

In case you are not aware, it is possible to interactively edit the plot output which is often the fastest way for a one-off solution.

If you hover over "Domain 2" in the output and double click you should see an editing frame:

enter image description here

Use the handles to rotate and position the label:

enter image description here

Then click outside the graphic and the edit is saved:

enter image description here

$\endgroup$
2
  • $\begingroup$ Can you clarify how to pull the “FullForm” of the resulting figure when one makes modifications in this manner? $\endgroup$ May 28, 2020 at 15:07
  • 1
    $\begingroup$ @CATrevillian You can wrap the resulting graphic object in FullForm (or InputForm) and evaluate the cell; Graphics is handled as a normal expression since Mathematica version 6.0. $\endgroup$
    – Mr.Wizard
    May 29, 2020 at 14:05

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.