1

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

4
  • Hi ankaaaaa, welcome to TeX.SE! Can you please show a MWE to see, what you already tried and to build upon?
    – TobiBS
    Commented Jul 7, 2020 at 18:13
  • Done, see edit!
    – ankaaaaa
    Commented 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. Commented Jul 8, 2020 at 21:35
  • Thanks for the comment, I will do that! :)
    – ankaaaaa
    Commented Jul 9, 2020 at 7:55

1 Answer 1

1

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}

plot

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .