2

This is a follow-up question to this question. Thanks to the answers given there I have the following code now

\documentclass{beamer}
\usetheme{metropolis} % Use metropolis theme
\usepackage[english,ngerman]{babel} % the new way
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}
\begin{figure}[!htb]
        \vspace{-0.5cm}
        \centering
        \begin{tikzpicture}
        \begin{axis}[
        xmin=-6.067, xmax=6.433,
        ymin=-1.3,ymax=2.2,
        scatter/classes={a={mark=o,draw=black}},
        xlabel={$x$},
        ylabel={$y$},
        scale=0.9
        ]

        \addplot[scatter,only marks,mark size = 1pt,fill = red,scatter src=explicit symbolic]
        table {
            % some points go here...
        };

        \addplot [|->, thick,  black]
        coordinates { (0,0) (3,1)};

        \addplot [|->, thick,  black]
        coordinates { (0,0) (-0.3,1)};
        \end{axis}

        \end{tikzpicture}
    \end{figure}
\end{document}

producing this output (please note that the missing arrow of the second vector seems to be a result of the Overleaf PDF export and is actually present in the preview): enter image description here

Now I would like to achieve the following:

  1. I would like to remove the vertical line at the start point of each vector.
  2. I would like to extend each vector such that they actually "touch" the axes of my plot (see the thin lines I added to the plot).

Any help is, as always, highly appreciated.

2
  • And what is stopping you? If you want to use Tikz/pgfplots, you need to have at least a basic understanding of what the code is doing. Arrows/line ends are defined in the addplot options (the square brackets) and the endpoints of your lines/vectors are defined by coordinates. Just change them according to what you want to achieve. You have already drawn in your thin lines (although I don't see the code that generates them), it should be easy to read off the coordinates.
    – Huang_d
    Jun 11, 2018 at 9:46
  • I "drew" those lines using Paint. You are right that I can simply look at the graph and use some hard numbers but I was under the impression that there is a nicer and cleaner way to do this by using some scaling option.
    – Hagbard
    Jun 11, 2018 at 10:06

1 Answer 1

0

I actually managed to solved this by simply adding a scaling factor and additional vectors with opposite signs:

    [...]
    \addplot [-, thick,  black, dashed]
    coordinates { (0,0) (2.2*3,2.2*1)};

    \addplot [-, thick,  black, dashed]
    coordinates { (0,0) (2.2*-3,2.2*-1)};

    \addplot [-, thick,  black, dashed]
    coordinates { (0,0) (2.2*-0.3,2.2*1)};

    \addplot [-, thick,  black, dashed]
    coordinates { (0,0) (2.2*0.3,2.2*-1)};

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.