Marks do not appear in 3D for 3D scatter plot
I am trying a 3d scatter plot as below, however marks are circles, appearing only in 2D always whichever view I choose. I want them to be flat on the X-Y plane. Please let me know how to do it. I tried "set layers" but that is pushing my entire graph down, behind next section's text. I think even the red line does the same, not giving me proper 3d perspective.
MWE:
documentclass{article}
usepackage{tikz}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{math, decorations.pathreplacing,angles,quotes,bending, arrows.meta}
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
makeatletter
pgfdeclareplotmark{dot}
{%
fill circle [x radius=0.02, y radius=0.08];
}%
makeatother
begin{document}
section{table using raw data in 3D}
The below diagram tries to replicate in 3D, the Figure 12.3 found in cite{devore} , page 472 \
% https://tex.stackexchange.com/questions/11251/trend-line-or-line-of-best-fit-in-pgfplots
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
addplot3[only marks, fill=cyan,mark=*] table {datatable};
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
node[above] at (X,4) {$x_1$};
node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
begin{thebibliography}{1}
bibitem{devore} Jay. L Devore {em Probability and Statistics for Engineering and the Sciences} 8th Edition.
end{thebibliography}
end{document}
Output:
tikz-pgf pgfplots 3d tikz-3d
add a comment |
I am trying a 3d scatter plot as below, however marks are circles, appearing only in 2D always whichever view I choose. I want them to be flat on the X-Y plane. Please let me know how to do it. I tried "set layers" but that is pushing my entire graph down, behind next section's text. I think even the red line does the same, not giving me proper 3d perspective.
MWE:
documentclass{article}
usepackage{tikz}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{math, decorations.pathreplacing,angles,quotes,bending, arrows.meta}
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
makeatletter
pgfdeclareplotmark{dot}
{%
fill circle [x radius=0.02, y radius=0.08];
}%
makeatother
begin{document}
section{table using raw data in 3D}
The below diagram tries to replicate in 3D, the Figure 12.3 found in cite{devore} , page 472 \
% https://tex.stackexchange.com/questions/11251/trend-line-or-line-of-best-fit-in-pgfplots
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
addplot3[only marks, fill=cyan,mark=*] table {datatable};
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
node[above] at (X,4) {$x_1$};
node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
begin{thebibliography}{1}
bibitem{devore} Jay. L Devore {em Probability and Statistics for Engineering and the Sciences} 8th Edition.
end{thebibliography}
end{document}
Output:
tikz-pgf pgfplots 3d tikz-3d
If I look at your table, in every row the third entry is zero. Isn't that the z coordinate? What I want to say is that it is not too surprising that the circles are all in the x-y plane. So I think the points are correct, i.e. represent the data. Note that this is not a scatter plot in the strict sense since there is no scatter directive. Note also that you may dropmakeatletter
andmakeatother
.
– marmot
Oct 21 '18 at 17:15
If you could post the original figure from the book you cite, it will be easier to help. Most people here won't have access to it.
– BambOo
Oct 21 '18 at 17:29
@marmot I have added a new question here. can you please check out. Its continuation from this problem.
– Parthiban Rajendran
Oct 22 '18 at 8:38
add a comment |
I am trying a 3d scatter plot as below, however marks are circles, appearing only in 2D always whichever view I choose. I want them to be flat on the X-Y plane. Please let me know how to do it. I tried "set layers" but that is pushing my entire graph down, behind next section's text. I think even the red line does the same, not giving me proper 3d perspective.
MWE:
documentclass{article}
usepackage{tikz}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{math, decorations.pathreplacing,angles,quotes,bending, arrows.meta}
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
makeatletter
pgfdeclareplotmark{dot}
{%
fill circle [x radius=0.02, y radius=0.08];
}%
makeatother
begin{document}
section{table using raw data in 3D}
The below diagram tries to replicate in 3D, the Figure 12.3 found in cite{devore} , page 472 \
% https://tex.stackexchange.com/questions/11251/trend-line-or-line-of-best-fit-in-pgfplots
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
addplot3[only marks, fill=cyan,mark=*] table {datatable};
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
node[above] at (X,4) {$x_1$};
node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
begin{thebibliography}{1}
bibitem{devore} Jay. L Devore {em Probability and Statistics for Engineering and the Sciences} 8th Edition.
end{thebibliography}
end{document}
Output:
tikz-pgf pgfplots 3d tikz-3d
I am trying a 3d scatter plot as below, however marks are circles, appearing only in 2D always whichever view I choose. I want them to be flat on the X-Y plane. Please let me know how to do it. I tried "set layers" but that is pushing my entire graph down, behind next section's text. I think even the red line does the same, not giving me proper 3d perspective.
MWE:
documentclass{article}
usepackage{tikz}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{math, decorations.pathreplacing,angles,quotes,bending, arrows.meta}
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
makeatletter
pgfdeclareplotmark{dot}
{%
fill circle [x radius=0.02, y radius=0.08];
}%
makeatother
begin{document}
section{table using raw data in 3D}
The below diagram tries to replicate in 3D, the Figure 12.3 found in cite{devore} , page 472 \
% https://tex.stackexchange.com/questions/11251/trend-line-or-line-of-best-fit-in-pgfplots
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
addplot3[only marks, fill=cyan,mark=*] table {datatable};
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
node[above] at (X,4) {$x_1$};
node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
begin{thebibliography}{1}
bibitem{devore} Jay. L Devore {em Probability and Statistics for Engineering and the Sciences} 8th Edition.
end{thebibliography}
end{document}
Output:
tikz-pgf pgfplots 3d tikz-3d
tikz-pgf pgfplots 3d tikz-3d
edited Jan 15 at 19:25
Stefan Pinnow
19.7k83275
19.7k83275
asked Oct 21 '18 at 16:45
Parthiban RajendranParthiban Rajendran
3387
3387
If I look at your table, in every row the third entry is zero. Isn't that the z coordinate? What I want to say is that it is not too surprising that the circles are all in the x-y plane. So I think the points are correct, i.e. represent the data. Note that this is not a scatter plot in the strict sense since there is no scatter directive. Note also that you may dropmakeatletter
andmakeatother
.
– marmot
Oct 21 '18 at 17:15
If you could post the original figure from the book you cite, it will be easier to help. Most people here won't have access to it.
– BambOo
Oct 21 '18 at 17:29
@marmot I have added a new question here. can you please check out. Its continuation from this problem.
– Parthiban Rajendran
Oct 22 '18 at 8:38
add a comment |
If I look at your table, in every row the third entry is zero. Isn't that the z coordinate? What I want to say is that it is not too surprising that the circles are all in the x-y plane. So I think the points are correct, i.e. represent the data. Note that this is not a scatter plot in the strict sense since there is no scatter directive. Note also that you may dropmakeatletter
andmakeatother
.
– marmot
Oct 21 '18 at 17:15
If you could post the original figure from the book you cite, it will be easier to help. Most people here won't have access to it.
– BambOo
Oct 21 '18 at 17:29
@marmot I have added a new question here. can you please check out. Its continuation from this problem.
– Parthiban Rajendran
Oct 22 '18 at 8:38
If I look at your table, in every row the third entry is zero. Isn't that the z coordinate? What I want to say is that it is not too surprising that the circles are all in the x-y plane. So I think the points are correct, i.e. represent the data. Note that this is not a scatter plot in the strict sense since there is no scatter directive. Note also that you may drop
makeatletter
and makeatother
.– marmot
Oct 21 '18 at 17:15
If I look at your table, in every row the third entry is zero. Isn't that the z coordinate? What I want to say is that it is not too surprising that the circles are all in the x-y plane. So I think the points are correct, i.e. represent the data. Note that this is not a scatter plot in the strict sense since there is no scatter directive. Note also that you may drop
makeatletter
and makeatother
.– marmot
Oct 21 '18 at 17:15
If you could post the original figure from the book you cite, it will be easier to help. Most people here won't have access to it.
– BambOo
Oct 21 '18 at 17:29
If you could post the original figure from the book you cite, it will be easier to help. Most people here won't have access to it.
– BambOo
Oct 21 '18 at 17:29
@marmot I have added a new question here. can you please check out. Its continuation from this problem.
– Parthiban Rajendran
Oct 22 '18 at 8:38
@marmot I have added a new question here. can you please check out. Its continuation from this problem.
– Parthiban Rajendran
Oct 22 '18 at 8:38
add a comment |
1 Answer
1
active
oldest
votes
UPDATE: A version without hardcoded values. (Note that I use a not entirely harmless command: globaldefs
. The alternative will be longer. I believe that here using globaldefs
is OK.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{3d,calc,decorations.pathreplacing,arrows.meta}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
makeatletter
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane}
makeatother
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
pgfplotstableread{
X Y Z m
2.2 0 0 0
2.7 0 0 0
3 13 0 0
3.55 0 0 0
4 15 0 0
4.5 0 0 0
4.75 0 0 0
5.5 0 0 0
}datatabletwo
pgfdeclareplotmark{fcirc}{%
begin{scope}[expand style={local frame}{MyLocalFrame},local frame]
begin{scope}[canvas is xy plane at z=0,transform shape]
fill circle(0.1);
end{scope}
end{scope}
}%
% based on https://tex.stackexchange.com/a/64237/121799
tikzset{expand style/.code n args={2}{tikzset{#1/.style/.expanded={#2}}}}
newcommand{GetLocalFrame}{
path let p1=($(1,0,0)-(0,0,0)$), p2=($(0,1,0)-(0,0,0)$),
p3=($(0,0,1)-(0,0,0)$) in pgfextra{
pgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
xdefMyLocalFrame{
x = { (x1,y1) },
y = { (ratio*x2,ratio*y2) },
z = { (x3,y3) }
}
}; }
begin{document}
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
% read out the transformation done by pgfplots
GetLocalFrame
begin{scope}[transform shape]
addplot3[only marks, fill=cyan,mark=fcirc]
table {datatable};
end{scope}
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
node[above] at (X,4) {$x_1$};
node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
end{document}
Old ANSWE: This is not an answer but just to show you what you get if do the projection.
documentclass{article}
usepackage{tikz}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{3d,calc}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
makeatletter
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane}
makeatother
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
pgfplotstableread{
X Y Z m
2.2 0 0 0
2.7 0 0 0
3 13 0 0
3.55 0 0 0
4 15 0 0
4.5 0 0 0
4.75 0 0 0
5.5 0 0 0
}datatabletwo
%makeatletter
pgfdeclareplotmark{dot}
{%
fill circle [x radius=0.02, y radius=0.08];
}%
%makeatother
pgfdeclareplotmark{fcirc}
{%
begin{scope}[x={(-21.20514pt,-9.26361pt)},
y={(2.54181pt,-1.57715pt)},z={(0.0pt,6.04706pt)}]
begin{scope}[canvas is xy plane at z=0,transform shape]
fill circle(0.1);
end{scope}
end{scope}
}%
begin{document}
section{table using raw data in 3D}
The below diagram tries to replicate in 3D, the Figure 12.3 found in cite{devore} , page 472 \
% https://tex.stackexchange.com/questions/11251/trend-line-or-line-of-best-fit-in-pgfplots
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
% read out the transformation done by pgfplots
path let p1=($(1,0,0)-(0,0,0)$), p2=($(0,1,0)-(0,0,0)$),
p3=($(0,0,1)-(0,0,0)$) in pgfextra{typeout{
x1,y1;x2,y2;x3,y3}};
begin{scope}[transform shape]
addplot3[only marks, fill=cyan,mark=fcirc]
table {datatable};
end{scope}
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
% draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
% draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
% draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
%
% draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
% draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
% node[above] at (X,4) {$x_1$};
% node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
begin{thebibliography}{1}
bibitem{devore} Jay. L Devore {em Probability and Statistics for Engineering and the Sciences} 8th Edition.
end{thebibliography}
end{document}
The circles are now properly projected on the x-y plane but, unfortunately, since the x and y scales look very different, they look like ellipse. Is that what you want?
On the other hand, if you want to cancel out the elliptic distortion, you can do that by cheating:
documentclass{article}
usepackage{tikz}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{3d,calc,decorations.pathreplacing,arrows.meta}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
makeatletter
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane}
makeatother
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
pgfplotstableread{
X Y Z m
2.2 0 0 0
2.7 0 0 0
3 13 0 0
3.55 0 0 0
4 15 0 0
4.5 0 0 0
4.75 0 0 0
5.5 0 0 0
}datatabletwo
%makeatletter
pgfdeclareplotmark{dot}
{%
fill circle [x radius=0.02, y radius=0.08];
}%
%makeatother
pgfdeclareplotmark{fcirc}
{%
begin{scope}[x={(-21.20514pt,-9.26361pt)},
y={(7.73369*2.54181pt,-7.73369*1.57715pt)},z={(0.0pt,6.04706pt)}]
begin{scope}[canvas is xy plane at z=0,transform shape]
fill circle(0.1);
end{scope}
end{scope}
}%
begin{document}
section{table using raw data in 3D}
The below diagram tries to replicate in 3D, the Figure 12.3 found in cite{devore} , page 472 \
% https://tex.stackexchange.com/questions/11251/trend-line-or-line-of-best-fit-in-pgfplots
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
% read out the transformation done by pgfplots
path let p1=($(1,0,0)-(0,0,0)$), p2=($(0,1,0)-(0,0,0)$),
p3=($(0,0,1)-(0,0,0)$) in pgfextra{
pgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
typeout{
x1,y1;x2,y2;x3,y3;ratio}};
begin{scope}[transform shape]
addplot3[only marks, fill=cyan,mark=fcirc]
table {datatable};
end{scope}
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
node[above] at (X,4) {$x_1$};
node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
begin{thebibliography}{1}
bibitem{devore} Jay. L Devore {em Probability and Statistics for Engineering and the Sciences} 8th Edition.
end{thebibliography}
end{document}
Unfortunately, because of the way pgfplots works, you need to run this, find out the transformation and the "cheating scale" ratio
, and then plug this in the definition of fcircle
in case you make any changes.
why was the distortion earlier? because they scales are not equal for x and y?
– Parthiban Rajendran
Oct 21 '18 at 17:59
@BambOo It is just the ratio of lengths of unit vectors inx
andy
direction, which gets computed inpgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
in my code.
– marmot
Oct 21 '18 at 17:59
@PaariVendhan Precisely. Forget about 3D and just draw a circle in a plane in which the y scale is, say, 3 times the x scale. You'll get an ellipse, which is also what happens in my upper plot. By computingpgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
and installing it I make these scales equal in the local frame in which the circles are drawn.
– marmot
Oct 21 '18 at 18:00
But I wonder why this squeezing was not happening in 2D scale as my another example here
– Parthiban Rajendran
Oct 21 '18 at 18:03
1
For the record: Jake's patch is now incorporated in v3.1 of TikZ.
– Stefan Pinnow
Jan 15 at 19:25
|
show 11 more comments
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f456138%2fmarks-do-not-appear-in-3d-for-3d-scatter-plot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
UPDATE: A version without hardcoded values. (Note that I use a not entirely harmless command: globaldefs
. The alternative will be longer. I believe that here using globaldefs
is OK.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{3d,calc,decorations.pathreplacing,arrows.meta}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
makeatletter
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane}
makeatother
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
pgfplotstableread{
X Y Z m
2.2 0 0 0
2.7 0 0 0
3 13 0 0
3.55 0 0 0
4 15 0 0
4.5 0 0 0
4.75 0 0 0
5.5 0 0 0
}datatabletwo
pgfdeclareplotmark{fcirc}{%
begin{scope}[expand style={local frame}{MyLocalFrame},local frame]
begin{scope}[canvas is xy plane at z=0,transform shape]
fill circle(0.1);
end{scope}
end{scope}
}%
% based on https://tex.stackexchange.com/a/64237/121799
tikzset{expand style/.code n args={2}{tikzset{#1/.style/.expanded={#2}}}}
newcommand{GetLocalFrame}{
path let p1=($(1,0,0)-(0,0,0)$), p2=($(0,1,0)-(0,0,0)$),
p3=($(0,0,1)-(0,0,0)$) in pgfextra{
pgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
xdefMyLocalFrame{
x = { (x1,y1) },
y = { (ratio*x2,ratio*y2) },
z = { (x3,y3) }
}
}; }
begin{document}
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
% read out the transformation done by pgfplots
GetLocalFrame
begin{scope}[transform shape]
addplot3[only marks, fill=cyan,mark=fcirc]
table {datatable};
end{scope}
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
node[above] at (X,4) {$x_1$};
node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
end{document}
Old ANSWE: This is not an answer but just to show you what you get if do the projection.
documentclass{article}
usepackage{tikz}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{3d,calc}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
makeatletter
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane}
makeatother
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
pgfplotstableread{
X Y Z m
2.2 0 0 0
2.7 0 0 0
3 13 0 0
3.55 0 0 0
4 15 0 0
4.5 0 0 0
4.75 0 0 0
5.5 0 0 0
}datatabletwo
%makeatletter
pgfdeclareplotmark{dot}
{%
fill circle [x radius=0.02, y radius=0.08];
}%
%makeatother
pgfdeclareplotmark{fcirc}
{%
begin{scope}[x={(-21.20514pt,-9.26361pt)},
y={(2.54181pt,-1.57715pt)},z={(0.0pt,6.04706pt)}]
begin{scope}[canvas is xy plane at z=0,transform shape]
fill circle(0.1);
end{scope}
end{scope}
}%
begin{document}
section{table using raw data in 3D}
The below diagram tries to replicate in 3D, the Figure 12.3 found in cite{devore} , page 472 \
% https://tex.stackexchange.com/questions/11251/trend-line-or-line-of-best-fit-in-pgfplots
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
% read out the transformation done by pgfplots
path let p1=($(1,0,0)-(0,0,0)$), p2=($(0,1,0)-(0,0,0)$),
p3=($(0,0,1)-(0,0,0)$) in pgfextra{typeout{
x1,y1;x2,y2;x3,y3}};
begin{scope}[transform shape]
addplot3[only marks, fill=cyan,mark=fcirc]
table {datatable};
end{scope}
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
% draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
% draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
% draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
%
% draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
% draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
% node[above] at (X,4) {$x_1$};
% node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
begin{thebibliography}{1}
bibitem{devore} Jay. L Devore {em Probability and Statistics for Engineering and the Sciences} 8th Edition.
end{thebibliography}
end{document}
The circles are now properly projected on the x-y plane but, unfortunately, since the x and y scales look very different, they look like ellipse. Is that what you want?
On the other hand, if you want to cancel out the elliptic distortion, you can do that by cheating:
documentclass{article}
usepackage{tikz}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{3d,calc,decorations.pathreplacing,arrows.meta}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
makeatletter
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane}
makeatother
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
pgfplotstableread{
X Y Z m
2.2 0 0 0
2.7 0 0 0
3 13 0 0
3.55 0 0 0
4 15 0 0
4.5 0 0 0
4.75 0 0 0
5.5 0 0 0
}datatabletwo
%makeatletter
pgfdeclareplotmark{dot}
{%
fill circle [x radius=0.02, y radius=0.08];
}%
%makeatother
pgfdeclareplotmark{fcirc}
{%
begin{scope}[x={(-21.20514pt,-9.26361pt)},
y={(7.73369*2.54181pt,-7.73369*1.57715pt)},z={(0.0pt,6.04706pt)}]
begin{scope}[canvas is xy plane at z=0,transform shape]
fill circle(0.1);
end{scope}
end{scope}
}%
begin{document}
section{table using raw data in 3D}
The below diagram tries to replicate in 3D, the Figure 12.3 found in cite{devore} , page 472 \
% https://tex.stackexchange.com/questions/11251/trend-line-or-line-of-best-fit-in-pgfplots
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
% read out the transformation done by pgfplots
path let p1=($(1,0,0)-(0,0,0)$), p2=($(0,1,0)-(0,0,0)$),
p3=($(0,0,1)-(0,0,0)$) in pgfextra{
pgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
typeout{
x1,y1;x2,y2;x3,y3;ratio}};
begin{scope}[transform shape]
addplot3[only marks, fill=cyan,mark=fcirc]
table {datatable};
end{scope}
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
node[above] at (X,4) {$x_1$};
node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
begin{thebibliography}{1}
bibitem{devore} Jay. L Devore {em Probability and Statistics for Engineering and the Sciences} 8th Edition.
end{thebibliography}
end{document}
Unfortunately, because of the way pgfplots works, you need to run this, find out the transformation and the "cheating scale" ratio
, and then plug this in the definition of fcircle
in case you make any changes.
why was the distortion earlier? because they scales are not equal for x and y?
– Parthiban Rajendran
Oct 21 '18 at 17:59
@BambOo It is just the ratio of lengths of unit vectors inx
andy
direction, which gets computed inpgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
in my code.
– marmot
Oct 21 '18 at 17:59
@PaariVendhan Precisely. Forget about 3D and just draw a circle in a plane in which the y scale is, say, 3 times the x scale. You'll get an ellipse, which is also what happens in my upper plot. By computingpgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
and installing it I make these scales equal in the local frame in which the circles are drawn.
– marmot
Oct 21 '18 at 18:00
But I wonder why this squeezing was not happening in 2D scale as my another example here
– Parthiban Rajendran
Oct 21 '18 at 18:03
1
For the record: Jake's patch is now incorporated in v3.1 of TikZ.
– Stefan Pinnow
Jan 15 at 19:25
|
show 11 more comments
UPDATE: A version without hardcoded values. (Note that I use a not entirely harmless command: globaldefs
. The alternative will be longer. I believe that here using globaldefs
is OK.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{3d,calc,decorations.pathreplacing,arrows.meta}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
makeatletter
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane}
makeatother
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
pgfplotstableread{
X Y Z m
2.2 0 0 0
2.7 0 0 0
3 13 0 0
3.55 0 0 0
4 15 0 0
4.5 0 0 0
4.75 0 0 0
5.5 0 0 0
}datatabletwo
pgfdeclareplotmark{fcirc}{%
begin{scope}[expand style={local frame}{MyLocalFrame},local frame]
begin{scope}[canvas is xy plane at z=0,transform shape]
fill circle(0.1);
end{scope}
end{scope}
}%
% based on https://tex.stackexchange.com/a/64237/121799
tikzset{expand style/.code n args={2}{tikzset{#1/.style/.expanded={#2}}}}
newcommand{GetLocalFrame}{
path let p1=($(1,0,0)-(0,0,0)$), p2=($(0,1,0)-(0,0,0)$),
p3=($(0,0,1)-(0,0,0)$) in pgfextra{
pgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
xdefMyLocalFrame{
x = { (x1,y1) },
y = { (ratio*x2,ratio*y2) },
z = { (x3,y3) }
}
}; }
begin{document}
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
% read out the transformation done by pgfplots
GetLocalFrame
begin{scope}[transform shape]
addplot3[only marks, fill=cyan,mark=fcirc]
table {datatable};
end{scope}
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
node[above] at (X,4) {$x_1$};
node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
end{document}
Old ANSWE: This is not an answer but just to show you what you get if do the projection.
documentclass{article}
usepackage{tikz}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{3d,calc}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
makeatletter
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane}
makeatother
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
pgfplotstableread{
X Y Z m
2.2 0 0 0
2.7 0 0 0
3 13 0 0
3.55 0 0 0
4 15 0 0
4.5 0 0 0
4.75 0 0 0
5.5 0 0 0
}datatabletwo
%makeatletter
pgfdeclareplotmark{dot}
{%
fill circle [x radius=0.02, y radius=0.08];
}%
%makeatother
pgfdeclareplotmark{fcirc}
{%
begin{scope}[x={(-21.20514pt,-9.26361pt)},
y={(2.54181pt,-1.57715pt)},z={(0.0pt,6.04706pt)}]
begin{scope}[canvas is xy plane at z=0,transform shape]
fill circle(0.1);
end{scope}
end{scope}
}%
begin{document}
section{table using raw data in 3D}
The below diagram tries to replicate in 3D, the Figure 12.3 found in cite{devore} , page 472 \
% https://tex.stackexchange.com/questions/11251/trend-line-or-line-of-best-fit-in-pgfplots
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
% read out the transformation done by pgfplots
path let p1=($(1,0,0)-(0,0,0)$), p2=($(0,1,0)-(0,0,0)$),
p3=($(0,0,1)-(0,0,0)$) in pgfextra{typeout{
x1,y1;x2,y2;x3,y3}};
begin{scope}[transform shape]
addplot3[only marks, fill=cyan,mark=fcirc]
table {datatable};
end{scope}
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
% draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
% draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
% draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
%
% draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
% draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
% node[above] at (X,4) {$x_1$};
% node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
begin{thebibliography}{1}
bibitem{devore} Jay. L Devore {em Probability and Statistics for Engineering and the Sciences} 8th Edition.
end{thebibliography}
end{document}
The circles are now properly projected on the x-y plane but, unfortunately, since the x and y scales look very different, they look like ellipse. Is that what you want?
On the other hand, if you want to cancel out the elliptic distortion, you can do that by cheating:
documentclass{article}
usepackage{tikz}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{3d,calc,decorations.pathreplacing,arrows.meta}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
makeatletter
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane}
makeatother
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
pgfplotstableread{
X Y Z m
2.2 0 0 0
2.7 0 0 0
3 13 0 0
3.55 0 0 0
4 15 0 0
4.5 0 0 0
4.75 0 0 0
5.5 0 0 0
}datatabletwo
%makeatletter
pgfdeclareplotmark{dot}
{%
fill circle [x radius=0.02, y radius=0.08];
}%
%makeatother
pgfdeclareplotmark{fcirc}
{%
begin{scope}[x={(-21.20514pt,-9.26361pt)},
y={(7.73369*2.54181pt,-7.73369*1.57715pt)},z={(0.0pt,6.04706pt)}]
begin{scope}[canvas is xy plane at z=0,transform shape]
fill circle(0.1);
end{scope}
end{scope}
}%
begin{document}
section{table using raw data in 3D}
The below diagram tries to replicate in 3D, the Figure 12.3 found in cite{devore} , page 472 \
% https://tex.stackexchange.com/questions/11251/trend-line-or-line-of-best-fit-in-pgfplots
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
% read out the transformation done by pgfplots
path let p1=($(1,0,0)-(0,0,0)$), p2=($(0,1,0)-(0,0,0)$),
p3=($(0,0,1)-(0,0,0)$) in pgfextra{
pgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
typeout{
x1,y1;x2,y2;x3,y3;ratio}};
begin{scope}[transform shape]
addplot3[only marks, fill=cyan,mark=fcirc]
table {datatable};
end{scope}
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
node[above] at (X,4) {$x_1$};
node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
begin{thebibliography}{1}
bibitem{devore} Jay. L Devore {em Probability and Statistics for Engineering and the Sciences} 8th Edition.
end{thebibliography}
end{document}
Unfortunately, because of the way pgfplots works, you need to run this, find out the transformation and the "cheating scale" ratio
, and then plug this in the definition of fcircle
in case you make any changes.
why was the distortion earlier? because they scales are not equal for x and y?
– Parthiban Rajendran
Oct 21 '18 at 17:59
@BambOo It is just the ratio of lengths of unit vectors inx
andy
direction, which gets computed inpgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
in my code.
– marmot
Oct 21 '18 at 17:59
@PaariVendhan Precisely. Forget about 3D and just draw a circle in a plane in which the y scale is, say, 3 times the x scale. You'll get an ellipse, which is also what happens in my upper plot. By computingpgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
and installing it I make these scales equal in the local frame in which the circles are drawn.
– marmot
Oct 21 '18 at 18:00
But I wonder why this squeezing was not happening in 2D scale as my another example here
– Parthiban Rajendran
Oct 21 '18 at 18:03
1
For the record: Jake's patch is now incorporated in v3.1 of TikZ.
– Stefan Pinnow
Jan 15 at 19:25
|
show 11 more comments
UPDATE: A version without hardcoded values. (Note that I use a not entirely harmless command: globaldefs
. The alternative will be longer. I believe that here using globaldefs
is OK.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{3d,calc,decorations.pathreplacing,arrows.meta}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
makeatletter
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane}
makeatother
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
pgfplotstableread{
X Y Z m
2.2 0 0 0
2.7 0 0 0
3 13 0 0
3.55 0 0 0
4 15 0 0
4.5 0 0 0
4.75 0 0 0
5.5 0 0 0
}datatabletwo
pgfdeclareplotmark{fcirc}{%
begin{scope}[expand style={local frame}{MyLocalFrame},local frame]
begin{scope}[canvas is xy plane at z=0,transform shape]
fill circle(0.1);
end{scope}
end{scope}
}%
% based on https://tex.stackexchange.com/a/64237/121799
tikzset{expand style/.code n args={2}{tikzset{#1/.style/.expanded={#2}}}}
newcommand{GetLocalFrame}{
path let p1=($(1,0,0)-(0,0,0)$), p2=($(0,1,0)-(0,0,0)$),
p3=($(0,0,1)-(0,0,0)$) in pgfextra{
pgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
xdefMyLocalFrame{
x = { (x1,y1) },
y = { (ratio*x2,ratio*y2) },
z = { (x3,y3) }
}
}; }
begin{document}
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
% read out the transformation done by pgfplots
GetLocalFrame
begin{scope}[transform shape]
addplot3[only marks, fill=cyan,mark=fcirc]
table {datatable};
end{scope}
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
node[above] at (X,4) {$x_1$};
node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
end{document}
Old ANSWE: This is not an answer but just to show you what you get if do the projection.
documentclass{article}
usepackage{tikz}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{3d,calc}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
makeatletter
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane}
makeatother
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
pgfplotstableread{
X Y Z m
2.2 0 0 0
2.7 0 0 0
3 13 0 0
3.55 0 0 0
4 15 0 0
4.5 0 0 0
4.75 0 0 0
5.5 0 0 0
}datatabletwo
%makeatletter
pgfdeclareplotmark{dot}
{%
fill circle [x radius=0.02, y radius=0.08];
}%
%makeatother
pgfdeclareplotmark{fcirc}
{%
begin{scope}[x={(-21.20514pt,-9.26361pt)},
y={(2.54181pt,-1.57715pt)},z={(0.0pt,6.04706pt)}]
begin{scope}[canvas is xy plane at z=0,transform shape]
fill circle(0.1);
end{scope}
end{scope}
}%
begin{document}
section{table using raw data in 3D}
The below diagram tries to replicate in 3D, the Figure 12.3 found in cite{devore} , page 472 \
% https://tex.stackexchange.com/questions/11251/trend-line-or-line-of-best-fit-in-pgfplots
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
% read out the transformation done by pgfplots
path let p1=($(1,0,0)-(0,0,0)$), p2=($(0,1,0)-(0,0,0)$),
p3=($(0,0,1)-(0,0,0)$) in pgfextra{typeout{
x1,y1;x2,y2;x3,y3}};
begin{scope}[transform shape]
addplot3[only marks, fill=cyan,mark=fcirc]
table {datatable};
end{scope}
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
% draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
% draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
% draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
%
% draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
% draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
% node[above] at (X,4) {$x_1$};
% node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
begin{thebibliography}{1}
bibitem{devore} Jay. L Devore {em Probability and Statistics for Engineering and the Sciences} 8th Edition.
end{thebibliography}
end{document}
The circles are now properly projected on the x-y plane but, unfortunately, since the x and y scales look very different, they look like ellipse. Is that what you want?
On the other hand, if you want to cancel out the elliptic distortion, you can do that by cheating:
documentclass{article}
usepackage{tikz}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{3d,calc,decorations.pathreplacing,arrows.meta}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
makeatletter
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane}
makeatother
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
pgfplotstableread{
X Y Z m
2.2 0 0 0
2.7 0 0 0
3 13 0 0
3.55 0 0 0
4 15 0 0
4.5 0 0 0
4.75 0 0 0
5.5 0 0 0
}datatabletwo
%makeatletter
pgfdeclareplotmark{dot}
{%
fill circle [x radius=0.02, y radius=0.08];
}%
%makeatother
pgfdeclareplotmark{fcirc}
{%
begin{scope}[x={(-21.20514pt,-9.26361pt)},
y={(7.73369*2.54181pt,-7.73369*1.57715pt)},z={(0.0pt,6.04706pt)}]
begin{scope}[canvas is xy plane at z=0,transform shape]
fill circle(0.1);
end{scope}
end{scope}
}%
begin{document}
section{table using raw data in 3D}
The below diagram tries to replicate in 3D, the Figure 12.3 found in cite{devore} , page 472 \
% https://tex.stackexchange.com/questions/11251/trend-line-or-line-of-best-fit-in-pgfplots
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
% read out the transformation done by pgfplots
path let p1=($(1,0,0)-(0,0,0)$), p2=($(0,1,0)-(0,0,0)$),
p3=($(0,0,1)-(0,0,0)$) in pgfextra{
pgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
typeout{
x1,y1;x2,y2;x3,y3;ratio}};
begin{scope}[transform shape]
addplot3[only marks, fill=cyan,mark=fcirc]
table {datatable};
end{scope}
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
node[above] at (X,4) {$x_1$};
node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
begin{thebibliography}{1}
bibitem{devore} Jay. L Devore {em Probability and Statistics for Engineering and the Sciences} 8th Edition.
end{thebibliography}
end{document}
Unfortunately, because of the way pgfplots works, you need to run this, find out the transformation and the "cheating scale" ratio
, and then plug this in the definition of fcircle
in case you make any changes.
UPDATE: A version without hardcoded values. (Note that I use a not entirely harmless command: globaldefs
. The alternative will be longer. I believe that here using globaldefs
is OK.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{3d,calc,decorations.pathreplacing,arrows.meta}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
makeatletter
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane}
makeatother
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
pgfplotstableread{
X Y Z m
2.2 0 0 0
2.7 0 0 0
3 13 0 0
3.55 0 0 0
4 15 0 0
4.5 0 0 0
4.75 0 0 0
5.5 0 0 0
}datatabletwo
pgfdeclareplotmark{fcirc}{%
begin{scope}[expand style={local frame}{MyLocalFrame},local frame]
begin{scope}[canvas is xy plane at z=0,transform shape]
fill circle(0.1);
end{scope}
end{scope}
}%
% based on https://tex.stackexchange.com/a/64237/121799
tikzset{expand style/.code n args={2}{tikzset{#1/.style/.expanded={#2}}}}
newcommand{GetLocalFrame}{
path let p1=($(1,0,0)-(0,0,0)$), p2=($(0,1,0)-(0,0,0)$),
p3=($(0,0,1)-(0,0,0)$) in pgfextra{
pgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
xdefMyLocalFrame{
x = { (x1,y1) },
y = { (ratio*x2,ratio*y2) },
z = { (x3,y3) }
}
}; }
begin{document}
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
% read out the transformation done by pgfplots
GetLocalFrame
begin{scope}[transform shape]
addplot3[only marks, fill=cyan,mark=fcirc]
table {datatable};
end{scope}
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
node[above] at (X,4) {$x_1$};
node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
end{document}
Old ANSWE: This is not an answer but just to show you what you get if do the projection.
documentclass{article}
usepackage{tikz}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{3d,calc}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
makeatletter
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane}
makeatother
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
pgfplotstableread{
X Y Z m
2.2 0 0 0
2.7 0 0 0
3 13 0 0
3.55 0 0 0
4 15 0 0
4.5 0 0 0
4.75 0 0 0
5.5 0 0 0
}datatabletwo
%makeatletter
pgfdeclareplotmark{dot}
{%
fill circle [x radius=0.02, y radius=0.08];
}%
%makeatother
pgfdeclareplotmark{fcirc}
{%
begin{scope}[x={(-21.20514pt,-9.26361pt)},
y={(2.54181pt,-1.57715pt)},z={(0.0pt,6.04706pt)}]
begin{scope}[canvas is xy plane at z=0,transform shape]
fill circle(0.1);
end{scope}
end{scope}
}%
begin{document}
section{table using raw data in 3D}
The below diagram tries to replicate in 3D, the Figure 12.3 found in cite{devore} , page 472 \
% https://tex.stackexchange.com/questions/11251/trend-line-or-line-of-best-fit-in-pgfplots
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
% read out the transformation done by pgfplots
path let p1=($(1,0,0)-(0,0,0)$), p2=($(0,1,0)-(0,0,0)$),
p3=($(0,0,1)-(0,0,0)$) in pgfextra{typeout{
x1,y1;x2,y2;x3,y3}};
begin{scope}[transform shape]
addplot3[only marks, fill=cyan,mark=fcirc]
table {datatable};
end{scope}
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
% draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
% draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
% draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
%
% draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
% draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
% node[above] at (X,4) {$x_1$};
% node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
begin{thebibliography}{1}
bibitem{devore} Jay. L Devore {em Probability and Statistics for Engineering and the Sciences} 8th Edition.
end{thebibliography}
end{document}
The circles are now properly projected on the x-y plane but, unfortunately, since the x and y scales look very different, they look like ellipse. Is that what you want?
On the other hand, if you want to cancel out the elliptic distortion, you can do that by cheating:
documentclass{article}
usepackage{tikz}
usepackage{pgfplots, pgfplotstable}
usetikzlibrary{3d,calc,decorations.pathreplacing,arrows.meta}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
makeatletter
tikzoption{canvas is xy plane at z}{%
deftikz@plane@origin{pgfpointxyz{0}{0}{#1}}%
deftikz@plane@x{pgfpointxyz{1}{0}{#1}}%
deftikz@plane@y{pgfpointxyz{0}{1}{#1}}%
tikz@canvas@is@plane}
makeatother
pgfplotsset{compat=1.15}
pgfplotstableread{
X Y Z m
2.2 14 0 0
2.7 23 0 0
3 13 0 0
3.55 22 0 0
4 15 0 0
4.5 20 0 0
4.75 28 0 0
5.5 23 0 0
}datatable
pgfplotstableread{
X Y Z m
2.2 0 0 0
2.7 0 0 0
3 13 0 0
3.55 0 0 0
4 15 0 0
4.5 0 0 0
4.75 0 0 0
5.5 0 0 0
}datatabletwo
%makeatletter
pgfdeclareplotmark{dot}
{%
fill circle [x radius=0.02, y radius=0.08];
}%
%makeatother
pgfdeclareplotmark{fcirc}
{%
begin{scope}[x={(-21.20514pt,-9.26361pt)},
y={(7.73369*2.54181pt,-7.73369*1.57715pt)},z={(0.0pt,6.04706pt)}]
begin{scope}[canvas is xy plane at z=0,transform shape]
fill circle(0.1);
end{scope}
end{scope}
}%
begin{document}
section{table using raw data in 3D}
The below diagram tries to replicate in 3D, the Figure 12.3 found in cite{devore} , page 472 \
% https://tex.stackexchange.com/questions/11251/trend-line-or-line-of-best-fit-in-pgfplots
begin{tikzpicture}[scale=1.5]
begin{axis}
[
view={140}{50},
xmin=1,xmax=6, ymin=5,ymax=40, zmin=0, zmax=10,
% ytick=empty,xtick=empty,ztick=empty,
clip=false, axis lines = middle
]
% read out the transformation done by pgfplots
path let p1=($(1,0,0)-(0,0,0)$), p2=($(0,1,0)-(0,0,0)$),
p3=($(0,0,1)-(0,0,0)$) in pgfextra{
pgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
typeout{
x1,y1;x2,y2;x3,y3;ratio}};
begin{scope}[transform shape]
addplot3[only marks, fill=cyan,mark=fcirc]
table {datatable};
end{scope}
addplot3[thick, red] table[y={create col/linear regression={y=Y}}] {datatable}; % compute a linear regression from the input table
defX{2.7}
defY{23}
draw [-{Latex[length=4mm, width=2mm]}] (X,Y+10,12.5) node[right]{$(x_1,y_1)$} ..controls (0,5) .. (X,Y,0);
draw [-{Latex[length=4mm, width=2mm]}] (9,30,20) node[left, align=right]{scriptsize True Regression Line\ scriptsize $y = beta_0 + beta_1 x$} .. controls (5,2.5) .. (5,22.7,0);
draw [decorate, decoration={brace,amplitude=3pt}, xshift=0.5mm] (X,Y-0.1,0) to (X,17,0) node[left, xshift=5mm, yshift=-1mm]{scriptsize 1}; % brace
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (1,17.1) to (X,17.1);
draw [thick,dash pattern={on 7pt off 2pt on 1pt off 3pt}] (X,17.1) -- (X,5);
node[above] at (X,4) {$x_1$};
node[right, align=left,yshift=0.5mm] at (1,17.1) {$E(Y|x_1)=mu_{Y.x_1}$};
end{axis}
end{tikzpicture}
begin{thebibliography}{1}
bibitem{devore} Jay. L Devore {em Probability and Statistics for Engineering and the Sciences} 8th Edition.
end{thebibliography}
end{document}
Unfortunately, because of the way pgfplots works, you need to run this, find out the transformation and the "cheating scale" ratio
, and then plug this in the definition of fcircle
in case you make any changes.
edited Oct 22 '18 at 21:18
answered Oct 21 '18 at 17:41
marmotmarmot
93.8k4109208
93.8k4109208
why was the distortion earlier? because they scales are not equal for x and y?
– Parthiban Rajendran
Oct 21 '18 at 17:59
@BambOo It is just the ratio of lengths of unit vectors inx
andy
direction, which gets computed inpgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
in my code.
– marmot
Oct 21 '18 at 17:59
@PaariVendhan Precisely. Forget about 3D and just draw a circle in a plane in which the y scale is, say, 3 times the x scale. You'll get an ellipse, which is also what happens in my upper plot. By computingpgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
and installing it I make these scales equal in the local frame in which the circles are drawn.
– marmot
Oct 21 '18 at 18:00
But I wonder why this squeezing was not happening in 2D scale as my another example here
– Parthiban Rajendran
Oct 21 '18 at 18:03
1
For the record: Jake's patch is now incorporated in v3.1 of TikZ.
– Stefan Pinnow
Jan 15 at 19:25
|
show 11 more comments
why was the distortion earlier? because they scales are not equal for x and y?
– Parthiban Rajendran
Oct 21 '18 at 17:59
@BambOo It is just the ratio of lengths of unit vectors inx
andy
direction, which gets computed inpgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
in my code.
– marmot
Oct 21 '18 at 17:59
@PaariVendhan Precisely. Forget about 3D and just draw a circle in a plane in which the y scale is, say, 3 times the x scale. You'll get an ellipse, which is also what happens in my upper plot. By computingpgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
and installing it I make these scales equal in the local frame in which the circles are drawn.
– marmot
Oct 21 '18 at 18:00
But I wonder why this squeezing was not happening in 2D scale as my another example here
– Parthiban Rajendran
Oct 21 '18 at 18:03
1
For the record: Jake's patch is now incorporated in v3.1 of TikZ.
– Stefan Pinnow
Jan 15 at 19:25
why was the distortion earlier? because they scales are not equal for x and y?
– Parthiban Rajendran
Oct 21 '18 at 17:59
why was the distortion earlier? because they scales are not equal for x and y?
– Parthiban Rajendran
Oct 21 '18 at 17:59
@BambOo It is just the ratio of lengths of unit vectors in
x
and y
direction, which gets computed in pgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
in my code.– marmot
Oct 21 '18 at 17:59
@BambOo It is just the ratio of lengths of unit vectors in
x
and y
direction, which gets computed in pgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
in my code.– marmot
Oct 21 '18 at 17:59
@PaariVendhan Precisely. Forget about 3D and just draw a circle in a plane in which the y scale is, say, 3 times the x scale. You'll get an ellipse, which is also what happens in my upper plot. By computing
pgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
and installing it I make these scales equal in the local frame in which the circles are drawn.– marmot
Oct 21 '18 at 18:00
@PaariVendhan Precisely. Forget about 3D and just draw a circle in a plane in which the y scale is, say, 3 times the x scale. You'll get an ellipse, which is also what happens in my upper plot. By computing
pgfmathsetmacro{ratio}{veclen(x1,y1)/veclen(x2,y2)}
and installing it I make these scales equal in the local frame in which the circles are drawn.– marmot
Oct 21 '18 at 18:00
But I wonder why this squeezing was not happening in 2D scale as my another example here
– Parthiban Rajendran
Oct 21 '18 at 18:03
But I wonder why this squeezing was not happening in 2D scale as my another example here
– Parthiban Rajendran
Oct 21 '18 at 18:03
1
1
For the record: Jake's patch is now incorporated in v3.1 of TikZ.
– Stefan Pinnow
Jan 15 at 19:25
For the record: Jake's patch is now incorporated in v3.1 of TikZ.
– Stefan Pinnow
Jan 15 at 19:25
|
show 11 more comments
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f456138%2fmarks-do-not-appear-in-3d-for-3d-scatter-plot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If I look at your table, in every row the third entry is zero. Isn't that the z coordinate? What I want to say is that it is not too surprising that the circles are all in the x-y plane. So I think the points are correct, i.e. represent the data. Note that this is not a scatter plot in the strict sense since there is no scatter directive. Note also that you may drop
makeatletter
andmakeatother
.– marmot
Oct 21 '18 at 17:15
If you could post the original figure from the book you cite, it will be easier to help. Most people here won't have access to it.
– BambOo
Oct 21 '18 at 17:29
@marmot I have added a new question here. can you please check out. Its continuation from this problem.
– Parthiban Rajendran
Oct 22 '18 at 8:38