TransWikia.com

I am exporting the code to plot floor function in latex from GeoGebra but it is not working (floor function)

TeX - LaTeX Asked by sultan on April 3, 2021

Good day!

I have transferred this code (to make a graph of the floor function) from GeoGebra to LaTeX but the output is very weird not getting the same output what I was getting in GeoGebra. please help.

Following is the code:

definecolor{xdxdff}{rgb}{0.49019607843137253,0.49019607843137253,1}
definecolor{qqwuqq}{rgb}{0,0.39215686274509803,0}
begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1cm,y=1cm]
begin{axis}[
x=1cm,y=1cm,
axis lines=middle,
ymajorgrids=true,
xmajorgrids=true,
xmin=-15.16,
xmax=15.16,
ymin=-11.76,
ymax=7.2,
xtick={-15,-14,...,15},
ytick={-11,-10,...,7},]
clip(-15.16,-11.76) rectangle (15.16,7.2);
draw[line width=2pt,color=qqwuqq,smooth,samples=100,domain=-15.16:15.16] plot(x,{floor((x))});
begin{scriptsize}
draw[color=qqwuqq] (-10.72,-11.43) node {$f$};
draw [fill=xdxdff] (1,1) circle (2.5pt);
draw[color=xdxdff] (1.16,1.43) node {$A$};
draw [fill=xdxdff] (2,2) circle (2.5pt);
draw[color=xdxdff] (2.16,2.43) node {$B$};
draw [fill=xdxdff] (3,3) circle (2.5pt);
draw[color=xdxdff] (3.16,3.43) node {$C$};
draw [fill=xdxdff] (4,4) circle (2.5pt);
draw[color=xdxdff] (4.16,4.43) node {$D$};
draw [fill=xdxdff] (0,0) circle (2.5pt);
draw[color=xdxdff] (0.16,0.43) node {$E$};
draw [fill=xdxdff] (-2,-2) circle (2.5pt);
draw[color=xdxdff] (-1.84,-1.57) node {$F$};
draw [fill=xdxdff] (-3,-3) circle (2.5pt);
draw[color=xdxdff] (-2.84,-2.57) node {$G$};
draw [fill=xdxdff] (-1,-1) circle (2.5pt);
draw[color=xdxdff] (-0.84,-0.57) node {$H$};
draw [fill=xdxdff] (-4,-4) circle (2.5pt);
draw[color=xdxdff] (-3.84,-3.57) node {$I$};
end{scriptsize}
end{axis}
end{tikzpicture}

One Answer

As usual, GeoGebra generated code needs to be edited.

A domain from –15 to 15 will result in a 30cm wide graph, so it's necessary to reduce it.

You also need to specify the compatibility level of pgfplots and many more samples than 100.

documentclass{article}
usepackage{tikz,pgfplots}
usetikzlibrary{arrows,arrows.meta}
pgfplotsset{compat=1.17}

begin{document}

definecolor{xdxdff}{rgb}{0.5,0.5,1}
definecolor{qqwuqq}{rgb}{0,0.4,0}
begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,font=scriptsize]
begin{axis}[
  x=1cm,y=1cm,
  axis lines=middle,
  ymajorgrids=true,
  xmajorgrids=true,
  xmin=-5.16,
  xmax=5.16,
  ymin=-5.76,
  ymax=5.2,
xtick={-5,-4,...,5},
ytick={-6,-5,...,6},
]
draw[
  line width=1pt,
  color=qqwuqq,
  smooth,
  samples=1000, % 100 is too small
  domain=-5.16:5.16] plot(x,{floor((x))});
draw[color=qqwuqq] (-10.72,-11.43) node {$f$};
draw [fill=xdxdff] (1,1) circle (2.5pt);
draw[color=xdxdff] (1.16,1.43) node {$A$};
draw [fill=xdxdff] (2,2) circle (2.5pt);
draw[color=xdxdff] (2.16,2.43) node {$B$};
draw [fill=xdxdff] (3,3) circle (2.5pt);
draw[color=xdxdff] (3.16,3.43) node {$C$};
draw [fill=xdxdff] (4,4) circle (2.5pt);
draw[color=xdxdff] (4.16,4.43) node {$D$};
draw [fill=xdxdff] (0,0) circle (2.5pt);
draw[color=xdxdff] (0.16,0.43) node {$E$};
draw [fill=xdxdff] (-2,-2) circle (2.5pt);
draw[color=xdxdff] (-1.84,-1.57) node {$F$};
draw [fill=xdxdff] (-3,-3) circle (2.5pt);
draw[color=xdxdff] (-2.84,-2.57) node {$G$};
draw [fill=xdxdff] (-1,-1) circle (2.5pt);
draw[color=xdxdff] (-0.84,-0.57) node {$H$};
draw [fill=xdxdff] (-4,-4) circle (2.5pt);
draw[color=xdxdff] (-3.84,-3.57) node {$I$};
end{axis}
end{tikzpicture}

end{document}

enter image description here

Correct answer by egreg on April 3, 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