在 pgfplots 条形图上排列有角度的刻度标签

在 pgfplots 条形图上排列有角度的刻度标签

我正在尝试制作一个条形图以供发布,并在刻度标签中添加数学文本。最易读的布局是将它们倾斜,但这样做会与轴发生冲突,并且很难与正确的条形图相关联。我尝试使用 \quad 空格进行填充,但这会使它们离它们应该标记的条形图更远。有没有办法偏移标签位置,或者有更优雅的解决方案?

最小示例:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}

\begin{axis}[%
xmin=0.5, xmax=5.5,
xtick={1,2,3,4,5},
xticklabels={
$\textrm{fish}^\textrm{cake}$,$\Delta \textrm{bob}^2$,spoon,$e^{i \pi}+1 = 0$,knife},
x tick label style={rotate=45, anchor=east},
ylabel={Energy / Hadouken mol$^{-1}$}]
\addplot[ybar,bar width=0.6cm,fill=gray,draw=black] plot coordinates{(1,10)
(2,20)
(3,40)
(4,-20)
(5,10)};


%% This is just to add a zero line for clarity
\addplot [
color=black,
solid,
forget plot
]
table{
0 0
6 0
};

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

输出:

在此处输入图片描述

答案1

我能想到两件事:

  • 将标注锚定在north east而不是east。以这种方式以对角线方式放置标注更有意义。

  • 通过设置来减少标签周围的间距inner sep=0mm

结果:

在此处输入图片描述

代码:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}

\begin{axis}[%
xmin=0.5, xmax=5.5,
xtick={1,2,3,4,5},
xticklabels={
$\textrm{fish}^\textrm{cake}$,$\Delta \textrm{bob}^2$,spoon,$e^{i \pi}+1 = 0$,knife},
x tick label style={rotate=45, anchor=north east, inner sep=0mm},
ylabel={Energy / Hadouken mol$^{-1}$}]
\addplot[ybar,bar width=0.6cm,fill=gray,draw=black] plot coordinates{(1,10)
(2,20)
(3,40)
(4,-20)
(5,10)};


%% This is just to add a zero line for clarity
\addplot [
color=black,
solid,
forget plot
]
table{
0 0
6 0
};

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

相关内容