5
$\begingroup$

I want to label a graph as shown in the attached image. I want the label on the line and parallel to the line that I am labeling, as it is shown in the image. Could you help me, please? Code:

LogLogPlot[{Exp[4]* x, Exp[10]*(x)}, {x, 1, 10^3}, Frame -> True, 
FrameLabel -> {x, y}]

enter image description here

$\endgroup$

1 Answer 1

13
$\begingroup$

You can use custom Arrowheads as the option setting for PlotStyle and post-process to replace Lines with Arrows:

arrowheads = Arrowheads[{{.5, .5, 
  Graphics[Text[Framed[Style[#, 16], Background -> White, FrameStyle -> None]]]}}]& /@
     {"W", "BLAH"};

LogLogPlot[{Exp[4]*x, Exp[10]*(x)}, {x, 1, 10^3}, Frame -> True, 
  PlotStyle -> arrowheads, FrameLabel -> {x, y}] /. Line -> Arrow

enter image description here

$\endgroup$
5
  • 3
    $\begingroup$ This is a very clever hack using Arrowheads like this. Nice job. It's not likely to get easier than this. $\endgroup$
    – march
    Jan 27 at 5:25
  • $\begingroup$ @kglr Thanks a lot. $\endgroup$
    – PoreyS
    Jan 27 at 5:27
  • $\begingroup$ Suppose, I need to label one line and no need to label the other line - How do I need to modify this code? $\endgroup$
    – PoreyS
    Jan 27 at 12:12
  • 1
    $\begingroup$ @PoreyS, PlotStyle -> {arrowheads[[1]], Arrowheads[{}]} labels the first line only. $\endgroup$
    – kglr
    Jan 27 at 13:30
  • $\begingroup$ @kglr Thanks a lot. $\endgroup$
    – PoreyS
    Jan 27 at 15:18

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.