2

I would like some help to get this plot:

enter image description here

Here is what I have so far:

\documentclass{article}
\usepackage{tikz,pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}
\usepackage{filecontents}

\begin{filecontents*}{data.csv}
x y
-4, 5.1
-3.95, 5
-3.95, 4.9
-3.95, 1
-3, 0.5
-3, -1.5
-2, -0.75
0.25, -0.75
1, -1
1.2, -0.75
1.5, -1
3, -0.25
\end{filecontents*}

\begin{filecontents*}{data2.csv}
x y
-4, 0.5
-3.95, 3
-2, 4
-1.5, 0.5
-0.5, 3.2
-0.7, -0.25
0.2, 0.1
0.3, -0.75
0.3, -1.85
0.45, 1
1.2, -0.75
1.35, -1.8
\end{filecontents*}

\begin{document}
\begin{tikzpicture}
  \begin{groupplot}[group style={group size=2 by 1},
%    ->=latex,
    xmin=-5.5,
    xmax=5.5,
    ymin=-6.5,
    ymax=6.5,
    height=4cm,
    width=5cm,
    xlabel={$x$},
    ylabel={$y$},
 %   xlabel style={below right},
 %   ylabel style={above left}
    ]
\nextgroupplot
\addplot [only marks,mark=x,red,mark options={scale=1}]table[x index=0,y index=1,col sep=comma, green, only marks] {data.csv};
\nextgroupplot
\addplot [only marks,mark=x,red,mark options={scale=1}]table[x index=0,y index=1,col sep=comma, green, only marks] {data2.csv};
\end{groupplot}
\end{tikzpicture}

\end{document}
6
  • 1
    Please place the result of your code and state the problems you're having.
    – CroCo
    Oct 9 '16 at 17:56
  • Your image shows 2 plots and a bunch of other stuff, but your code only seems to include one and you only seem to have one lot of data. Maybe the idea is obvious to you .... Right now, it looks like the problem is just that you haven't finished.
    – cfr
    Oct 10 '16 at 1:21
  • @cfr, I have added the second data and graph. Thanks.
    – Joe
    Oct 10 '16 at 2:26
  • @CroCo, I wanted some help to get the plot to look like the image that I have attached. Thanks.
    – Joe
    Oct 10 '16 at 2:27
  • Do you have formulas for the various lines you want to draw? Oct 10 '16 at 2:51
3

An approximation using some plots, some fine tuning might be desirable. I haven't added the arrow between the axes and some other stuff.

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.14}
\usepackage{filecontents}

\begin{filecontents*}{data.csv}
x y
-4, 5.1
-3.95, 5
-3.95, 4.9
-3.95, 1
-3, 0.5
-3, -1.5
-2, -0.75
0.25, -0.75
1, -1
1.2, -0.75
1.5, -1
3, -0.25
\end{filecontents*}

\begin{filecontents*}{data2.csv}
x y
-4, 0.5
-3.95, 3
-2, 4
-1.5, 0.5
-0.5, 3.2
-0.7, -0.25
0.2, 0.1
0.3, -0.75
0.3, -1.85
0.45, 1
1.2, -0.75
1.35, -1.8
\end{filecontents*}

\begin{document}
\begin{tikzpicture}
  \begin{groupplot}[group style={group size=2 by 1},
    xticklabels={},yticklabels={},
%    ->=latex,
    xmin=-5.5,
    xmax=5.5,
    ymin=-6.5,
    ymax=6.5,
    height=4cm,
    width=5cm,
    xlabel={$x$},
    ylabel={$y$},
 %   xlabel style={below right},
 %   ylabel style={above left}
    axis lines=center,axis equal,clip=false %%%% <---- Added
    ]
\nextgroupplot
\addplot [only marks,mark=x,red,mark options={scale=1}]table[x index=0,y index=1,col sep=comma, green, only marks] {data.csv};

\pgfplotsinvokeforeach{0,...,4}{
\addplot [xshift=#1*0.1cm,yshift=0.5cm-0.1*#1cm,red,thin,dotted,domain=-9+#1:0+#1,rotate around={10+20*#1:(axis cs:-3.5+#1,0)}] {((x+5-2*#1)/4)^2};
}

\nextgroupplot
\pgfplotsinvokeforeach{-2,-1,...,2}{
\addplot [thin,dotted,red,domain=-5-#1:5-#1] {x + 3*#1};
}
\addplot [-Stealth,thick,black,domain=-4:4] {-x};
\addplot [only marks,mark=x,red,mark options={scale=1}]table[x index=0,y index=1,col sep=comma, green, only marks] {data2.csv};
\end{groupplot}
\end{tikzpicture}

\end{document}
2

In the preamble I have added the backgrounds tikz library. Change de groupplots options to increase the horizontal sep (distance between the graphs). Add option to get rid of xlabel and xticks (respectively for ylabel and yticks). And see annotation after groupplot environnement. Of course it is an example.

\documentclass{article}
\usepackage{tikz,pgfplots}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{backgrounds}
\pgfplotsset{compat=newest}
\usepackage{filecontents}

\begin{filecontents*}{data.csv}
x y
-4, 5.1
-3.95, 5
-3.95, 4.9
-3.95, 1
-3, 0.5
-3, -1.5
-2, -0.75
0.25, -0.75
1, -1
1.2, -0.75
1.5, -1
3, -0.25
\end{filecontents*}

\begin{filecontents*}{data2.csv}
x y
-4, 0.5
-3.95, 3
-2, 4
-1.5, 0.5
-0.5, 3.2
-0.7, -0.25
0.2, 0.1
0.3, -0.75
0.3, -1.85
0.45, 1
1.2, -0.75
1.35, -1.8
\end{filecontents*}

\begin{document}
\begin{tikzpicture}
  \begin{groupplot}[group style={group size=2 by 1,horizontal sep=2cm},
    %->=latex,
    xmin=-5.5, xmax=5.5, ymin=-6.5, ymax=6.5,
    height=4cm, width=5cm,
    xlabel=\empty, ylabel=\empty,
    xtick =\empty, ytick =\empty,
 %   xlabel style={below right},
 %   ylabel style={above left},
    axis x line = middle,
    axis y line = middle,
    axis equal image,
    ]
\nextgroupplot[title=\emph{kernel PCA}]
\addplot [only marks,mark=x,red,mark options={scale=1}]table[x index=0,y index=1,col sep=comma, green, only marks] {data.csv};
\nextgroupplot
\addplot [only marks,mark=x,red,mark options={scale=1}]table[x index=0,y index=1,col sep=comma, green, only marks] {data2.csv};
\draw[>=stealth,->] (-4,4) -- (4,-4) node[right]{F}; % F arrow
\draw[dotted] (-4-1  ,-4+4) -- (4-1  ,4+4); 
\draw[dotted] (-4-0.5,-4+2) -- (4-0.5,4+2);
\draw[dotted] (-4-0  ,-4+0) -- (4-0  ,4+0);
\draw[dotted] (-4+0.5,-4-2) -- (4+0.5,4-2);
\draw[dotted] (-4+1  ,-4-4) -- (4+1  ,4-4);
\end{groupplot}
\draw[] (3,0.25) node[]{$k(\textbf{x},\textbf{y})=(\textbf{x}\cdot \textbf{y})^d$};
\draw[very thick,dashed,>=stealth,->] (2,2) node[left,above]{$\textbf{R}^2$} -- (4,2) node[midway,below]{$\Phi$};

\begin{pgfonlayer}{background}
  \filldraw [line width=4mm,join=round,black!10] (0,0) rectangle (6,3);
\end{pgfonlayer}

\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.