在 pgfplots 中使用第二个 y 轴的最小工作示例是以下代码
\begin{tikzpicture}
\begin{axis}[scale only axis, axis y line*=left]
\addplot[no marks, blue] {x^2};
\end{axis}
\begin{axis}[scale only axis, axis x line=none, axis y line*=right]
\addplot[no marks, red] {x^7};
\end{axis}
\end{tikzpicture}
我怎样才能将第二个 y 轴的指数位置(\cdot 10^4
)从左到右更改到其所属的位置?
答案1
使用。您可以使用安装的版本号\pgfplotsset{compat=newest}
来代替。当前 pgfplots 版本为 1.13。current
pgfplots
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13} %<-
\begin{document}
\begin{tikzpicture}
\begin{axis}[scale only axis, axis y line*=left]
\addplot[no marks, blue] {x^2};
\end{axis}
\begin{axis}[scale only axis, axis x line=none, axis y line*=right]
\addplot[no marks, red] {x^7};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
您可以修改every y tick scale label
样式:
\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[scale only axis, axis y line*=left]
\addplot[no marks, blue] {x^2};
\end{axis}
\begin{axis}[scale only axis, axis x line=none, axis y line*=right,
every y tick scale label/.style={
at={
(rel axis cs:1,1)},
anchor=south east}]
\addplot[no marks, red] {x^7};
\end{axis}
\end{tikzpicture}
\end{document}