更改 pgfpltots 中的 y 轴限制

更改 pgfpltots 中的 y 轴限制

我不确定为什么我的图表没有从 \filecontents data.csv 文件中获取数据,但我想将 y 轴的比例从 0 更改为 .005。

感谢您的帮助。

这是我的代码:

\documentclass[11pt]{book}
\usepackage[top=3cm,bottom=3cm,left=3.2cm,right=3.2cm,headsep=10pt,a4paper]{geometry}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{float}
\usepackage{pgfplots,pgfplotstable, booktabs}
\usetikzlibrary{pgfplots.groupplots, matrix}
\pgfplotsset{compat=1.10, title/.append style={align =center}}

\begin{filecontents*}{data.csv}
  Iter  abs11  abs21  abs12  abs22
     1, 0.0016930, 0.0007109, 0.0169301, 0.0071087
     2, 0.0004656, 0.0006430, 0.0046563, 0.0064301
     3, 0.0001496, 0.0010624, 0.0014964, 0.0106239
     4, 0.0000946, 0.0006596, 0.0009458, 0.0065962
     5, 0.0000274, 0.0002370, 0.0002737, 0.0023697
     6, 0.0000388, 0.0001168, 0.0003882, 0.0011681
     7, 0.0000232, 0.0001592, 0.0002324, 0.0015921
     8, 0.0000073, 0.0001997, 0.0000728, 0.0019965
     9, 0.0001358, 0.0002963, 0.0013578, 0.0029635
    10, 0.0000410, 0.0002793, 0.0004099, 0.0027925
\end{filecontents*}

\pgfplotsset{minor grid style={dashed,red}}
\pgfplotsset{major grid style={dotted,green!50!black}}

\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{groupplot}[group style={
  group size= 1  by 2,
  vertical sep=2cm,
  horizontal sep = 2cm,
  ylabels at=edge left,group name=ape},
  width=15cm,
  height=8cm,
  try min ticks=5,
  ]
\nextgroupplot[align =center, 
title={\textbf{\emph{(a) RSLE Absolute Errors with $\mathbf{N(0,0.001^{2})}$}}}, 
grid=both, every major grid/.style={gray, opacity=0.5}
]

\addplot [only marks,mark=*,red,mark options={scale=.65}]table[x index=0,y index=1,col sep=comma, green, only marks] {data.csv};\label{plots:plot1}
\addplot [only marks,mark=*,blue,mark options={scale=.65}]table[x index=0,y index=2,col sep=comma, green, only marks] {data.csv};\label{plots:plot2}
\coordinate (top) at (rel axis cs:0,1);

\nextgroupplot[title = {\textbf{\emph{(b) RSLE Absolute Errors with $\mathbf{N(0,0.01^{2})}$}}},grid=both, every major grid/.style={gray, opacity=0.5}]
\addplot [only marks,mark=*,red,mark options={scale=.65}]table[x index=0,y index=3,col sep=comma, green, only marks] {data.csv};\label{plots:plot3}
\addplot [only marks,mark=*,blue,mark options={scale=.65}]table[x index=0,y index=4,col sep=comma, green, only marks] {data.csv};
\coordinate (bot) at (rel axis cs:1,0);
\end{groupplot}

\path (top-|current bounding box.west)--
  node[anchor=south,rotate=90] {\large{\bf{Absolute Parameter Error ($\mid$Estimated - Actual$\mid$})}}
  (bot-|current bounding box.west);
% legend
\path (top|-current bounding box.north)--
  coordinate(legendpos)
  (bot|-current bounding box.north);
\matrix[
matrix of nodes,
anchor=south,
draw,
inner sep=0.2em,
draw
  ]at([yshift=1ex]legendpos)
  {
\ref{plots:plot1}& $\delta r_{2}$ &[5pt]
\ref{plots:plot2}& $\delta r_{3}$ &[5pt]\\};
\end{tikzpicture}
\caption[Plot showing Absolute Errors with noise with parameters for RLSE.]{Plot showing RLSE Absolute Errors with noise with parameters (a) $N(0,0.001^{2})$ and (b) $N(0,0.001^{2})$.}\label{abserror}
\end{figure}

\end{document} 

答案1

从问题中看不太清楚,但问题原来是data.csv同一目录中的另一个文件。在这种情况下,会发出警告并使用旧文件:

LaTeX Warning: File `data.csv' already exists on the system.
Not generating it from this source.

要按您想要的方式格式化数字,您可以写入\pgfkeys{/pgf/number format/.cd,fixed,precision=3},并为了避免缩放所有刻度,使用 pgfplots 选项scaling ticks=false

\usepackage{pgfplots,pgfplotstable, booktabs}
\usetikzlibrary{pgfplots.groupplots, matrix}
\pgfplotsset{compat=1.10, title/.append style={align =center}}
\pgfkeys{/pgf/number format/.cd,fixed,precision=3}

\begin{filecontents*}{data.csv}
  Iter  abs11  abs21  abs12  abs22
     1, 0.0016930, 0.0007109, 0.0169301, 0.0071087
     2, 0.0004656, 0.0006430, 0.0046563, 0.0064301
     3, 0.0001496, 0.0010624, 0.0014964, 0.0106239
     4, 0.0000946, 0.0006596, 0.0009458, 0.0065962
     5, 0.0000274, 0.0002370, 0.0002737, 0.0023697
     6, 0.0000388, 0.0001168, 0.0003882, 0.0011681
     7, 0.0000232, 0.0001592, 0.0002324, 0.0015921
     8, 0.0000073, 0.0001997, 0.0000728, 0.0019965
     9, 0.0001358, 0.0002963, 0.0013578, 0.0029635
    10, 0.0000410, 0.0002793, 0.0004099, 0.0027925
\end{filecontents*}

\pgfplotsset{minor grid style={dashed,red}}
\pgfplotsset{major grid style={dotted,green!50!black}}

\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{groupplot}[group style={
  group size= 1  by 2,
  vertical sep=2cm,
  horizontal sep = 2cm,
  ylabels at=edge left,group name=ape},
  width=15cm,
  height=8cm,
  try min ticks=5,
  scaled ticks=false,
  ]
\nextgroupplot[align =center, 
title={\textbf{\emph{(a) RSLE Absolute Errors with $\mathbf{N(0,0.001^{2})}$}}}, 
grid=both, every major grid/.style={gray, opacity=0.5}
]

\addplot [only marks,mark=*,red,mark options={scale=.65}]table[x    index=0,y index=1,col sep=comma, green, only marks]    {data.csv};\label{plots:plot1}
\addplot [only marks,mark=*,blue,mark options={scale=.65}]table[x index=0,y index=2,col sep=comma, green, only marks] {data.csv};\label{plots:plot2}
\coordinate (top) at (rel axis cs:0,1);

\nextgroupplot[title = {\textbf{\emph{(b) RSLE Absolute Errors with $\mathbf{N(0,0.01^{2})}$}}},grid=both, every major grid/.style={gray, opacity=0.5}]
\addplot [only marks,mark=*,red,mark options={scale=.65}]table[x index=0,y index=3,col sep=comma, green, only marks] {data.csv};\label{plots:plot3}
\addplot [only marks,mark=*,blue,mark options={scale=.65}]table[x index=0,y index=4,col sep=comma, green, only marks] {data.csv};
\coordinate (bot) at (rel axis cs:1,0);
\end{groupplot}

\path (top-|current bounding box.west)--
  node[anchor=south,rotate=90] {\large{\bf{Absolute Parameter Error ($\mid$Estimated - Actual$\mid$})}}
  (bot-|current bounding box.west);
% legend
\path (top|-current bounding box.north)--
  coordinate(legendpos)
  (bot|-current bounding box.north);
\matrix[
matrix of nodes,
anchor=south,
draw,
inner sep=0.2em,
draw
  ]at([yshift=1ex]legendpos)
  {
\ref{plots:plot1}& $\delta r_{2}$ &[5pt]
\ref{plots:plot2}& $\delta r_{3}$ &[5pt]\\};
\end{tikzpicture}
\caption[Plot showing Absolute Errors with noise with parameters for RLSE.]{Plot showing RLSE Absolute Errors with noise with parameters (a) $N(0,0.001^{2})$ and (b) $N(0,0.001^{2})$.}\label{abserror}
\end{figure}

\end{document}

相关内容