Facebook Page
Twitter
RSS
+ Reply to Thread
Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: TikZ pictures

  1. MHB Seeker
    MHB Global Moderator
    MHB Math Scholar
    MHB Coder
    Klaas van Aarsen's Avatar
    Status
    Offline
    Join Date
    Mar 2012
    Location
    Leiden
    Posts
    8,042
    Thanks
    5,286 times
    Thanked
    14,270 times
    Thank/Post
    1.774
    Awards
    MHB Pre-University Math Award (2018)  

MHB Model Helper Award (2017)  

MHB Best Ideas (2017)  

MHB Analysis Award (2017)  

MHB Calculus Award (2017)
    #1
    Hi everyone!

    We are very excited to announce the introduction of TikZ pictures.
    MHB is the very first math site ever to allow members to post TikZ pictures!

    To add for instance a plot, we can now use:
    Latex Code:
     
    \begin{tikzpicture}
      %preamble \usepackage{pgfplots}
      \begin{axis}
        \addplot coordinates {(0,1) (0.5,1) (1,1.2)}; 
      \end{axis} 
    \end{tikzpicture}



    Syntax

    TikZ has a dedicated syntax for every area of expertise we want to make drawings for.
    So dedicated, that it almost doesn't seem feasible to learn all of it.
    The easiest way appears to google for a tikz example of a specific type of diagram, and modify it to our own needs.
    TikZ is extensively documented all over the web.
    Just google for instance for tikz state diagram to see how to create a state diagram.
    In each area of expertise the syntax is designed to be as simple and intuitive as possible.
    And if it's not clear how an example should be modified, we can check the "http://mirrors.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf"]main TikZ package documentation[/URL]. Specifically for plots we may want to use the pgfplots package (as in the example above), which is documented in the .

    That said, there are a number of common and intuitive elements.
    For instance, a point is just (x,y), and a line is 2 points connected by
    --
    , such as
    (0,0) -- (1,0)
    .
    If we want to modify an attribute, for instance use an arrow or use a bent line, we add something in square brackets, such as
    [->]
    respectively
    [bend left]
    , as in
    \draw[bend left] (0,0) to (5,5);

    As for what we should add, we'll have to look up what the options are, or deduce it from an example.
    The general layout is $\LaTeX$ with its
    \
    directives and parameters that can be grouped with
    {...}
    .

    Note that this latex should be standalone.
    It should not be enclosed in latex tags, such as [MATH], \$\$, or \$.

    As a side note, we can use [LATEXS] tags to quote latex with syntax highlighting, as we have done to quote the various latex fragments in this post.

    Custom preamble

    We have the option to specify the preamble with
    %preamble
    directives.
    It means we can include any package or library that has our fancy.

    So if we create a picture of the form
    Latex Code:
     
    \begin{tikzpicture}
      %preamble \usepackage{amsmath}
      %preamble \usetikzlibrary{arrows}
      ...
    \end{tikzpicture}

    the resulting document is:
    Latex Code:
     
    \documentclass[border=10pt]{standalone}
    \usepackage{tikz}
     
    \usepackage{amsmath}
    \usetikzlibrary{arrows}
     
    \begin{document}
    \begin{tikzpicture}
      ...
    \end{tikzpicture}
    \end{document}

    Note that if we specify at least one preamble directive, the default preamble is discarded except for the
    tikz
    package.
    So we will have to specify all other needed packages or libraries as well.

    Toolbar button

    To make things easier, and more visible, we've added a new button on the toolbar with this icon:



    This will generate TIKZ tags which will be interpreted as the beginning and ending TikZ tags.
    So if we enter:

    we'll get the same picture.


    Example function graph

    Just to give a couple of additional examples:

    Latex Code:
    \begin{tikzpicture}
      %preamble \usepackage{pgfplots}
      \begin{axis}[xmin=-1.5, xmax=1.5, samples=101]
        \addplot[blue, ultra thick] (x, {cos(deg(x)) / (3*x^2 - pi^2)});
      \end{axis}
    \end{tikzpicture}



    Note in particular that $\cos$ takes degrees as a parameter instead of radians.

    Example state diagram

    Latex Code:
    \begin{tikzpicture}[shorten >=1pt,node distance=2cm,auto]
      %preamble \usetikzlibrary{automata}
      \node[state,initial]    (q_0)                {$q_0$};
      \node[state,accepting]  (q_1) [right of=q_0] {$q_1$};
     
      \path[->] (q_0) edge [bend left]  node {$a$} (q_1)
                (q_1) edge [bend left]  node {$b$} (q_0);
    \end{tikzpicture}



    Example graph of a hyperbola

    Latex Code:
    \begin{tikzpicture}
    %preamble \usepackage{amsmath}
    \draw[gray!50, very thin,->] (-4,0) -- (4,-0); % x-axis
    \draw[gray!50, very thin,->] (0,-3) -- (0,3);  % y-axis
    \draw[gray!50, very thin] (-2,-1.5) rectangle (2,1.5);
    \draw[red,line width=2pt] (2.5,0) -- (2.5,1.125) node[right=1pt] {$\ell=\dfrac{b^2}{a}$}; % semi latus rectum
    \draw[domain=-1.3:1.3,smooth,variable=\t,line width=2pt] plot ({2*cosh(\t)},{1.5*sinh(\t)});
    \draw[domain=-1.3:1.3,smooth,variable=\t,line width=2pt] plot ({-2*cosh(\t)},{1.5*sinh(\t)});
    \node at (-1.2,-2.5) {$\dfrac{x^2}{a^2} - \dfrac{y^2}{b^2}=1$ };
    \node at (1.5,-2.5) {$r=\dfrac{b^2}{a - c \cos\theta}$ };
    \node at (-1.5,2.5) {$(\pm a \cosh u, b \sinh u)$ };
    \draw (-4,-3) -- (4,3);
    \draw (4,-3) -- (-4,3);
    \node at (-1.2,0.1) {a};
    \node at (-1.85,0.75) {b};
    \node at (-0.85,0.85) {c};
    \draw[<->, green] (0,-0.3) -- (2.5,-0.3);
    \node[green] at (1.25,-4pt) {c};
    \fill (-2.5,0) circle (0.1); % focus
    \fill (2.5,0) circle (0.1);  % focus
    \end{tikzpicture}



    Example histogram

    Latex Code:
    \begin{tikzpicture}
    %preamble \usepackage{pgfplots}
    \begin{axis}[	tiny,
    		width=6in,
    		xtick=data,
    		ymin=0 ]
    	\addplot+[
    		hist={bins=10, density},
    		fill=blue!20,
    		mark=none,
    	] table[ row sep=\\, y index=0 ] {%
    		data \\ 565 \\ 786 \\ 870 \\ 923 \\ 948 \\ 951 \\ 964 \\ 968 \\
    		997 \\1007 \\1013 \\1037 \\1040 \\1051 \\1056 \\1080 \\
    		1088 \\1090 \\1102 \\1103 \\1104 \\1120 \\1151 \\1159 \\
    		1165 \\1185 \\1189 \\1207 \\1216 \\1233 \\1251 \\1256 \\
    		1261 \\1292 \\1312 \\1317 \\1347 \\1358 \\1385 \\1416 \\
    		1477 \\1500 \\1514 \\1567 \\1592 \\1588 \\1615 \\1713 \\
    	 	2325 \\3168 \\
    	};
    \end{axis}
    \end{tikzpicture}




    Example astronomical drawing

    Latex Code:
    \begin{tikzpicture}
    \draw (-4,0) -- (4,0);
    \draw (-4,0) circle (1.5);
    \draw (-4,-1.5) -- (4,-.2);
    \fill[draw=black!50,top color=blue!80,bottom color=black!40] 
        (-4,0) circle (.5) node {Earth};
    \fill[draw=black!50,top color=orange!80,bottom color=black!40] 
        (4,0) circle (1) node {Sun};
    \fill[draw=black!50,top color=gray,bottom color=black!20]
         (-4,-1.5) circle (.1) node[below = 1pt] {Satellite};
    \end{tikzpicture}




    Happy TikZ drawing!!
    Last edited by MarkFL; February 15th, 2018 at 02:50.

  2. # ADS
    Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many
     

  3. MHB Craftsman

    Status
    Offline
    Join Date
    Jul 2016
    Posts
    341
    Thanks
    460 times
    Thanked
    169 times
    Trophies
    6 Highscores
    Awards
    MHB Model User Award (2016)
    #2
    Congratulations MHB on achieving another milestone !!!

  4. MHB Journeyman
    MHB Math Scholar
    caffeinemachine's Avatar
    Status
    Offline
    Join Date
    Mar 2012
    Location
    India
    Posts
    819
    Thanks
    580 times
    Thanked
    1,148 time
    Thank/Post
    1.402
    Awards
    MHB Topology and Advanced Geometry Award (2016)
    #3
    This should be advertised on the first page of MHB and not just in a separate post. Anybody visiting the forum should see that he/she can post using tikz!

  5. MHB Oldtimer
    MHB Site Helper
    MHB Math Scholar
    Opalg's Avatar
    Status
    Online
    Join Date
    Feb 2012
    Location
    Leeds, UK
    Posts
    2,510
    Thanks
    858 times
    Thanked
    6,631 times
    Thank/Post
    2.642
    Awards
    MHB University Math Award (2018)  

MHB Challenges Solver Award (2017)  

Graduate POTW Award (2017)  

University POTW Award (2017)  

Secondary School/High School POTW Award (2017)
    #4
    This is really impressive. The only disappointment is that the Safari browser does not seem to support it. On my iMac the TikZ images display correctly if I use Firefox, Opera or Chrome, but not with Safari. It looks as though I'll have to switch to Firefox as my default browser.

  6. MHB Seeker
    MHB Global Moderator
    MHB Math Scholar
    MHB Coder
    Klaas van Aarsen's Avatar
    Status
    Offline
    Join Date
    Mar 2012
    Location
    Leiden
    Posts
    8,042
    Thanks
    5,286 times
    Thanked
    14,270 times
    Thank/Post
    1.774
    Awards
    MHB Pre-University Math Award (2018)  

MHB Model Helper Award (2017)  

MHB Best Ideas (2017)  

MHB Analysis Award (2017)  

MHB Calculus Award (2017)
    #5 Thread Author
    Quote Originally Posted by Opalg View Post
    This is really impressive. The only disappointment is that the Safari browser does not seem to support it. On my iMac the TikZ images display correctly if I use Firefox, Opera or Chrome, but not with Safari. It looks as though I'll have to switch to Firefox as my default browser.
    Hi Opalg, thanks for the feedback!

    Please try again. It should work for Safari now.

  7. MHB Oldtimer
    MHB Site Helper
    MHB Math Scholar
    Opalg's Avatar
    Status
    Online
    Join Date
    Feb 2012
    Location
    Leeds, UK
    Posts
    2,510
    Thanks
    858 times
    Thanked
    6,631 times
    Thank/Post
    2.642
    Awards
    MHB University Math Award (2018)  

MHB Challenges Solver Award (2017)  

Graduate POTW Award (2017)  

University POTW Award (2017)  

Secondary School/High School POTW Award (2017)
    #6
    Quote Originally Posted by I like Serena View Post
    It should work for Safari now.
    It does! Excellent!!

  8. Pessimist Singularitarian
    MHB Coder
    MHB Math Helper
    MHB Ambassador
    MarkFL's Avatar
    Status
    Offline
    Join Date
    Feb 2012
    Location
    St. Augustine, FL.
    Posts
    13,283
    Thanks
    34,201 times
    Thanked
    31,600 times
    Thank/Post
    2.379
    Trophies
    24 Highscores
    Awards
    MHB Chat Room Award (2017)  

MHB Calculus Award (2017)  

MHB Pre-University Math Award (2017)  

MHB Statistics Award (2016)  

MHB Calculus Award (2016)
    #7
    The feature is being improved, and so it is down for the time being. Sorry for any inconvenience.

    edit: The changes are now complete and the feature is up again.

  9. Pessimist Singularitarian
    MHB Coder
    MHB Math Helper
    MHB Ambassador
    MarkFL's Avatar
    Status
    Offline
    Join Date
    Feb 2012
    Location
    St. Augustine, FL.
    Posts
    13,283
    Thanks
    34,201 times
    Thanked
    31,600 times
    Thank/Post
    2.379
    Trophies
    24 Highscores
    Awards
    MHB Chat Room Award (2017)  

MHB Calculus Award (2017)  

MHB Pre-University Math Award (2017)  

MHB Statistics Award (2016)  

MHB Calculus Award (2016)
    #8
    Quote Originally Posted by caffeinemachine View Post
    This should be advertised on the first page of MHB and not just in a separate post. Anybody visiting the forum should see that he/she can post using tikz!
    Good suggestion!

    I have added this thread to our "Featured Threads" list, and put it in the top slot.

  10. زيد اليافعي
    MHB Site Helper
    MHB Math Helper
    ZaidAlyafey's Avatar
    Status
    Offline
    Join Date
    Jan 2013
    Location
    KSA
    Posts
    1,666
    Thanks
    3,673 times
    Thanked
    3,866 times
    Thank/Post
    2.321
    Awards
    MHB Math Notes Award (2014)  

MHB Best Ideas (2014)  

MHB Best Ideas (Jul-Dec 2013)  

MHB Analysis Award (Jul-Dec 2013)  

MHB Calculus Award (Jul-Dec 2013)
    #9
    Very nice. Anybody interested for a contour integration tutorial? Should be simpler now.

  11. MHB Seeker
    MHB Global Moderator
    MHB Math Scholar
    MHB Coder
    Klaas van Aarsen's Avatar
    Status
    Offline
    Join Date
    Mar 2012
    Location
    Leiden
    Posts
    8,042
    Thanks
    5,286 times
    Thanked
    14,270 times
    Thank/Post
    1.774
    Awards
    MHB Pre-University Math Award (2018)  

MHB Model Helper Award (2017)  

MHB Best Ideas (2017)  

MHB Analysis Award (2017)  

MHB Calculus Award (2017)
    #10 Thread Author
    Since a common application on MHB will probably be to show the graph of some function, here's another example.

    Latex Code:
    \begin{tikzpicture}
      %preamble \usepackage{pgfplots}
      \begin{axis}[xmin=-1.5, xmax=1.5, samples=101]
        \addplot[blue, ultra thick] (x, {cos(deg(x)) / (3*x^2 - pi^2)});
      \end{axis}
    \end{tikzpicture}



    Note in particular that $\cos$ takes degrees as a parameter instead of radians.

    I've added this example to the opening post as well.

Similar Threads

  1. pictures in signature
    By ineedhelpnow in forum Questions, Comments, and Feedback
    Replies: 4
    Last Post: September 10th, 2014, 17:49
  2. TikZ 3.0
    By dwsmith in forum TikZ Pictures
    Replies: 0
    Last Post: April 27th, 2014, 11:07
  3. tikz formatting
    By dwsmith in forum TikZ Pictures
    Replies: 6
    Last Post: January 20th, 2013, 20:12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Math Help Boards