![如何从顶部、底部和右侧边框删除 Tikz pgfplot 刻度?](https://linux22.com/image/394330/%E5%A6%82%E4%BD%95%E4%BB%8E%E9%A1%B6%E9%83%A8%E3%80%81%E5%BA%95%E9%83%A8%E5%92%8C%E5%8F%B3%E4%BE%A7%E8%BE%B9%E6%A1%86%E5%88%A0%E9%99%A4%20Tikz%20pgfplot%20%E5%88%BB%E5%BA%A6%EF%BC%9F.png)
我正在创建一个直方图,我已经使用以下代码完成了:
\begin{tikzpicture}
\centering
\begin{axis}[
ymin=0, ymax=50,
minor y tick num = 2,
axis background/.style={fill=gray!5},
area style,
xticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=1,zerofill}\pgfmathprintnumber{\tick}x,
yticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=0,zerofill}\pgfmathprintnumber{\tick}\%,
xlabel={EV/EBIT},
ylabel={Frequency}],
]
\addplot+ [ybar interval,mark=no, fill={rgb:red,0;green,47;blue,135},draw=gray!5] plot coordinates { (0, 0) (5, 7.6) (10, 40.1) (15, 30.5) (20, 10.7) (25, 4.1) (30, 2.4) (35, 1.4) (40, 1.0) (45, 0.7) (50, 0.4)};
\end{axis}
\end{tikzpicture}
这使:
但让我感到烦恼的是底部 x 轴、顶部边框和右侧边框上的刻度。有什么办法可以改变这种情况吗?
答案1
要使 y 刻度只在左侧,请添加ytick pos=left,
,请参阅部分4.15.2 刻度对齐:位置和偏移请参阅 pgfplots 手册以了解更多详细信息。要完全删除 xticks,只需添加xtick style={draw=none}
。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xtick style={draw=none},ytick pos=left,
ymin=0, ymax=8000,
minor y tick num = 2,
axis background/.style={fill=gray!5},
area style,
]
\addplot+ [ybar interval,mark=no, fill={rgb:red,0;green,47;blue,135},draw=gray!5] plot coordinates { (0, 32) (5, 1228) (10, 6658) (15, 5060) (20, 1786) (25, 684) (30, 404) (35, 228) (40, 165) (45, 119) (50, 72)};
\end{axis}
\end{tikzpicture}
\end{document}