I'm trying to reproduce the following pyplot figure with pgfplots:

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 1)
plt.plot(np.log(x)-np.log(1-x), np.log(x / (x + (1-x))))
plt.xlim(-3, 3)

My attempt so far with pgfplots, using x coord trafo:



\begin{axis}[every axis plot post/.append style={
  x coord trafo/.code={\pgfmathparse{log10(#1) - log10(1-#1)}},
  \addplot {log10(x / (x + (1-x)))};


I think I'm close, but am unable to set xlim to (-3, 3). I think I'm thinking too much in a pyplot manner! Is there an elegant way to achieve this?

  • I don't know pyplot, but are you searching for xmin and xmax? – Stefan Pinnow Jul 29 at 18:36

Hopefully everything is stated in the comments of the code ...

% used PGFPlots v1.16
        % set the x axis limits
        % (for details see also the comment before `\addplot`)
%        % commented `no markers` to show that default sample rate is
%        % sufficient when the domain is adapted accordingly
%        no markers,
        % because at x = 0 and x = 1 the values are not defined
        % I adopted the values a bit
%        % because after adopting the `domain` the first and last point
%        % aren't "skipped" there should be no need for such a high sample rate
%        samples=51,
        % added `smooth` just in case the `samples` are to less
        % instead of using `x coord trafo` just plot a parametric plot
        % (as I assume you did in pyplot)
        % this allows to easily set `xmin` and `xmax`
        % (if you would stick to `x coord trafo` you would need to know
        %  the *untransformed* x values which correspond to the
        %  transformed values of -3 and 3 and state them in `xmin` and `xmax`)
        \addplot (
            {log10(x) - log10(1-x)},
            {log10(x / (x + (1-x)))}

image showing the result of above code

  • Thanks Stefan! Oddly I did not realise I could do a parametric plot...! Thanks very much for the comments in the code. – jodles Jul 29 at 19:43

Why don't you use a parametric plot?



        \addplot[thick, blue] ({log10(x)-log10(1-x)}, {log10(x / (x + (1-x)))});


enter image description here

  • Thanks Rmano! It baffles me that I did not realise I could use a parametric plot... – jodles Jul 29 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.