3

I'd like to plot a curve, for example y=1-e^{-x}, mapping the values 1,2... of x axis on x1,x2... and the values 1,2... of y axis on y1,y2...

I know only how define symbolic axis values:

\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={$x$},
        ylabel={$y$},
        axis lines=center,
        symbolic x coords={0,$x_1$, $x_2$, $x_3$, $x_4$},
        xmin={[normalized]0},
        xmax={[normalized]5},
        xtickmax={[normalized]4},
        xtick distance=1,
        symbolic y coords={0,$y_1$, $y_2$, $y_3$, $y_4$},
        ymin={[normalized]0},
        ymax={[normalized]5},
        ytickmax={[normalized]4},
        ytick distance=1]
    \end{axis}
\end{tikzpicture}

\end{document}

Thank you in advance.

4

Instead of using symbolic coordinates you can change the ticklabels. Below I kept xtick distance/ytick distance from your code, but I removed everything related to symbolic coordinates, and set

xticklabel={$x_{\pgfmathprintnumber[precision=0]{\tick}}$},     
yticklabel={$y_{\pgfmathprintnumber[precision=0]{\tick}}$}

to make the ticklabels as you said.

output of code

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

\begin{document}

\begin{tikzpicture}
\begin{axis}[
        xlabel={$x$},
        ylabel={$y$},
        axis lines=center,
        xtick distance=1,
        ytick distance=1,
        xmin=0,xmax=5,
        ymin=0,ymax=5,
        xticklabel={$x_{\pgfmathprintnumber[precision=0]{\tick}}$},
        yticklabel={$y_{\pgfmathprintnumber[precision=0]{\tick}}$}
]

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

\end{axis}
\end{tikzpicture}

\end{document}
  • Hello @Torbjørn T. Is it possible to get a smooth curve without samples? – Gennaro Arguzzi Dec 3 '17 at 18:22
  • @GennaroArguzzi Without markers, you mean? \addplot +[mark=none,samples=50] {1-e^(-x)};? – Torbjørn T. Dec 3 '17 at 18:32
  • Fantastic solution @Torbjørn T. – Gennaro Arguzzi Dec 3 '17 at 19:52
  • How can I remove the last tick on the axis? – Gennaro Arguzzi Dec 3 '17 at 19:58
  • @GennaroArguzzi You could set xmax=4.9 instead of xmax=5. Another option is to use xtick={0,...,4} instead of xtick distance=1. Similar for y. – Torbjørn T. Dec 3 '17 at 20: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.