我为正在制作的图表编写了以下代码:
\usepackage{tikz}
\begin{document}
\begin{figure}[h]
\centering
\caption{AMD top 10 SBP peers (2016)}
\label{FigAMDtop10SBPpeers}
\begin{tikzpicture}
\begin{axis}[
ymin=0, ymax=8,
ylabel = Annual Search Fraction,
yticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=0,zerofill}\pgfmathprintnumber{\tick}\%,
axis background/.style={fill=gray!5},
symbolic x coords={Intel,HP,Nvidia,Broadcom,Texas Instruments,Google,Microsoft,IBM},
xtick=data]
\addplot[ybar,fill={rgb:red,0;green,47;blue,135}] coordinates {
(Intel,6.1529271206690564)
(HP,1.3888888888888888)
(Nvidia,1.045400238948626)
(Broadcom,0.9557945041816009)
(Texas Instruments,0.9109916367980884)
(Google,0.6869772998805257)
(Microsoft,0.6571087216248507)
(IBM,0.6421744324970132)
};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
看起来像:
显然,x 标签不合适。我想知道是否有办法让整个 x 标签可见,而无需旋转标签(我不喜欢布局)?对于像 Texas Instruments 这样有两个单词的公司,也许可以将第二个单词放在下一行?
编辑:可能的解决方案不是我想要的,因为这只是将其他所有标签向下移动。这不是我想要的;我想让标签位置保持相邻。
答案1
代码借自使用 tikz 在 newcommand 的刻度标签中包含数学环境
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\pgfplotsset{xpiaxis/.style={% instead of command define style ...
xtick={0,...,8},%
xticklabels={Intel,HP,Nvidia,Broadcom,\parbox{1in}{\centering{}Texas\\Instruments}}
}
}
\begin{document}
\begin{figure}[h]
\centering
\caption{AMD top 10 SBP peers (2016)}
\label{FigAMDtop10SBPpeers}
\begin{tikzpicture}
\begin{axis}[
width=\textwidth,
ymin=0, ymax=8,
ylabel = Annual Search Fraction,
yticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=0,zerofill}\pgfmathprintnumber{\tick}\%,
axis background/.style={fill=gray!5},
xpiaxis]
\addplot[ybar,fill={rgb:red,0;green,47;blue,135}] coordinates {
(1,6.1529271206690564)
(2,1.3888888888888888)
(3,1.045400238948626)
(4,0.9557945041816009)
(5,0.9109916367980884)
(6,0.6869772998805257)
(7,0.6571087216248507)
(8,0.6421744324970132)
};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}