3

I'm trying to put automatically label several plots. For this purpose, I just discover the pin option to add it to the plots.

This solution works rather well, and semi-automatically. However, when you redefine the axis (by setting xmin, xmax, ymin, and ymax) the position stops working, as the labels appear in the original position not the clipped one.

So, how can I make the pin and pos keywords work within the defined axis instead of the original domain?

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\pagestyle{empty}

\begin{document}
\begin{tikzpicture}
\pgfplotsset{
    every axis plot post/.append style=
        {mark=none}}

\begin{axis}[
  xmin=-10, xmax=10,
  ymin=-10, ymax=10,
  domain=-10:10,
    ]
\addplot {1.690476*x+0.238095} node [pos=1,pin={above left:{$1$}},inner sep=0pt] {};
\addplot {-57.000000*x+-20.000000} node [pos=1,pin={above left:{$2$}},inner sep=0pt] {};
\addplot {-0.590909*x+-0.113636} node [pos=1,pin={above left:{$3$}},inner sep=0pt] {};
\end{axis}
\end{tikzpicture}
\end{document}

Custom axis

enter image description here

No axis defined

enter image description here

  • Perhaps this answer can help, the restrict y to domain option restricts drawing the graph instead of just clipping part of it by restricting the axis. – hugovdberg Apr 11 '14 at 13:39
  • The problem is that doesn't show the line with extreme values (such as the red plot). – adn Apr 11 '14 at 14:02
  • What do you mean doesn't show the line? If you restrict the y domain to -10:10 it should still show that part of the line, just as setting the ymin and ymax would. If not then perhaps you should post a question why restrict y to domain doesn't work as expected. – hugovdberg Apr 11 '14 at 14:05
2

I think I understand your problem with restrict y to domain now, with the default amount of samples no data is actually produced in that y-domain. The simplest solution is to manually specify a different x-domain for that function and/or increase the sampling frequency so the plot is visible also with a restricted y-domain.

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\pagestyle{empty}

\begin{document}
\begin{tikzpicture}
\pgfplotsset{
  every axis plot post/.append style=
  {mark=none}}

  \begin{axis}[
  restrict y to domain=-10:10,
  domain=-10:10,
  ]
  \addplot {1.690476*x+0.238095} node [pos=1,pin={below right:{$1$}},inner sep=0pt] {};
  \addplot[samples=200,domain=-1:0] {-57.000000*x+-20.000000} node [pos=1,pin={above left:{$2$}},inner sep=0pt] {};
  \addplot {-0.590909*x+-0.113636} node [pos=1,pin={above left:{$3$}},inner sep=0pt] {};
\end{axis}
\end{tikzpicture}
\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.