5

I need to get this done in TikZ. Can anyone help me? I know how to get the axes done but the curve itself is quite hard for me:

One

MWE:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}%http://www.ctan.org/pkg/pgfplots
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[%
            domain = -.5:3,
            samples = 50,
            axis x line = center,
            axis y line = center,
            xlabel = {$x$},
            ylabel = {$y$},
            ticks = none
            ]
            \addplot[blue] {abs(x-2)} [yshift=3pt] node[pos=.95,left] {$y=|x-2|$};
        \end{axis}
    \end{tikzpicture}
\end{document}

    
3
  • You can't just plot a curve by name, presumably you have some polynomial approximation that you want to plot? Choice of approximation would be off topc here. Commented Aug 25, 2022 at 10:45
  • I want to get the closest curve that resembles the one in the picture! The function could be any, i.e., x^2 (half)
    – Jeff
    Commented Aug 25, 2022 at 10:47
  • as I say, I don't think choice of approximation is on topic, your sketch doesn't look like x^2 to me, You should specify the function you want to plot. Commented Aug 25, 2022 at 10:57

2 Answers 2

3

Code for drawn your diagram with pgfplots is a bit more complex as with pure tikz:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[%
    axis lines = center,
    xlabel = {$T$},
    ylabel = {$E(T)$},
    label style = {anchor=north east},
    xmin = 0, xmax=5,     ymin=0, ymax=1,
    ticks = none,
    enlargelimits=false,
    clip=false,
%
    domain = 1:4,
    samples = 50,
    no marks
            ]
\addplot    {1/x};
\draw[red,  densely dashed]  (0,1/2) node[left] {$E_0$} -| (2,0) node[below] {$T_0$};
\draw[blue, densely dashed]  (0,1/3) node[left] {$E_1$} -| (3,0) node[below] {$T_1$};
\end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

4

For something that simply you can use bare TikZ without pgfplots

Code

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[
  mark point at x/.style 2 args={
    densely dotted,
    insert path={(#1, 0) |- (0, {f(#1)})
      node[black, at start, below] {$T_{#2}$}
      node[black, at end, left] {$E_{#2}$}}
  },
  declare function={f(\x)=1/\x;}
]
\draw[<->] (up:3) |- (right:5);
\draw plot [smooth, domain=.34:4.9] (\x, {f(\x)});

\begin{scope}[nodes={font=\small}]
  \draw[blue, mark point at x={2}{1}];
  \draw[red, mark point at x={1}{0}];
  \node[below] at (right:4) {Token};
  \node[left] at (up:2) {Eth};
\end{scope}
\end{tikzpicture}
\end{document}

Output

enter image description here

You must log in to answer this question.

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