8

I'd like to plot a curve like the following (TTR=1-e^{-t}; t*=-log(0.2); TTR_PLATEAU=1):

enter image description here

So far I know only how show a series of symbolic values on axis.

\documentclass{article}
\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.15}
\usepackage{physics}
\usepackage{amsmath, amssymb, amsfonts}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
        xlabel={$t$},
        ylabel={$TTR$},
        axis lines=center,
        xtick distance=1,
        ytick distance=1,
        xmin=0,xmax=4.9,
        ymin=0,ymax=4.9,
        xticklabel={$t_{\pgfmathprintnumber[precision=0]{\tick}}$},
        yticklabel={$TTR_{\pgfmathprintnumber[precision=0]{\tick}}$}
]

\addplot +[mark=none,smooth] {1-e^(-x)};

\end{axis}
\end{tikzpicture}

\end{document}

Thank you so much.

7

xtick/ytick is used to set ticks at specific locations, xticklabels/yticklabels (note s at the end) is used to provide a list of labels (rather than providing a pattern, as one does with xticklabel).

output of code

\documentclass{article}
\usepackage{pgfplots}% also loads graphicx
\pgfplotsset{width=10cm,compat=1.15}
\usepackage{physics}
\usepackage{amsmath, amssymb, amsfonts}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
        xlabel={$t$},
        ylabel={$TTR$},
        axis lines=center,
        xmin=0,xmax=4.9,
        ymin=0,ymax=4.9,
        ytick={0.8,1},
        xtick={1.61},
        xticklabels={$t^*$},
        yticklabels={80\% TTR\_PL, TTR\_PLATEAU}
]

\addplot +[mark=none,smooth] {1-e^(-x)};
\draw [dashed] (0,0.8) -| (1.61,0);
\draw [dashed] (0,1) -- (\pgfkeysvalueof{/pgfplots/xmax},1);

\end{axis}
\end{tikzpicture}

\end{document}
  • Wow! Amazing, short, extremely clear, code! @Torbjørn T. – Gennaro Arguzzi Dec 4 '17 at 9:39
  • Is there a way to reduce the y axis length? For example length(y axis)=length(x axis)/2. – Gennaro Arguzzi Dec 4 '17 at 10:02
  • @GennaroArguzzi See chapter 4.10 Scaling options in the pgfplots manual. There are width and height keys that you can use to set the size of the axis, add e.g. width=8cm,height=4cm to the axis options. By default the lengths you define include some space for labels, so the actual size of the axis box is a little bit smaller. If you add scale only axis to the axis options, width and height apply to the axis box only, so the total size (including axis labels/ticklabels) will be larger. – Torbjørn T. Dec 4 '17 at 10:15
  • Thank you @Torbjørn T. I was wrong because my last question is not pertinent with the initial question. – Gennaro Arguzzi Dec 4 '17 at 11:00
7

alternatively, by use of intersections library:

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.15}
\usetikzlibrary{intersections}
\usepackage{siunitx}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
        xlabel={$t$},
        ylabel={$TTR$},
        axis lines=center,
        ymin=0, ymax=2,
        xtick=\empty,
        ytick=\empty,
        no marks,
        every axis plot post/.append style={very thick},
        clip=false
]

\addplot +[name path=A,domain=0:5] {1-e^(-x)};
\path [name path=B] (0,0.8) -- + (5,0);
\draw [name intersections={of=A and B, by={a}}, dashed]
    (0,0.8) node[left] {\SI{80}{\%}TTR\_PL}  -| (a |- 0,0) node[below] {$t*$};
\draw[dashed] (0,1)node[left] {TTR\_PLATEAU} -- + (5,0);
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

  • I put parameter no marks inside axis definition but it printed the marks anyway (see my answer). How can I get rid of them. – Cragfelt Dec 5 '17 at 10:15
  • 1
    @Cragfelt, hm, my image is drawn by code in answer. i check it again and it works as intended. last test with two small changes in code (curve is now in blue and thick) are put in answer. so you should have in your tests something different from code in answer. the same axis options i also use in the answer on your next question tex.stackexchange.com/questions/404465. – Zarko Dec 5 '17 at 12:35
  • @Zarko I have achieved plotting the axis with no ticks. I've just put xtick=\empty and ytick=\empty. Thank you for the tip. – Cragfelt Dec 12 '17 at 7:55
  • this you can see in my answer ... – Zarko Dec 12 '17 at 7:58
  • @Zarko and there is where I took it from. ;-) – Cragfelt Dec 12 '17 at 10:12
3

Too late

enter image description here

\documentclass{article}
\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.15}
\usepackage{physics}
\usepackage{amsmath, amssymb, amsfonts}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    xlabel={$t$},
    ylabel={$TTR$},
    axis lines=center,
    xtick={\empty},
    ytick={\empty},
    xmin=0,xmax=4.9,
    ymin=0,ymax=4.9,
    extra x ticks={1.6,0},
    extra y ticks={0.75,1.2},
    extra x tick labels={$t^*$},
    extra y tick labels={$80\%$~TTR\_PL, TTR\_PLATEAU},
    no marks,
]
\addplot +[mark=none,smooth,ultra thick] {1-e^(-x)};
\addplot[thick,dashed,domain=0:5] {1};
\addplot[thick,dashed] coordinates {(1.6,0) (1.6,0.7981)};
\addplot[thick,dashed] coordinates {(0,0.7981) (1.6,0.7981)};

\end{axis}
\end{tikzpicture}

\end{document}
0

A way of doing this with MetaPost and its intersectionpoint operator, for whom it may interest. Integrated in a LuaLaTeX program via the luamplib package.

\RequirePackage{luatex85}
\documentclass[border=3mm]{standalone}
\usepackage{luamplib}
    \mplibsetformat{metafun}
    \mplibtextextlabel{enable}
    \mplibnumbersystem{double}
\begin{document}
\begin{mplibcode}
    u = cm; v = 2cm; xmax = 4.9; ymax = 1.9; xstep = .1; 
    beginfig(1);
        % graph and intersection
        path graph; 
        graph = origin for t = xstep step xstep until xmax: .. (t, 1-exp(-t)) endfor;
        draw graph xyscaled (u, v) withcolor red;
        z = ((0, .8) -- (infinity, .8)) intersectionpoint graph;
        draw ((x, 0) -- z -- (0, y)) xyscaled (u, v) dashed evenly;
        draw (0, v) -- (xmax*u, v) dashed evenly;
        % Axes and labels
        drawarrow origin -- (xmax*u, 0);
        label.bot("$t^*$", (x*u, 0));
        label.bot("$t$", (xmax*u, 0));
        drawarrow origin -- (0, ymax*v);
        label.lft("\textsc{TTR\_PLATEAU}", (0, v));
        label.lft("\textsc{80~\%~TTR\_PL}", (0, .8v));
        label.lft("\textsc{TTR}", (0, ymax*v));
    endfig;
\end{mplibcode}
\end{document}

enter image description here

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.