【问题标题】:Problem with rotated yticklabels using pgfplot使用 pgfplot 旋转 yticklabels 的问题
【发布时间】:2019-10-15 06:29:51
【问题描述】:

我正在使用"yticklabel style={rotate=90}" 将 pgfplot 中的 ytick 标签旋转 90°。标签的文本没有正确水平对齐。

在以下示例中,“Grouped”未与其他标签对齐(尤其是因为它包含“p”)。

图片:

我已经用完了“样式”选项来解决这个问题,知道如何让这些值水平对齐吗?谢谢!

编辑:

最小示例(请注意,我的实际代码使用标签来处理 CSV 文件中的列):

\documentclass{article}
% translate with >> pdflatex -shell-escape <file>

% This file is an extract of the PGFPLOTS manual, copyright by Christian Feuersaenger.
% 
% Feel free to use it as long as you cite the pgfplots manual properly.
%
% See
%   http://pgfplots.sourceforge.net/pgfplots.pdf
% for the complete manual.
%
% Any required input files (for <plot table> or <plot file> or the table package) can be downloaded
% at
% http://www.ctan.org/tex-archive/graphics/pgf/contrib/pgfplots/doc/latex/
% and
% http://www.ctan.org/tex-archive/graphics/pgf/contrib/pgfplots/doc/latex/plotdata/

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\pagestyle{empty}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    xbar, xmin=0,
    width=12cm, height=5.5cm, enlarge y limits=0.5,
    xlabel={\#participants},
    symbolic y coords={Flat,Grouped},
    ytick=data,
    nodes near coords, nodes near coords align={horizontal},
    yticklabel style={rotate=90},
    ]
    \addplot coordinates {(3,Flat) (7,Grouped)};
  \end{axis}
\end{tikzpicture}
\end{document}

【问题讨论】:

  • 在标签中插入\strut 而不使用降序可能会有所帮助,但这只是一个猜测,只要没有示例代码可以测试

标签: latex


【解决方案1】:

yticklabel style={rotate=90,anchor=base,yshift=0.2cm}:

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

\pagestyle{empty}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    xbar, xmin=0,
    width=12cm, height=5.5cm, enlarge y limits=0.5,
    xlabel={\#participants},
    symbolic y coords={Flat,Grouped},
    ytick=data,
    nodes near coords, nodes near coords align={horizontal},
    yticklabel style={rotate=90,anchor=base,yshift=0.2cm},
    ]
    \addplot coordinates {(3,{Flat}) (7,Grouped)};
  \end{axis}
\end{tikzpicture}
\end{document}

(红线只是为了看基线是否对齐)

【讨论】:

  • 太好了,我使用yshift=1ex 将偏移量固定到 y 轴。谢谢!
猜你喜欢
  • 1970-01-01
  • 2018-04-24
  • 1970-01-01
  • 2011-11-16
  • 1970-01-01
  • 1970-01-01
  • 2014-07-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多