Pgfplot 图形偏离中心

Pgfplot 图形偏离中心

\includegraphics我在独立模式下创建了一个 tikzpicture(见下面的代码)。然后通过(见图)将生成的 .pdf 文件导入我的文档。但是,使用时轴标签被切断并成为 ytick 的一部分[trim axis left, trim axis right]。如果我不使用该命令,它看起来很好,但不再居中。有什么想法吗?

PS 这是重复的,但可能更简洁由于轴标签,Pgfplot 图形偏离中心

在此处输入图片描述

\documentclass[tikz,border=12pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks}
\begin{document}
\definecolor{mycolor1}{rgb}{0.0416666666666667,0,0}

\begin{tikzpicture}[trim axis left, trim axis right]


\begin{axis}[%
width=6.17578125in,
height=2.23276041666667in,
area legend,
scale only axis,
xmin=0.5,
xmax=5.5,
xtick={1,2,3,4,5},
xticklabels={Equipment,Patient,{Hygiene products},Near-bed,Far-bed},
ymin=0,
ymax=0.35,
ytick={  0, 0.1, 0.2, 0.3, 0.4},
ylabel={Probability density},yticklabel style={/pgf/number format/fixed},
legend style={at={(0.143572984749455,0.733206590621038)},anchor=south west,draw=black,fill=white,legend cell align=left}
]
\addplot[ybar,bar width=0.282321428571429in,bar shift=-0.176450892857143in,fill=mycolor1,draw=black] plot coordinates{(1,0.163793103)
(2,0.164367816)
(3,0.141954023)
(4,0.279310345)
(5,0.250574713)};

\addlegendentry{Smith et al.};

\addplot [
color=black,
solid,
forget plot
]
table[row sep=crcr]{
0.5 0\\
5.5 0\\
};
\addplot[ybar,bar width=0.282321428571429in,bar shift=0.176450892857143in,fill=white,draw=black] plot coordinates{(1,0.165289256)
(2,0.185950413)
(3,0.157024793)
(4,0.285123967)
(5,0.20661157)};

\addlegendentry{Adjusted YAB};

\end{axis}
\end{tikzpicture}%
\end{document}

答案1

您可以做的一件事是(手动)增加图表周围的边框。该standalone包允许独立于顶部和底部边框设置左边框和右边框。因此,如果您更改

\documentclass[tikz,border=12pt]{standalone}

\documentclass[tikz,border={38pt 12pt}]{standalone}

那么你的 y 轴标签将不会被裁剪,你的图表将保持居中。唯一的缺点是,这有点肮脏!

相关内容