TransWikia.com

TikZ does not draw functions anymore

TeX - LaTeX Asked by PUserR on September 30, 2020

I am using the latest TeXstudio version with PdfLaTeX as my compiler. I have this commands enabled: pdflatex.exe -synctex=1 -shell-escape -interaction=nonstopmode %.tex. The document is getting created but TikZ does not draw the functions. The Code works in Overleaf (online editor) perfectly fine with the drawn functions so there must be a problem with my PdfLaTeX or my TeXstudio. I tried reinstalling MikTeX and TeXstudio. I have even installed on a virtual machine to look if it works there but without success. It also does not work in WinShell. I also tried to compile the document with LuaLaTeX but again, without success. Furthermore, Overleaf’s default compiler was set to PdfLaTeX. I thinks that there is something wrong with my PdfLaTeX but I have no idea left for a possibility to solve that problem. My Code is:

documentclass{article}

usepackage{pgfplots}
usetikzlibrary{through,calc,arrows,snakes}

pgfplotsset{compat=1.16}

begin{document}
begin{center}
    begin{tikzpicture}[scale=0.8, x=2cm, y=2cm, axis/.style={ ->, >=stealth'}]
        draw[dotted,color=black, xstep=1cm, ystep=1cm] (-1.9,0) grid (1.9,3.9);
        draw[axis] (-2,0) -- (2,0) node[above] {small $x$};
        draw[axis] (0,0) -- (0,4) node[right] {small $y$};
        foreach x/xtext in {-2/-2, -1/-1, 0/0, 1/1} draw[shift={(x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below, fill=white] {small xtext};
        foreach y/ytext in {1/1, 2/2, 3/3}  draw[shift={(0,y)}] (2pt,0pt) -- (-2pt,0pt) node[left, fill=white] {small ytext};
        % functions
            draw[color=red, thick] plot[domain=-2:2, samples=250] function{x*x} node[right] {small $f(x)$};
    end{tikzpicture}
end{center}
end{document}

These are the results:
Output of both programs (left Overleaf, right TeXstudio)

As you can see on the left it looks perfectly fine (Overleaf) but on the right (TeXstudio) it doesnt. I want to continue writing in TeXstudio not in Overleaf so it would be great if this is working.

2 Answers

Your code is calling gnuplot. It need both gnuplot installed and -shell-escape (or enable-write18) compilation option.

Answered by gigiair on September 30, 2020

This works in local (recent) MikTeX installation as well in Overleaf:

documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
usetikzlibrary{arrows,
                calc, 
                decorations.pathmorphing, 
                through}

begin{document}
begin{center}
    begin{tikzpicture}[scale=0.8, x=2cm, y=2cm, axis/.style={ ->, >=stealth'}]
draw[dotted, xstep=1cm, ystep=1cm] (-1.9,0) grid (1.9,3.9);
draw[axis] (-2,0) -- (2,0) node[above] {small $x$};
draw[axis] ( 0,0) -- (0,4) node[right] {small $y$};
%
    foreach x/xtext in {-2/-2, -1/-1, 0/0, 1/1} 
draw[shift={(x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below, fill=white] {small xtext};
    foreach y/ytext in {1/1, 2/2, 3/3}  
draw[shift={(0,y)}] (2pt,0pt) -- (-2pt,0pt) node[left, fill=white] {small ytext};
% functions
draw[color=red, thick] plot[domain=-2:2, samples=250] 
    (x,{x*x}) node[right] {small $f(x)$};
    end{tikzpicture}
end{center}
end{document}

enter image description here

Answered by Zarko on September 30, 2020

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