0

I want to know the x value and the y value on a pgfplot area to draw a line. How to find it?

For an example, I need to draw a line from the X label to the Y label; to do so I need to get the x value and the y value of the labels to fill the \pslineoptions thing.

I am using Texmaker + Miktex.

screenshot of the texmaker window

My workspace screen hot

MWE

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{pgfplots}\pgfplotsset{compat=1.18}

\author{Some dude's name}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
    xlabel={x}, 
    ylabel={y}, 
    grid, 
    ticks=none
]
\addplot3[blue, no marks, surf, domain=0:1, samples=50] {25-5*x*x -y*y};

\end{axis}
\end{tikzpicture}
\end{document}
9
  • Please don't post only a screenshot as a MWE. No one has the time to re-write the entire code to test it. Please edit your post by adding your complete MWE.
    – SebGlav
    Jul 27, 2021 at 10:29
  • @SebGlav well it is not about coding, it is about the interface/interacting in texmaker. Jul 27, 2021 at 10:30
  • @SebGlav There is no need to do coding to answer my question, I am asking a way finding the x value and y value Jul 27, 2021 at 10:31
  • @SebGlav anyway, i am going to edit the question... Jul 27, 2021 at 10:32
  • What do you mean by x value and y value? In wich coordinate system? If you need a line, why don't you draw it directly in the graph ? (\draw and all TikZ commands work in pgfplots)
    – Rmano
    Jul 27, 2021 at 11:06

1 Answer 1

1

You can use normal TikZ commands in pgfplots; the only problem is to identify which coordinate system you want and avoid clipping if you need it.

In the case of 3d graphs, the relevant part is around page 359 of the manual. You have to take care of precedence yourself to avoid the line above the graph, if needed...

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{pgfplots}\pgfplotsset{compat=1.18}

\author{Some dude's name}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
    xlabel={x},
    ylabel={y},
    grid,
    ticks=none,
    % clip mode=individual,
]

\draw [thick, blue] (rel axis cs:0.5,0,0) -- (rel axis cs:0.5,1,0);
\addplot3[blue, no marks, surf, domain=0:1, samples=10] {25-5*x*x -y*y};
\draw [thick, red] (rel axis cs:0.5,0,0) -- (rel axis cs:1,0.5,0);

\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

PD notice that \usepackage[utf8]{inputenc} is default since 2018 and not needed, but you probably want \usepackage[T1]{fontenc}...

10
  • You are a precious stone!!! thank you. Thanks. You couldn't find a way to get the x value and the y value of the labels or some point? Jul 27, 2021 at 11:32
  • how to customize the (rel axis cs:0.5,0,0) -- (rel axis cs:0.5,1,0) in the \draw thing to get my own positions? Jul 27, 2021 at 11:37
  • So... \draw worls like in css; first line = loaded first, Am I correct? Jul 27, 2021 at 11:43
  • It's quite complex (no idea of CSS myself). I suggest you take the first tutorial in the TikZ manual (I know, it's a 1000+ pages manual, but hey...)
    – Rmano
    Jul 27, 2021 at 11:47
  • what i said is that first \draw prints first second \draw prints second. Am I correct? Jul 27, 2021 at 12:03

You must log in to answer this question.

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