我想要的是:
- 在第一个图中:忽略数据文件的第一行
- 在第二个图中:在有限的 y 范围内显示图形(0:3.5)
我拥有的:
关于 1) 没有可行的解决方案和错误:
Package PGF Math Error: Could not parse input '5*10^8' as a floating point number, sorry. The unreadable part was near '*10^8'.. ...domain={1.21678749999999990E7}:{5*10^8}] t
对于 2),Dimension too large. \end{axis}
如果我省略“ymax”选项,我可以摆脱此错误消息,但我只想绘制此 y 范围内的数据。否则比例会太大,而且似乎我也需要限制读入数据?
一切都归结为restrict x to domain=<start>:<end>
但我似乎仍然存在一些语法错误?
编辑:啊。这就是混合 x 轴和 y 轴时发生的情况。(因此代码中提到的方法可能确实有效。)
\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.12}
\pgfplotstableread[col sep=space]{%
3.00000000000000000E5 2.01770954045417160E-2
1.21678749999999990E7 6.53843084045015650E-1
2.02879999999999990E7 9.34720793380564530E-1
4.02759999999999960E7 9.30338681065119390E-1
6.02639999999999980E7 5.36647938885778150E-1
7.08826249999999900E7 3.04803797644972230E-1
8.02519999999999990E7 9.33974811366713990E-2
9.02460000000000130E7 1.32431168793329920E-1
1.00240000000000000E8 3.54244688254279620E-1
1.10233999999999990E8 5.56734207627991040E-1
1.20228000000000000E8 7.89192714838333220E-1
1.30222000000000020E8 9.96160077734732850E-1
1.40216000000000010E8 1.23583766580312780E0
1.50209999999999980E8 1.46258850812222540E0
1.60204000000000010E8 1.69992167155321970E0
1.70198000000000000E8 1.95123830485607840E0
1.80192000000000020E8 2.22623159795794030E0
1.90185999999999990E8 2.50805235677870940E0
2.00180000000000020E8 2.77839855801785560E0
2.03303124999999960E8 2.90467776154555810E0
2.18294124999999980E8 3.50255734987308460E0
2.30786625000000000E8 4.00071696691821100E0
2.49525374999999980E8 5.01045376157417350E0
2.97621500000000030E8 1.00071861346771680E1
3.17609500000000010E8 1.52144470748861930E1
3.51339250000000060E8 5.11315529444377590E1
3.65705625000000010E8 5.64439690499664070E2
3.68204124999999970E8 6.46670133059780470E2
3.73825749999999960E8 1.28837192967264010E2
3.94438375000000010E8 3.14628301208824810E1
4.60024000000000030E8 1.02387484129196960E1
5.00000000000000000E8 7.99406030727084270E0
}\datat
\pgfplotstableread[col sep=space]{%
3.00000000000000000E5 1.00404355551509550E-7
1.54925000000000020E6 1.36824493432681880E-7
1.21678749999999990E7 1.43033737315883540E-7
2.02879999999999990E7 1.44632961165595790E-7
4.02759999999999960E7 1.39406177062964030E-7
6.02639999999999980E7 1.36487519163806460E-7
7.02580000000000120E7 1.35779692017299450E-7
8.02519999999999990E7 1.34017193632160230E-7
9.02460000000000130E7 1.31860433859521780E-7
1.00240000000000000E8 1.29120627287948260E-7
1.10233999999999990E8 1.24526497804674220E-7
1.20228000000000000E8 1.19549452160883240E-7
1.30222000000000020E8 1.13171593160961900E-7
1.40216000000000010E8 1.04087039044147180E-7
1.50209999999999980E8 9.25617857567434400E-8
1.50834625000000020E8 9.17023108625545370E-8
1.60204000000000010E8 7.94831770727646350E-8
1.70198000000000000E8 6.30136807536853190E-8
1.80192000000000020E8 4.66571908839113720E-8
1.90185999999999990E8 2.73887584234017910E-8
2.00180000000000020E8 7.56282270904724550E-9
2.03303124999999960E8 1.44238994938850200E-9
2.18294124999999980E8 nan
2.30786625000000000E8 nan
2.49525374999999980E8 nan
2.97621500000000030E8 nan
3.17609500000000010E8 nan
3.51339250000000060E8 nan
3.65705625000000010E8 nan
3.68204124999999970E8 nan
3.73825749999999960E8 nan
3.94438375000000010E8 nan
4.60024000000000030E8 nan
5.00000000000000000E8 nan
}\datav
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
height=5cm,
width=5cm,
no markers,
% ymin=0,
% ymax=3.5*10^-7,
% xmin=.1*10^8,
% xmax={5*10^8},
]
% \addplot +[restrict x to domain=0.1*10^8:5*10^8] table [col sep=space] from \data; % does not work
% \addplot +[restrict x to domain={0.1*10^8}:{5*10^8}] table [col sep=space] from \data; % does not work
% \addplot +[restrict x to domain={1.21678749999999990E7}:{5*10^8}] table [col sep=space] from \data; % does not work
% \addplot +[restrict expr to domain={1.21678749999999990E7}:{5*10^8}] table [col sep=space] from \data; % does not work
\addplot +[] table [col sep=space]from \datav; % with the notch at the beginning
\end{axis}
\end{tikzpicture} \hspace{5mm} \begin{tikzpicture}
\begin{axis}[%
height=5cm,
width=5cm,
no markers,
ymin=0,
ymax=3.5,
]
\addplot +[] table [col sep=space]from \datat;
\end{axis}
\end{tikzpicture}
\end{document}
看起来像这样:
(图 1 中仍有缺口,并且出现错误信息“尺寸对于图 2 来说太大”)
答案1
对于第一个图,问题只是错误的数字符号(从 更改5*10^8
为正确5e8
等等):
\begin{tikzpicture}
\begin{axis}[%
height=5cm,
width=5cm,
no markers,
xmin=.1e8,
xmax=5e8,
]
\addplot+ table [col sep=space] from \datav;
\end{axis}
\end{tikzpicture}
请注意,如果您在命令中直接从文件读取数据addplot table
,则可以使用skip first n=1
忽略第一行,但如果表中装有pgfplotstableread
。
什么做工作是@Fritz 的解决方案所以你可以在序言中添加
% Style to select only points from #1 to #2 (inclusive)
\pgfplotsset{select coords between index/.style 2 args={
x filter/.code={
\ifnum\coordindex<#1\def\pgfmathresult{}\fi
\ifnum\coordindex>#2\def\pgfmathresult{}\fi
}
}}
进而
\addplot+ table [col sep=space, select coords between index={1}{1000}] from \datav;
(我认为这会产生稍微好一点的输出)。
对于第二个,问题在于,当缩放到新的 yrange 时,值在 600 左右的点超出了 TeX 的尺寸容量。可能有更好的方法,但一个快速而快捷的选择是
\begin{tikzpicture}
\begin{axis}[%
height=5cm,
width=5cm,
no markers,
ymin=0,
ymax=3.5,
]
\addplot +[restrict y to domain=0:3.5] table [col sep=space] from \datat;
\end{axis}
\end{tikzpicture}
结果是(使用第一个图表的简单方法,限制轴):
或(与 Fritz 的select coords between index
):