如何在数轴上画一个开口圆?

如何在数轴上画一个开口圆?

这是一个后续问题标记数轴

我的问题是如何使用 Gonzalo Medina 的答案来制作一个开放圆(以表示开放间隔)。

答案1

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
  axis y line=none,
  axis lines=left,
  axis line style={-},
  xmin=112.5,
  xmax=121.5,
  ymin=0,
  ymax=1,
  xlabel=$\mu$,
  scatter/classes={
                    a={mark=*,draw=magenta,fill=white},
                    b={mark=*,red}
                    },
  restrict y to domain=0:1,
  xtick={113,114,...,121},
  point meta=explicit symbolic,
]
\addplot[scatter,blue,thick] table [y expr=0,meta index=1, header=false] {
114.06 a
119.94 b
};

\node[coordinate,label=above:{$L_1=114.06$}] at (axis cs:114.06,0.05) {};
\node[coordinate,label=above:{$L_2=119.94$}] at (axis cs:119.94,0.05) {};
\end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

并且相当普遍元帖子解决方案...

在此处输入图片描述

prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);

% open or closed ends?
boolean a_open, b_open;
a_open = true;
b_open = false;

% lower and upper values
a = 114.06;
b = 119.94;

% color for the interval
color interval_color;
interval_color = .47 red;

% limits for tick marks
alpha = floor(a)-1;
omega = ceiling(b)+1;

% horizontal & vertical units
u = 8cm/(omega-alpha);
v = 1cm;

% axis
drawarrow (-5mm,0) -- ((omega-alpha)*u+5mm,0) withcolor .3 white;
% with ticks and labels
for i=0 step ceiling(8mm/u) until omega-alpha:
  draw (origin -- (0,v/5)) shifted (i*u,0) withcolor .3 white;
  label(decimal (alpha+i), (i*u,-v/2));
  endfor

% lower and upper points on the line
z1 = ((a-alpha)*u,0);
z2 = ((b-alpha)*u,0);

% draw the interval
draw z1--z2 withpen pencircle scaled 1.6 withcolor interval_color;

% mark the ends
fill fullcircle scaled 4 shifted z1 withcolor interval_color;
if a_open: fill fullcircle scaled 3 shifted z1 withcolor background; fi

fill fullcircle scaled 4 shifted z2 withcolor interval_color;
if b_open: fill fullcircle scaled 3 shifted z2 withcolor background; fi

% labels (done like this to use the values already given for a and b)
write "label(btex $L_1=" & decimal a & "$ etex,z1+(0,2/3v));" to ".mplabels"; 
write "label(btex $L_2=" & decimal b & "$ etex,z2+(0,2/3v));" to ".mplabels"; 
write EOF to ".mplabels";
input .mplabels;

label(btex $\mu$ etex, .5[z1,z2]-(0,6/5v));

endfig;
end.

对于不同的下限和上限,这应该可以相当自动地工作,例如,只需更改这些行

% open or closed ends?
a_open = false;
b_open = true;

% lower and upper values
a = 57.2;
b = 73.1;

你得到

在此处输入图片描述

如果您有很多要绘制的图形,您可以vardef为它们创建一个类似的函数。

答案3

PSTricks 解决方案:

\documentclass{article}

\usepackage{pstricks-add}

\begin{document}

\def\beginning{113}
\def\first{114.06 }  %  left side of interval
\def\second{119.94 } % right side of interval
\begin{pspicture}(-0.5,-0.55)(8.5,0.5)
  \pnodes{P}%
    (!\first \beginning sub 0)%
    (!\second \beginning sub 0)
  \psaxes[yAxis = false, Ox = \beginning]{->}(0,0)(-0.5,0)(8.5,0)
  \psline[linewidth = 1.5pt, linecolor = blue](P0)(P1)
  \psdot[dotstyle = Bo](P0)
  \uput[90](P0){$L_{1} = \first$}
  \psdot(P1)
  \uput[90](P1){$L_{2} = \second$}
\end{pspicture}

\end{document}

输出

相关内容