两个图不相等,第二个图画在 x 轴上方?

两个图不相等,第二个图画在 x 轴上方?

我使用以下代码为两个数据集创建了图表。

  \begin{filecontents*}{data3.csv}
Test Hard      Soft 
a 25.12221  26.34338
b 23.55208  23.55208
c 17.74874  26.8047
d 18.47252  28.57218
e 21.07144  34.25253
\end{filecontents*}

\begin{filecontents*}{data4.csv}
Test Hard       Soft    
a 199.92098  150.91825
b 286.99305  286.99305
c 1091.95897    135.708
d 924.3317   90.336168
e 508.0838   24.424587
\end{filecontents*}

\begin{tikzpicture}[]
\begin{axis}[ybar,xmajorgrids=false,xtick={1,2,3,4,5},xticklabels={a,b,c,d,e},typeset ticklabels with strut , title = {PSNR value change}]
    \addplot[draw=none,fill=red] table[col sep=space, x expr={\coordindex+1}, y expr=\thisrow{Hard}] {data3.csv};
    \addplot[draw=none,fill=blue!75] table[col sep=space, x expr={\coordindex+1}, y expr=\thisrow{Soft}] {data3.csv};
    \legend{Hard,Soft}
\end{axis}
\end{tikzpicture}   
\hspace{0.5em}% NO SPACE!
\begin{tikzpicture}[]
\begin{axis}[ybar,xmajorgrids=false,xtick={1,2,3,4,5},xticklabels={a,b,c,d,e},typeset ticklabels with strut , title = {MSE value change}]
    \addplot[draw=none,fill=red] table[col sep=space, x expr={\coordindex+1}, y expr=\thisrow{Hard}] {data4.csv};
    \addplot[draw=none,fill=blue!75] table[col sep=space, x expr={\coordindex+1}, y expr=\thisrow{Soft}] {data4.csv};
    \legend{Hard,Soft}
\end{axis}
\end{tikzpicture} 

但第二张图在 X 轴上方绘制。这是我的输出。需要专家帮助来解决这个问题

在此处输入图片描述

答案1

您可以通过添加使它们的外观变得相同ymin=0

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}

\begin{filecontents*}{data3.csv}
Test Hard      Soft 
a 25.12221  26.34338
b 23.55208  23.55208
c 17.74874  26.8047
d 18.47252  28.57218
e 21.07144  34.25253
\end{filecontents*}

\begin{filecontents*}{data4.csv}
Test Hard       Soft    
a 199.92098  150.91825
b 286.99305  286.99305
c 1091.95897    135.708
d 924.3317   90.336168
e 508.0838   24.424587
\end{filecontents*}

\begin{document}

\begin{tikzpicture}[]
\begin{axis}[ybar,xmajorgrids=false,xtick={1,2,3,4,5},xticklabels={a,b,c,d,e},typeset
ticklabels with strut , title = {PSNR value change},ymin=0]
    \addplot[draw=none,fill=red] table[col sep=space, x expr={\coordindex+1}, y expr=\thisrow{Hard}] {data3.csv};
    \addplot[draw=none,fill=blue!75] table[col sep=space, x expr={\coordindex+1}, y expr=\thisrow{Soft}] {data3.csv};
    \legend{Hard,Soft}
\end{axis}
\end{tikzpicture}   
\hspace{0.5em}% NO SPACE!
\begin{tikzpicture}[]
\begin{axis}[ybar,xmajorgrids=false,xtick={1,2,3,4,5},xticklabels={a,b,c,d,e},typeset
ticklabels with strut ,ymin=0, title = {MSE value change}]
    \addplot[draw=none,fill=red] table[col sep=space, x expr={\coordindex+1}, y expr=\thisrow{Hard}] {data4.csv};
    \addplot[draw=none,fill=blue!75] table[col sep=space, x expr={\coordindex+1}, y expr=\thisrow{Soft}] {data4.csv};
    \legend{Hard,Soft}
\end{axis}
\end{tikzpicture} 
\end{document}

在此处输入图片描述

相关内容