2

Trying to recreate this graph: enter image description here

however mine turns out like this:

enter image description here

Issues that I am having:

  1. The curve doesn't look very smooth and even.
  2. Nothing I try to draw (\draw) appears in the figure, I'm trying to add the text inside the figure.

Code:

\begin{tikzpicture}
    \begin{axis}[xlabel = {lowest to highest},
                ylabel = {income earned},
                xmin = 0,
                xmax = 1,
                ymin = 0,
                ymax = 1
    ]
        \addplot[smooth]{x};
        \addplot[smooth, thick, label=$x$]{x^2};
        \coordinate (P) at (0,0);
        \node[rotate=45] (N) at (P) {lorenz curve};
    \end{axis}
\end{tikzpicture}

The last part trying to draw the text node was just something I found here: TikZ diagonal text. What am I doing wrong?

2

Something like this?

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[xlabel = {lowest to highest},
                ylabel = {income earned},
                xmin = 0,
                xmax = 1,
                ymin = 0,
                ymax = 1
    ]
        \addplot[domain=0:1]{x} node[midway,above,sloped]{Line of equality}
        node[midway,below,sloped]{Concentration area};
        \addplot[domain=0:1,smooth, thick, label=$x$]{x^2}
        node[midway,below,sloped]{Lorenz curve};
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

7
  • Amazing! Only thing is that the "concentration area" comes out at an awkward position for me, the y=x line goes through it, unlike your picture above. How would I move it? – Chisq Apr 17 '19 at 14:31
  • Use [below=1ex] or so to adjust the positioning. – John Kormylo Apr 17 '19 at 14:34
  • 1
    @Chisq Does that happen when you compile the above or when you embed it into another document (in which you e.g. did not say \pgfplotsset{compat=1.16})? – user121799 Apr 17 '19 at 14:36
  • 1
    @Chisq It is hard for me to debug this because the above does not have the issue, nor do I know what I can do to reproduce it. There are many conceivable reasons. How about \addplot[domain=0:1]{x} node[midway,above,sloped]{Line of equality}; \node[rotate=40] at (0.5,0.4 ){Concentration area};? – user121799 Apr 17 '19 at 14:49
  • 1
    @Chisq This is because pgfplots rescales both directions independently to produce a plot that has the preset width and height. You can turn this off by adding axis equal image to the options of the axis, in which case the x and y units will be the same (in this example). – user121799 Apr 17 '19 at 15:03

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.