TransWikia.com

Plot points from pgfplotstableset

TeX - LaTeX Asked by robintux on August 17, 2021

i have my MWE

documentclass[]{beamer}
usepackage{etoolbox}
usepackage{pgfplots}
usepackage{pgfplotstable}
begin{document}
begin{frame}
frametitle{ Regression}
framesubtitle{Weight and Height}
begin{columns}
begin{column}{0.2textwidth}
pgfmathsetseed{1138} % set the random seed
pgfplotstableset{ % Define the equations for x and y
    create on use/x/.style={create col/expr={42+5*pgfplotstablerow}},
    create on use/y/.style={create col/expr={(0.6*thisrow{x}+130)+5*rand}},
}
pgfplotstablenew[columns={x,y}]{10}loadedtable % create a new table with 10 rows and columns x and y:
pgfplotstabletypeset[fixed]{loadedtable}
end{column}
begin{column}{0.8textwidth}  
Consideremos la variable textit{Peso} en el eje X , es decir esta es la variable independiente.Y luego consideremos la variable textit{Altura} en el 
eje Y, es decir, esta es la variable dependiente.
begin{tikzpicture}
begin{axis}[
xlabel=Weight (kg), % label x axis
ylabel=Height (cm), % label y axis
axis lines=left, %set the position of the axes
xmin=40, xmax=105, % set the min and max values of the x-axis
ymin=150, ymax=200, % set the min and max values of the y-axis
clip=false
]
addplot[only marks] table {loadedtable};
end{axis}
end{tikzpicture}
end{column}
end{columns}
end{frame}
end{document}

This tikzpicture works great on article document, but in my beamer stop working.

One Answer

This has nothing to do with beamer vs. article but with the fact that a column is a group, so the loadedtable is not "known" in the right column. This can be solved by defining the table before the columns.

documentclass[]{beamer}
usepackage{pgfplots}
usepackage{pgfplotstable}
begin{document}
begin{frame}[t]
frametitle{Regression}
framesubtitle{Weight and Height}
pgfmathsetseed{1138}% set the random seed
pgfplotstableset{ % Define the equations for x and y
    create on use/x/.style={create col/expr={42+5*pgfplotstablerow}},
    create on use/y/.style={create col/expr={(0.6*thisrow{x}+130)+5*rand}},
}%
pgfplotstablenew[columns={x,y}]{10}loadedtable % create a new table with 10 rows and columns x and y:
begin{columns}[T]
begin{column}{0.22textwidth}
pgfplotstabletypeset[fixed]{loadedtable}
end{column}%
begin{column}{0.78textwidth}  
Consideremos la variable textit{Peso} en el eje X, es decir esta es la
variable independiente. Y luego consideremos la variable textit{Altura} en el 
eje Y, es decir, esta es la variable dependiente.

begin{tikzpicture}
begin{axis}[height=4.5cm,width=0.9textwidth,
xlabel=Weight (kg), % label x axis
ylabel=Height (cm), % label y axis
axis lines=left, %set the position of the axes
xmin=40, xmax=105, % set the min and max values of the x-axis
ymin=150, ymax=200, % set the min and max values of the y-axis
clip=false
]
addplot[only marks] table {loadedtable};
end{axis}
end{tikzpicture}
end{column}
end{columns}
end{frame}
end{document}

enter image description here

I had to make the left column a tiny bit wider and the plot smaller to avoid overfull hboxes. Needless to say that you could add the regression line with pgfplots, too, if needed.

Answered by user194703 on August 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP