为了绘制开区间或闭区间,你可以这样做:
intPlot[ss_, {s_, e_}, ee_] := Graphics[{Red, Thickness[.01],
Text[Style[ss, Large, Red, Bold], {s, 0}],
Text[Style[ee, Large, Red, Bold], {e, 0}],
Line[{{s, 0}, {e, 0}}]},
Axes -> {True, False},
AxesStyle -> Directive[Thin, Blue, 12],
PlotRange -> {{ s - .2 Abs@(s - e), e + .2 Abs@(s - e)}, {0, 0}},
AspectRatio -> .1]
intPlot["[", {3, 4}, ")"]
Edit
以下是 @Simon 所做的很好的扩展,可能被我再次尝试解决重叠间隔问题破坏了。
intPlot[ss_, {s_, e_}, ee_] := intPlot[{{ss, {s, e}, ee}}]
intPlot[ints : {{_String, {_?NumericQ, _?NumericQ}, _String} ..}] :=
Module[{i = -1, c = ColorData[3, "ColorList"]},
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]]},
{c[[++i + 1]], Thickness[.01],
Text[Style[ss, Large, c[[i + 1]], Bold], {s, i}],
Text[Style[ee, Large, c[[i + 1]], Bold], {e, i}],
Line[{{s, i}, {e, i}}]}], {int, ints}],
Axes -> {True, False},
AxesStyle -> Directive[Thin, Blue, 12],
PlotRange -> {{min - .2 Abs@(min - max), max + .2 Abs@(min - max)}, {0, ++i}},
AspectRatio -> .2]]]
(*Examples*)
intPlot["[", {3, 4}, ")"]
intPlot[{{"(", {1, 2}, ")"}, {"[", {1.5, 4}, ")"},
{"[", {2.5, 7}, ")"}, {"[", {1.5, 4}, ")"}}]