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