我是 LyX 用户,我想在我的一篇论文中使用线图。这只是一条带有几个已识别点的线。对我来说,兴趣点是 24、32 和 38。您能告诉我实现此目的的最简单方法是什么吗?我听说过打包的 pgfplots,但我不知道如何使用它。对于我的情况来说,这似乎有点小题大做。
欢迎提出所有建议,提前致谢。
答案1
您可以将其用于tikz
如下的简单绘图:
如果你经常做这些类型的图形,那么将它们包装在一个宏中是有意义的,你可以在其中定义
#1
= 起始值,#2
= 最终值,并且#3
= 要标记的点的列表。
然后,
\DrawNumberLine{18}{42}{24,32,38}
\DrawNumberLine{0}{50}{24,32,38}
\DrawNumberLine{0}{25}{2,7,12,20,22}
产量:
代号:基础版
\documentclass{article}
\usepackage{tikz}
\tikzset{tick style/.style={thick, black}}
\begin{document}
\begin{tikzpicture}[scale=0.5]
\draw [thin, gray, -latex] (18,0) -- (42,0);
\foreach \Tick in {20,25,...,40} {
\draw [tick style] (\Tick,1.5ex) -- (\Tick,-1.5ex) node [below] {$\Tick$} ;
}
\foreach \X in {24, 32, 38} {
\draw [fill=red] (\X,0) circle (4pt) node [above, blue] {$\X$};
}
\end{tikzpicture}
\end{document}
代码:宏版本
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
%\usepackage{showframe}
\tikzset{number line style/.style={thin, gray, -latex}}
\tikzset{tick style/.style={thick, black}}
%% http://tex.stackexchange.com/questions/175507/scale-tikzpicture-to-enclosing-minipage
\newcommand*{\MyScale}{1}%
\newcommand*{\MyResizeBox}[2]{%
% #1 = width
% #2 = tikzpicture
\renewcommand*{\MyScale}{1}%
\sbox0{#2}%
\pgfmathsetmacro{\MyScale}{0.98*#1/\wd0}%
#2%
}%
\newcommand*{\TickStep}{5}
\newcommand*{\DrawNumberLine}[3]{%
% #1 = x min
% #2 = x max
% #3 = comma separated list of points to show
\MyResizeBox{\linewidth}{%
\noindent
\begin{tikzpicture}[x=\MyScale cm, y=1cm]
\draw [number line style] (#1,0) -- (#2,0);
\pgfmathtruncatemacro{\TickStart}{\TickStep*int(#1/\TickStep)}%
\pgfmathtruncatemacro{\TickEnd}{\TickStep*int(#2/\TickStep -1)}%
\pgfmathtruncatemacro{\NumOfTicks}{1+(\TickEnd-\TickStart)/\TickStep}%
\foreach \Tick in {1,...,\NumOfTicks} {
\pgfmathtruncatemacro{\CurrentTick}{\TickStart+\Tick*\TickStep}%
\draw [tick style] (\CurrentTick,0.5ex) -- (\CurrentTick,-0.5ex)
node [below] {\tiny$\CurrentTick$} ;
}
\foreach \X in {#3} {
\draw [fill=red] (\X,0) circle (2pt)
node [above, blue] {\tiny$\X$};
}
\end{tikzpicture}%
}%
}
\begin{document}
\DrawNumberLine{18}{42}{24,32,38}%
\medskip\par
\DrawNumberLine{0}{50}{24,32,38}%
\medskip\par
\DrawNumberLine{0}{25}{2,7,12,20,22}%
\end{document}