我正在尝试创建一个具有两个独立 y 轴的图。右侧 y 轴为单位 * 10^5。但是,乘法标题的位置不正确。我使用以下代码:
\begin{tikzpicture}
\begin{axis}[
axis y line* = left,
xlabel = grid size $l$,
ylabel = \textcolor{blue}{\footnotesize$\blacksquare$}
indices per $\mathcal{T}$,
ymode = log,
log origin=infty]
\addplot[color=blue,mark=x] coordinates {
(15000,317.631)
(20000,182.318)
(40000,49.3089)
(80000,14.4933)
(160000,5.02436)
(320000,2.37795)
(500000,1.81145)
(640000,1.62701)
(1280000,1.29392)
(2560000,1.18447)
};
\end{axis}
\begin{axis}[
hide x axis,
ylabel near ticks,
axis y line*=right,
ylabel={\textcolor{red}{\footnotesize$\blacksquare$} number of $\mathcal{T}_{pot}$}]
\addplot[color=red,mark=x] coordinates {
(15000,40819)
(20000,41179)
(40000,41179)
(80000,42720)
(160000,44312)
(320000,44866)
(640000,98610)
(1280000,168980)
(2560000,184202)
};
\draw[black,dashed] (axis cs:500000,0) -- (axis cs:500000,200000);
\draw (axis cs:500000,200000) node[below right] {$l_r$};
\end{axis}
\end{tikzpicture}
其结果如下:
但是,我希望右上角的 *10^5 与 y 轴右侧对齐,而不是左侧。它应该像右侧 y 轴的刻度标签一样对齐。
非常感谢您的帮助!
答案1
您需要调整的选项是y tick scale label style
。如果您指定为
at={(yticklabel cs:1.05)}
这将与 y 轴上的其他刻度对齐,超出末尾 5%。如果您指定
at={(yticklabel cs:1.05,10pt)}
10pt
那么它将被进一步向右移动。
\documentclass{article}
\usepackage{pgfplots,amssymb}
\pgfplotsset{compat=1.10}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis y line* = left,
xlabel = grid size $l$,
ylabel = \textcolor{blue}{\footnotesize$\blacksquare$}
indices per $\mathcal{T}$,
ymode = log,
log origin=infty]
\addplot[color=blue,mark=x] coordinates {
(15000,317.631)
(20000,182.318)
(40000,49.3089)
(80000,14.4933)
(160000,5.02436)
(320000,2.37795)
(500000,1.81145)
(640000,1.62701)
(1280000,1.29392)
(2560000,1.18447)
};
\end{axis}
\begin{axis}[
hide x axis,
ylabel near ticks,
axis y line*=right,
y tick scale label style={at={(yticklabel cs:1.05,10pt)}},
ylabel={\textcolor{red}{\footnotesize$\blacksquare$} number of $\mathcal{T}_{pot}$}]
\addplot[color=red,mark=x] coordinates {
(15000,40819)
(20000,41179)
(40000,41179)
(80000,42720)
(160000,44312)
(320000,44866)
(640000,98610)
(1280000,168980)
(2560000,184202)
};
\draw[black,dashed] (axis cs:500000,0) -- (axis cs:500000,200000);
\draw (axis cs:500000,200000) node[below right] {$l_r$};
\end{axis}
\end{tikzpicture}
\end{document}