2

I am trying to graph y=e^(1/x) using PGF/TikZ.

I have been unsuccessful in solving the following three problems:

  1. I want the axis labels to look nice

I want the y-axis label to be at the top right of the y-axis like in a book

Similarly, I want the x-axis label to be at the bottom right of the x-axis

Currently, they are not in these places, and do not look "nice"

  1. I would like to make the discontinuity smaller, so it is more aesthetically pleasing.

  2. How do I remove the tick marks on the y-axis?

Below is a short executable example. I removed a lot of the extra packages, but some are present; I didn't feel fully confident going in and making big changes to these parts of the preamble.

Thank you very much for taking the time to help me get past these roadblocks, and for overlooking some of the not-so-minimal parts of the following code.

\documentclass{article}
\usepackage[utf8]{inputenc}

%maths
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}

%tikzpicture
\usepackage{tikz}
\usepackage{scalerel}
\usepackage{pict2e}
\usepackage{tkz-euclide}

\usetikzlibrary{calc}
\usetikzlibrary{patterns,arrows.meta}
\usetikzlibrary{shadows}
\usetikzlibrary{external}
\usetikzlibrary{decorations.markings}

%pgfplots
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{statistics}
\usepgfplotslibrary{fillbetween}

\pgfplotsset{
    standard/.style={
    axis line style = thick,
    trig format=rad,
    enlargelimits,
    axis x line=middle,
    axis y line=middle,
    enlarge x limits=0.15,
    enlarge y limits=0.15,
    every axis x label/.style={at={(current axis.right of origin)},anchor=north west}
    every axis y label/.style={at={(current axis.above origin)},anchor=south east}
    grid=both,
    ticklabel style={font=\tiny,fill=white}
    }
}

\begin{document}
      \begin{tikzpicture}
    \begin{axis}[
    %standard,
    xmin=-2, xmax=4,
    ymin=-2,ymax=4,
    axis lines=middle,
    xtick={-1/2},
    ytick={},
    yticklabels={},
    xticklabels={$-\frac{1}{2}$},
    %ticks=none,
    x label style={at={(ticklabel cs:1)},anchor=north},
    y label style={at={(ticklabel cs:1)},rotate=0,anchor=west},
    xlabel={$x$},
    ylabel={$y$}]
    %\clip (-2,-2) rectangle (4,2);
    \addplot [
        domain=-2:-0.51, 
        samples=100, 
        color=black]
    {e^(1/x)};
    \addplot[mark=*, fill=black, forget plot] coordinates{(-0.5,0.136)};
    \addplot [
        domain=-0.49:-0.1, 
        samples=100, 
        color=black]
    {e^(1/x)};
    \addplot[mark=*, fill=white, forget plot] coordinates{(0,0)};
    \addplot [
        domain=0.1:4, 
        samples=100, 
        color=black]
    {e^(1/x)};
    \path[draw,dashed] (-2,1) -- (4,1);
    \end{axis}
    \end{tikzpicture}
\end{document}
1
  • Welcome to TeX.SE!
    – Mensch
    Oct 1 at 20:11

1 Answer 1

4
  • your document example is not minimal, in preamble are loaded many unrelated package and defined unrelated commands. In my MWE I remove all of them,
  • you have many questions, you should focused to one only ...
  • it is not entirely clear, what you after, so I guess, that you looking for something like this:

enter image description here

This figure is produced by the following MWE (Minimal Working Example, a small but complete, compilable document):

\documentclass[border=3.141592]{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
%\usepgfplotslibrary{statistics}    % not used in this example
%\usepgfplotslibrary{fillbetween}   % not used in this example

\pgfplotsset{compat=1.18}

\begin{document}
      \begin{tikzpicture}
    \begin{axis}[
    axis lines=middle,
    ymin=-1, ymax=10, 
    xtick={-1/2},
    ytick=\empty,  % <--- changed
    xlabel={$x$},   
    ylabel={$y$},   
    tick label style={font=\footnotesize},
    label style={below left},
    restrict y to domain=-2:100,    % <------ added
    samples=200,
    every axis plot post/.append style={very thick},
        ]
    \addplot [domain=-2:4] {e^(1/x)};
    \path[draw,dashed] (-2,1) -- (4,1);
    \end{axis}
    \end{tikzpicture}
\end{document}
7
  • pgfplotstable is not needed Oct 2 at 0:07
  • @hpekristiansen, you are right. Corrected now.
    – Zarko
    Oct 2 at 6:18
  • Good day, Zarko, thank you for taking the time to let me know about your experience regarding my MWE. I greatly appreciate you sharing your feedback. Again, I understand your frustration, and I sincerely apologize for any inconvenience I have caused you. Oct 2 at 6:19
  • @Tyler, you are welcome! Does my answer solve your problem? If yes, you may consider to accept it (by clicking on check mark at tope left side of the answer).
    – Zarko
    Oct 2 at 6:29
  • I am grateful to you for taking the time to read and answer my question, as well as make suggestions. The axis labels are in the right spot and the ticks are gone. I still need to figure out how to scale down the discontinuity notation, but I'll try to figure that out myself. Thanks! Oct 2 at 6:41

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.