Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wrote a little function to add lines with labels to plots. It just creates customized {GridLines -> ..., Epilog -> ...} code:

LastOrEmpty[seq_] := If[Length[seq] > 0, Last[seq], {}];

AddLabel[lab_, pos_] := 
  Inset[Framed[lab, Background -> White, FrameStyle -> None], pos];

AddLines[xs_, ys_, xlvl_, ylvl_] := {
   GridLines -> {LastOrEmpty /@ xs, LastOrEmpty /@ ys},
   Epilog -> Join[
     Table[AddLabel[xs[[i, 1]], {xs[[i, 2]], ylvl}], {i, Length[xs]}],
     Table[AddLabel[ys[[i, 1]], {xlvl, ys[[i, 2]]}], {i, Length[ys]}]
     ] 
   };

But is using a little creepy syntax:

AddLines[
  {label1 -> val1, label2 -> val2, ...}, (* <- vertical lines *)
  {label3 -> val3, label4 -> val4, ...}, (* <- horizontal lines *)
  xlvl, (* <- Horisontal align of labels*)
  ylvl  (* <- Vertical align of labels*)
] // Evaluate

For example:

ParametricPlot[{x1[w], 
   x3[w]}, {w, w1 - 5, w1 + 9},
  AspectRatio -> 1/GoldenRatio,
  AxesOrigin -> {0.10, 0},
  AxesLabel -> {"x1(\[Omega])", "x3(\[Omega])"},
  GridLinesStyle -> Dashed,
  AddLines[
    {T1 -> 0.2},
    {K1 -> 2, Kgr -> 0.52, Baseline -> 1},
    0.59, 2.9] // Evaluate
  ]

enter image description here

Now I would like to write something like:

  Lines -> {
    {T1 -> 0.2},
    {K1 -> 2, Kgr -> 0.52, Baseline -> 1},
    0.59, 2.9}

And at the best I would like to make it to automatically calculate align, i.e. would look like:

  Lines -> {
    {T1 -> 0.2},
    {K1 -> 2, Kgr -> 0.52, Baseline -> 1}}

Have you any idea how to make it?

share|improve this question
up vote 4 down vote accepted

For example, without modifying your current definitions you can do:

SetAttributes[myPlot, HoldAll];
Options[myPlot] = Join[Options[ParametricPlot], {"Lines" -> ""}];

myPlot[funs_, r_, opts : OptionsPattern[]] :=
    ParametricPlot[funs, r, 
      (Evaluate@Join[FilterRules[{opts}, Options[ParametricPlot]],
                     AddLines[Sequence @@ OptionValue[myPlot, "Lines"]]])];

myPlot[{w, 5 w}, {w, 0, .6}, 
       AspectRatio -> 1/GoldenRatio, AxesOrigin -> {0.10, 0}, 
       AxesLabel -> {"x1(\[Omega])", "x3(\[Omega])"}, GridLinesStyle -> Dashed, 
       "Lines" -> {{T1 -> 0.2}, {K1 -> 2, Kgr -> 0.52, Baseline -> 1}, 0.59, 2.9}]

Mathematica graphics

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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