我正在寻找与 matplotlibs Secondary Axes 等效的 pgfplotshttps://matplotlib.org/3.1.0/gallery/subplots_axes_and_figures/secondary_axis.html
答案1
更新:找到解决方案了!我遇到了类似的问题,并对其进行了少许修改。 在 Pgfplots 中使用乘法指定 xtick/ytick
重要的是,xmin 和 xmax 在两个轴上相等,并且 y 轴方向是相反的。
\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows, arrows.meta}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\let\yticklist=\empty% create scaled list
\foreach \y in {105,100, ..., 60}
{
\pgfmathparse{(1-(1-3.1415/\y)^2)*100} \pgfmathresult
\pgfmathprintnumberto[precision=2]{\pgfmathresult}{\roundednumber}
\ifx\empty\yticklist\relax \xdef\yticklist{\roundednumber}%
\else \xdef\yticklist{\yticklist,\roundednumber}%
\fi
}
\begin{axis}[%
xmin=44,
xmax=66,
y dir= reverse,
ymin=60,
ymax=105 ,
ytick = {60, 65, ..., 105},
yticklabels/.expanded = {\yticklist},
axis x line=none,
axis y line=right,
y axis line style={-Butt Cap},
ylabel = {loss in \%},
]
\end{axis}
\begin{axis}[%
xmin=44,
xmax=66,
ymin=60,
ymax=105,
ytick = {60, 65, ..., 105},
ylabel={quality},
xlabel={angle in deg},
grid=major,
]
\addplot[red, line width=0.8mm] table{file.txt};
\end{axis}
\end{tikzpicture}
\end{document}