2

I have data that becomes almost linear when plotting it in a logarithmic contour plot. Therefore I want to generate the contour lines externally and store the data logarithmically. Then I want to use the contour prepared feature of pgfplots to generate contour plots.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel={$\log x$},
ylabel={$\log y$},
title={$\log z$}
]% mock data
\addplot [contour prepared] table {
0   -11.37  10.
0.1041  -12.    10.
0   -9.374  8.
0.436   -12.    8.
0.7662  -12.    6.
0   -7.374  6.
1.092   -12.    4.
0   -5.374  4.
0   -3.374  2.
1.406   -12.    2.
0.1041  -2. 0
1.602   -11.42  0
0.436   -2. -2.
1.602   -9.424  -2.
1.602   -7.424  -4.
0.7663  -2. -4.
1.602   -5.424  -6.
1.092   -2. -6.
1.602   -3.424  -8.
1.406   -2. -8.
};
\end{axis}
\end{tikzpicture}
\end{document}

However, instead of the labels log x, log y, and log z I want labels x, y, and z and correspondingly all ticks should be transformed according to x -> 10^x. Especially for the x axis it would be good if I could use values from {1,2,5,10,20} for the ticks. Additionally, it would be nice if I could also add logarithmic minor ticks, when appropriate (in this example only useful for the x axis).

1 Answer 1

1
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}[
xlabel={$x$},
ylabel={$y$},
title={$z$},
xtick={1,2,5,10,20},
xticklabels={1,2,5,10,20},
%log ticks with fixed point,
ytick distance=10,
]% mock data
\addplot [contour prepared] table[x expr={10^\thisrowno{0}}, y expr={10^\thisrowno{1}}
] {
0   -11.37  10.
0.1041  -12.    10.
0   -9.374  8.
0.436   -12.    8.
0.7662  -12.    6.
0   -7.374  6.
1.092   -12.    4.
0   -5.374  4.
0   -3.374  2.
1.406   -12.    2.
0.1041  -2. 0
1.602   -11.42  0
0.436   -2. -2.
1.602   -9.424  -2.
1.602   -7.424  -4.
0.7663  -2. -4.
1.602   -5.424  -6.
1.092   -2. -6.
1.602   -3.424  -8.
1.406   -2. -8.
};
\end{loglogaxis}
\end{tikzpicture}
\end{document}

Logarithmic plot with contour lines

You must log in to answer this question.

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