This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!

Intervals-Belisarius

By: simonjtyler on Jul 23rd, 2011  |  syntax: None  |  size: 0.88 KB  |  views: 71  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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}, ")"}}]
clone this paste RAW Paste Data