2
\begin{tikzpicture}
   \begin{axis}[
        axis x line = center,
        axis y line = center,
        xmin        = -3.0,
        xmax        =  5.0,
        ymin        = -3.0,
        ymax        =  5.0]
        \addplot[
            domain = 0.1:5.0,
        ] {1/x};
    \end{axis}
    
    \foreach \Point/\PointLabel in {(4,4)/x_0, (3,1)/B, (1,4)/P_1, (3,4)/P_1}
    \draw[fill=black] \Point circle (0.05) node[above right] {$\PointLabel$};
\end{tikzpicture}

The code above will generate the following graph:

enter image description here

I was trying to add the text x0 around the point (1,1) in the axis environment. But it seems that the coordinate system between the axis environment and the tikzpicture is different.

Could you help me with explaining the environment misalignment problem?

And how to put the x0 label at the (1,1) coordinate under the axis environment in an elegant way?

6
  • 2
    Inside the axis environment one can use \coordinate (A) at (axis cs: 4,4}; to define a global coordinate, then use \draw (A) etc outside the axis environment. May 24, 2021 at 23:02
  • @JohnKormylo: Do not use axis cs: explicitly - it has been default since long time ago. Jan 22, 2023 at 10:20
  • If you really really want to learn about the relationship between coordinates inside and outside the axis then there is chapter 4.26 in the manual or see e.g. tex.stackexchange.com/a/667195/8650 Jan 22, 2023 at 10:31
  • @hpekristiansen, I don't trust defaults, especially ones which change. In C, after int was redefined from short to long, I stopped using int altogether. Jan 22, 2023 at 16:26
  • @JohnKormylo: The default for a specific compat level does not change. I can only say that you should not write it - it is a bad habit that is perpetuated by old posts on this site. Jan 22, 2023 at 17:26

2 Answers 2

2

The points P_1, P_2, B and x_o˙I would draw wit separate addplot function with options only marks, nodes near coords, and point meta=explicit symbolic:

enter image description here

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

\begin{document}
    \begin{tikzpicture}
\begin{axis}[
axis lines = center,
xmin = -3.0,    xmax = 5.0,
ymin = -3.0,    ymax = 5.0,
            ]
%
\addplot [domain = 0.1:5.0, samples=50] {1/x};
\addplot [only marks, mark=*,           % <---
          nodes near coords,            % <--- 
          point meta=explicit symbolic] % <---
          coordinates {(1,1) [$x_0$]    % given coordinate
                       (1,-2)[$B$]      % coordinate estimated from your picture
                       (1,4) [$P_1$]    % <---
                       (-2,4)[$P_1$]};  % <---
\end{axis}
    \end{tikzpicture}
\end{document}

Used coordinates (except for x_0) I estimated from your image in question. If needed, correct their positions as you like to have.

1

The better methode is in answer by @Zarko. You can also just create your points as you are doing, but inside axis. The only thing is that you can not use foreach in that way. If you need a loop, you need to use \pgfplotsinvokeforeach and friends - see manual chapter 8.1.

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=center,
xmin=-3.0, xmax=5.0,
ymin=-3.0, ymax=5.0,
]
\addplot[domain=0.1:5.0, samples=50, smooth] {1/x};
\fill (1,1) circle[radius=0.05] node[above right] {$x_0$};
\end{axis}
\end{tikzpicture}
\end{document}

Graph with curve and a single point

You must log in to answer this question.

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