切割钢筋组之间的间隙

切割钢筋组之间的间隙

有人知道我怎样才能使条形图组靠得更近吗?当我注释掉它时,enlarge x limits={abs=0.1}图表的大小是正确的,但条形图相距太远,而当我添加它时,条形图会靠得更近,但图表太小/并非所有东西都适合图表。

\begin{figure}
   \centering
\makeatletter
\pgfplotsset{
    calculate offset/.code={
        \pgfkeys{/pgf/fpu=true,/pgf/fpu/output format=fixed}
        \pgfmathsetmacro\testmacro{(\pgfplotspointmeta *10^\pgfplots@data@scale@trafo@EXPONENT@y)*\pgfplots@y@veclength)}
        \pgfkeys{/pgf/fpu=false}
    },
    every node near coord/.style={
        /pgfplots/calculate offset,
        yshift=-\testmacro
    }
}
% gating 1, 2, 3
\pgfplotstableread{
% Q S U
1 1219 937 2547
2 2576 3578 2387
3 1424 462 158
}\dataset
\begin{tikzpicture}
\begin{axis}[ybar,
        bar width=20pt,
        enlarge x limits={abs=0.1}    
        width=14cm,
        height=6cm,
        ymin=0,
        ymax=4000,        
        ylabel={frequency},
        xtick=data,
        xticklabels = {
            Gating1,
            Gating2,
            Gating3,
        },
    %    enlarge x limits={abs=1}    
        xlabel=Stimuli Condition,
        xlabel style={yshift=-10ex},
        xticklabel style={yshift=-10ex},
        major x tick style = {opacity=0},
        minor x tick num = 1,
        minor tick length=1ex,
        every node near coord/.append style={
                anchor=east,
                rotate=90
        }
        ]

\addplot[draw=black,fill=blue!20, nodes near coords=Question] table[x index=0,y index=1] \dataset;
\addplot[draw=black,fill=red!20, nodes near coords=Statement] table[x index=0,y index=2] \dataset;
\addplot[draw=black,fill=green!20, nodes near coords=Uncertain] table[x index=0,y index=3] \dataset;

\end{axis}
\end{tikzpicture}
\caption{Frequency and Proportion of Responses by Utterance Type and Gating Condition}\label{graph Frequency and Proportion of Responses by Utterance Type and Gating Condition}

\end{figure}

答案1

只是改变

enlarge x limits={abs=0.1} 

例如

enlarge x limits={abs=0.7},

我还在其中添加了一个逗号以使代码运行起来。

\documentclass{article} 
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}
\begin{figure}
   \centering
\makeatletter
\pgfplotsset{
    calculate offset/.code={
        \pgfkeys{/pgf/fpu=true,/pgf/fpu/output format=fixed}
        \pgfmathsetmacro\testmacro{(\pgfplotspointmeta *10^\pgfplots@data@scale@trafo@EXPONENT@y)*\pgfplots@y@veclength)}
        \pgfkeys{/pgf/fpu=false}
    },
    every node near coord/.style={
        /pgfplots/calculate offset,
        yshift=-\testmacro
    }
}
% gating 1, 2, 3
\pgfplotstableread{
% Q S U
1 1219 937 2547
2 2576 3578 2387
3 1424 462 158
}\dataset
\begin{tikzpicture}
\begin{axis}[ybar,
        bar width=20pt,
        enlarge x limits={abs=0.7}, 
        width=12cm,
        height=6cm,
        ymin=0,
        ymax=4000,        
        ylabel={frequency},
        xtick=data,
        xticklabels = {
            Gating1,
            Gating2,
            Gating3,
        },
    %    enlarge x limits={abs=1}    
        xlabel=Stimuli Condition,
        xlabel style={yshift=-10ex},
        xticklabel style={yshift=-10ex},
        major x tick style = {opacity=0},
        minor x tick num = 1,
        minor tick length=1ex,
        every node near coord/.append style={
                anchor=east,
                rotate=90
        }
        ]

\addplot[draw=black,fill=blue!20, nodes near coords=Question] table[x index=0,y index=1] \dataset;
\addplot[draw=black,fill=red!20, nodes near coords=Statement] table[x index=0,y index=2] \dataset;
\addplot[draw=black,fill=green!20, nodes near coords=Uncertain] table[x index=0,y index=3] \dataset;

\end{axis}
\end{tikzpicture}
\caption{Frequency and Proportion of Responses by Utterance Type and Gating Condition}\label{graph Frequency and Proportion of Responses by Utterance Type and Gating Condition}

\end{figure}
\end{document}

\documentclass[11pt]{article} 
\usepackage{fullpage, lipsum, tikz}
\usepackage{eso-pic}
\AddToShipoutPictureBG{%
\begin{tikzpicture}[remember picture, overlay]
\node[opacity=.1, inner sep=0pt]
    at(current page.center){\includegraphics[width=14cm,
    angle=45]{example-image-duck}};
\end{tikzpicture}%
}
\begin{document}
\lipsum[1-20] 
\end{document}

\documentclass{standalone}

\usepackage{pgfplots}
\pgfplotsset{no markers}
\pgfplotsset{but I really want a mark/.style={/pgfplots/every axis plot
post/.append style={mark=#1}}}
\begin{document}

\begin{tikzpicture}
  \begin{axis}
    \addplot coordinates { (1,1) (2,2) (3,2) };
  \end{axis}
\end{tikzpicture}

\begin{tikzpicture}
  \begin{axis}[but I really want a mark={*}]% works
    \addplot coordinates { (1,1) (2,2) (3,2) };
  \end{axis}
\end{tikzpicture}
\end{document}

\begin{tikzpicture}
  \begin{axis}[mark options={*}]% does not work
    \addplot[mark=*] coordinates { (1,1) (2,2) (3,2) };% does not work, but strangely changes line color to black?
  \end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

顺便说一句,上面是工作示例,也就是说,它可以按原样编译。由于我不知道你的序言,我不得不把宽度调小一点,以适应标准类article。这是为什么你可能总是想提供一个完整的示例,让其他人可以复制和编译的众多原因之一。

相关内容