我想绘制一些 y 坐标较小的数据。我使用以下代码进行编译,结果在 y 轴上出现了一个意外的 $10^{-2}$(见下图)。有办法去掉它吗?谢谢!
\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.8]
\begin{axis}[
axis lines = left,
xlabel={$\theta$},
ylabel={},
axis line style = thick,
xmin=-1, xmax=2.1,
ymin=-0.015, ymax=0.025,
ytick={}, yticklabels={},
xtick={0,1}, xticklabels={$0$, $1$}, xtick style={draw=none}, ytick style={draw=none},
legend style={at={(1.1,1)}},
legend style={draw=none},
ymajorgrids=false,
grid style=dashed,
every axis x label/.style={
at={(ticklabel* cs:1.0)},
anchor=west,},
every axis y label/.style={
at={(ticklabel* cs:1)},
anchor=south,
},
]
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您可以使用scaled ticks=false
以下选项关闭常见的缩放因子:
\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.8]
\begin{axis}[
axis lines = left,
xlabel={$\theta$},
ylabel={},
scaled ticks=false,
axis line style = thick,
xmin=-1, xmax=2.1,
ymin=-0.015, ymax=0.025,
ytick={}, yticklabels={},
xtick={0,1}, xticklabels={$0$, $1$}, xtick style={draw=none}, ytick style={draw=none},
legend style={at={(1.1,1)}},
legend style={draw=none},
ymajorgrids=false,
grid style=dashed,
every axis x label/.style={
at={(ticklabel* cs:1.0)},
anchor=west,},
every axis y label/.style={
at={(ticklabel* cs:1)},
anchor=south,
},
]
\end{axis}
\end{tikzpicture}
\end{document}
答案2
解决您的问题的(真正的)MWE(最小工作示例)的一个例子:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = left,
axis line style = thick,
xlabel={$\theta$},
xlabel style={at={(1,0)},anchor=west},
xmin=-1, xmax=2.1,
ymin=-0.015, ymax=0.025,
xtick={0,1},
tick style={draw=none},
ytick=\empty,
% extra y ticks = {0.005,0.01}, % if needed some thicks
legend style={at={(1.1,1)}, draw=none},
]
\end{axis}
\end{tikzpicture}
\end{document}
答案3
答案是,ytick=\empty,
这会使 tikz 在 y 轴刻度上不放置任何内容。