I am looking for a pgfplots equivalent to matplotlibs Secondary Axes https://matplotlib.org/3.1.0/gallery/subplots_axes_and_figures/secondary_axis.html
-
Hi ankaaaaa, welcome to TeX.SE! Can you please show a MWE to see, what you already tried and to build upon?– TobiBSCommented Jul 7, 2020 at 18:13
-
Done, see edit!– ankaaaaaCommented Jul 7, 2020 at 19:11
-
Seems you found an answer :) In cases like that it's generally better to post it as an actual answer, not as an edit to the question.– Torbjørn T.Commented Jul 8, 2020 at 21:35
-
Thanks for the comment, I will do that! :)– ankaaaaaCommented Jul 9, 2020 at 7:55
Add a comment
|
1 Answer
Update: Found a solution! I used a similar problem and edited it a little. Specify xtick/ytick with multiplication in Pgfplots
Important is, that the xmin and xmax are equal in both axis, and that the y axis direction is reversed.
\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}