我尝试在区间 [0, 1] 上绘制 2 个函数。其中一个函数可以运行,但我用于模拟数据的函数却不行。
\documentclass[8pt]{article}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{pgfplots}
\usetikzlibrary{chains,shapes.multipart}
\usetikzlibrary{shapes,calc}
\usetikzlibrary{automata,positioning}
\usetikzlibrary{patterns}
\usepackage[latin1]{inputenc}
\usepackage{verbatim}
\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}
\addplot[blue,domain=0:.95] {ln(1000000)/((1-x))};
\addplot[smooth,domain=0:.95]
(0.01,15.4936011731625) --
(0.05,16.1972063938156) --
(0.1,15.6307188495994) --
(0.15,15.8221184986178) --
(0.2,17.3298915610067) --
(0.35,28.2033991515636) --
(0.4,22.9307031580538) --
(0.45,24.6029702750966) --
(0.5,24.9720082713757) --
(0.55,28.3029688145034) --
(0.6,31.5953977632453) --
(0.65,33.9497355091153) --
(0.7,45.5851026929449) --
(0.75,56.294973153621) --
(0.8,63.6406904051546) --
(0.85,65.5148971946328) --
(0.9,117.04824508907) --
(0.95,174.020252958231) ;
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
答案1
您提供数据的格式错误:您可以使用\addplot [...] coordinates {(...) (...) (...)};
(坐标之间没有破折号),或者更好的是,使用以下格式提供数据表
\addplot [...] table {
x0 y0
x1 y1
x2 y2
};
请注意,当您绘制坐标或表格中的数据时,该domain
键不起作用,它仅适用于绘制函数时。
因此
\documentclass[8pt]{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[blue,domain=0:0.95] {ln(1000000)/((1-x))};
\addplot[smooth] coordinates {
(0.01,15.4936011731625)
(0.05,16.1972063938156)
(0.1,15.6307188495994)
(0.15,15.8221184986178)
(0.2,17.3298915610067)
(0.35,28.2033991515636)
(0.4,22.9307031580538)
(0.45,24.6029702750966)
(0.5,24.9720082713757)
(0.55,28.3029688145034)
(0.6,31.5953977632453)
(0.65,33.9497355091153)
(0.7,45.5851026929449)
(0.75,56.294973153621)
(0.8,63.6406904051546)
(0.85,65.5148971946328)
(0.9,117.04824508907)
(0.95,174.020252958231)
};
\end{axis}
\end{tikzpicture}
\end{document}
或者
\documentclass[8pt]{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[blue,domain=0:0.95] {ln(1000000)/((1-x))};
\addplot[smooth] table{
0.01 15.4936011731625
0.05 16.1972063938156
0.1 15.6307188495994
0.15 15.8221184986178
0.2 17.3298915610067
0.35 28.2033991515636
0.4 22.9307031580538
0.45 24.6029702750966
0.5 24.9720082713757
0.55 28.3029688145034
0.6 31.5953977632453
0.65 33.9497355091153
0.7 45.5851026929449
0.75 56.294973153621
0.8 63.6406904051546
0.85 65.5148971946328
0.9 117.04824508907
0.95 174.020252958231
};
\end{axis}
\end{tikzpicture}
\end{document}