![PGFPlot 格式帮助](https://linux22.com/image/252442/PGFPlot%20%E6%A0%BC%E5%BC%8F%E5%B8%AE%E5%8A%A9.png)
我有以下 pgfplot:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{every axis legend/.append style={
at={(1.05,1)},
anchor=north west}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ylabel=Number of Respondents,
enlargelimits=0.15,
legend cell align=right,
ybar,
bar width=10pt,
symbolic x coords = {Very U, Somewhat U, Not U},
xtick=data,
x tick label style={anchor=north},
width=.50\textwidth,
ymin=0,
]
\addplot
coordinates {(Very U,1) (Somewhat U,3) (Not U,1)};
\addplot
coordinates {(Very U,2) (Somewhat U,0) (Not U,0)};
\addplot
coordinates {(Very U,1) (Somewhat U,2) (Not U,0)};
\addplot
coordinates {(Very U,4) (Somewhat U,5) (Not U,1)};
\legend{Survey Vote \#257, Survey Vote \#968, Survey Vote \#156, All Surveys}
\end{axis}
\end{tikzpicture}
\end{document}
我想要做的是让最左边的组在开始之前有一个小填充(不在 y 轴的正上方),并且最右边的组也一样,在它和 y 轴之间有一个小填充。
我还想让图例稍微大一点……
答案1
为了在图的左侧和右侧获得额外的填充,您可以设置enlarge x limits=<fraction>
。0.3
在这种情况下效果很好,但它会导致图中间的条重叠,因此您必须将减少一点bar width
,比如说,减少到6pt
。
enlarge x limits=0.3,
bar width=6pt
如您所见,由于 x 标签很长,它们会重叠,因此看起来您必须使图更宽。您可以通过明确设置 aheight
和 a来实现width
,也可以使用键 来实现x post scale=<multiplier>
。
enlarge x limits=0.3,
x post scale=1.5
为了使图例图像更大,您可以使用legend image post style={scale=<multiplier>}
:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{every axis legend/.append style={
at={(1.05,1)},
anchor=north west},
legend image post style={scale=1.5}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ylabel=Number of Respondents,
enlarge x limits=0.3,
x post scale=1.5,
legend cell align=right,
ybar,
symbolic x coords = {Very U, Somewhat U, Not U},
xtick=data,
x tick label style={anchor=north},
width=.50\textwidth,
ymin=0,
]
\addplot
coordinates {(Very U,1) (Somewhat U,3) (Not U,1)};
\addplot
coordinates {(Very U,2) (Somewhat U,0) (Not U,0)};
\addplot
coordinates {(Very U,1) (Somewhat U,2) (Not U,0)};
\addplot
coordinates {(Very U,4) (Somewhat U,5) (Not U,1)};
\legend{Survey Vote \#257, Survey Vote \#968, Survey Vote \#156, All Surveys}
\end{axis}
\end{tikzpicture}
\end{document}