latex 中 x 轴和 y 轴的格式问题

latex 中 x 轴和 y 轴的格式问题

我有一个 latex 代码,用于从文本文件生成图形。文本文件的内容如下:

0.01    0.119693    48.43196
0.02    0.1310796   6214.208
0.03    0.1289268   12973.42
0.04    0.1286408   17064.04
0.05    0.128663    19556.76
0.06    0.1289252   21224.36
0.07    0.1283098   22407.22

这是乳胶代码:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=6cm,compat=newest}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    scale only axis,
    xlabel={$Applied\; Load\;(packets\;per\;cycle\;per\;node) $},
    xtick={0.01,0.02,0.03,0.04,0.05,0.06,0.07},
    ylabel={$Throughput\;(in\;flits\;per\;cycles)$},
    ytick={0,0.05,0.1,0.15},
    legend style={font=\small,at={(0.5,0.96)},anchor=north,style={nodes={right}}},
    legend pos=outer north east,
    legend cell align=left,
]
\addplot[color=red,mark=*, mark options={fill=red}]
    table[x index=0,y index=1] {DOR_data.txt};

    \legend{DOR}

\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[
    scale only axis,
    xlabel={$Applied\; Load\;(packets\;per\;cycle\;per\;node) $},
    xtick={0.01,0.02,0.03,0.04,0.05,0.06,0.07},
    ylabel={$Delay\;(in\;cycles)$},
    ytick={0,1000,5000,10000,15000,20000},
    legend style={font=\small,at={(0.5,0.96)},anchor=north,style={nodes={right}}},
    legend pos=outer north east,
    legend cell align=left,
]
\addplot[color=red,mark=*, mark options={fill=red}]
    table[x index=0,y index=2] {DOR_data.txt};


    \legend{DOR}

\end{axis}
\end{tikzpicture}

\end{document}

图表结果如下:

在此处输入图片描述

现在有两个问题:

  1. 左侧图表上没有 y 轴指针。
  2. 在 x 轴上,10^(-2) 与 x 标签重叠。我希望它们显示为 0.01、0.02 等。

之前我曾用过相同的代码。这很奇怪。

答案1

例如,您需要添加,ytick={0.12,0.125,0.13}因为您的数据范围不同。然后您也可以自定义标签。添加scaled ticks=false,会删除 $10^{-2}$,然后使用xticklabels您可以将其命名为 0.01、0.02 等等。以下是图 1 的示例

\begin{tikzpicture}
 \begin{axis}[
  scale only axis,
  xlabel={\textit{Applied Load (packets per cycle per node)}},
  xtick={0.01,0.02,0.03,0.04,0.05,0.06,0.07},
  xticklabels={0.01,0.02,0.03,0.04,0.05,0.06,0.07},
  ylabel={\textit{Throughput (in flits per cycles)}},
  scaled ticks=false,
  ytick={0.12,0.125,0.13},
  yticklabels={0.12,0.125,0.13},
  legend style={font=\small,at={(0.5,0.96)},anchor=north,style={nodes= {right}}}, 
  legend pos=outer north east,
  legend cell align=left,
  ]
  \addplot[color=red,mark=*, mark options={fill=red}]
  table[x index=0,y index=1] {data1.dat};
 \legend{DOR}

 \end{axis}
\end{tikzpicture}

在此处输入图片描述

相关内容