Advertisement
simonjtyler

Intervals-Belisarius

Jul 23rd, 2011
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. (* A small extension of the code by belisarius in *)
  2. (* http://stackoverflow.com/questions/6797651/plotting-a-number-line-in-mathematica/6797911#6797911 *)
  3.  
  4. intPlot[ss_, {s_, e_}, ee_] := intPlot[{{ss, {s, e}, ee}}]
  5. intPlot[ints : {{_String, {_?NumericQ, _?NumericQ}, _String}..}] :=
  6. With[{min = Min[ints[[All, 2, 1]]], max = Max[ints[[All, 2, 2]]]},
  7. Graphics[Table[
  8. With[{ss = int[[1]], s = int[[2, 1]], e = int[[2, 2]], ee = int[[3]]},
  9. {Red, Thickness[.01], Text[Style[ss, Large, Red, Bold], {s, 0}],
  10. Text[Style[ee, Large, Red, Bold], {e, 0}],
  11. Line[{{s, 0}, {e, 0}}]}], {int, ints}],
  12. Axes -> {True, False}, AxesStyle -> Directive[Thin, Blue, 12],
  13. PlotRange -> {{min - .2 Abs@(min - max), max + .2 Abs@(min - max)}, {0, 0}},
  14. AspectRatio -> .1]]
  15.  
  16. (* Examples *)
  17.  
  18. intPlot["[", {3, 4}, ")"]
  19. intPlot[{{"(", {1, 2}, ")"}, {"[", {3, 4}, ")"}}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement