Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Graphs in Latex

Options
  • 01-02-2015 2:15pm
    #1
    Registered Users Posts: 5,619 ✭✭✭


    I'm trying to draw graphs in Latex.

    I found the following example on the internet which is exactly the sort of thing I'm looking for. Any help??


    6cALL.png


Comments

  • Moderators, Science, Health & Environment Moderators Posts: 4,692 Mod ✭✭✭✭Tree


    I usually render the graphs elsewhere and import them as png's or svg's depending on the graph. Can highly recommend using ggplot2 in R for making gorgeous graphics.


  • Registered Users Posts: 5,619 ✭✭✭TheBody


    Tree wrote: »
    I usually render the graphs elsewhere and import them as png's or svg's depending on the graph. Can highly recommend using ggplot2 in R for making gorgeous graphics.

    That's what I have always done in the past. I just thought I would have a go at doing it in Latex. I have found various existing pieces of code but they are all lacking in some regards.

    Thanks anyway.


  • Moderators, Science, Health & Environment Moderators Posts: 4,692 Mod ✭✭✭✭Tree


    You can use sweave to integrate the R, if you'd rather do it all in one file.

    I don't know anyone who generates any graphics in LaTeX that arent boxes around sections in a poster.


  • Registered Users Posts: 5,619 ✭✭✭TheBody


    Tree wrote: »
    You can use sweave to integrate the R, if you'd rather do it all in one file.

    I don't know anyone who generates any graphics in LaTeX that arent boxes around sections in a poster.

    As little as I know about Latex, I know ABSOLUTELY nothing about R!! I guess I'll muddle along with importing the graphs from elsewhere until I find a better fix!

    Thanks anyway.


  • Registered Users Posts: 26,578 ✭✭✭✭Turtwig


    LaTeX has vector graphics packages that are quite nice. Unfortunately it takes quite a bit of time to learn them and you have to constantly practice it. Otherwise you forget just how to use them. *cough* *cough*

    I agree with Tree. Just use something like gnuplot or R to create the graphs and let LaTeX encapsulate the image of the graph.

    If you don't want to go down this route. Then a vector graphics package like Tikz which, among many other things, allows you input mathematical functions and plot them, is what you're looking for.


  • Advertisement
  • Registered Users Posts: 339 ✭✭vanderlyle


    I like TikZ. Here is a decent introduction: cremeronline.com/LaTeX/minimaltikz.pdf

    Or this could be what you are looking for, it has lots of samples of graphs, varying in complexity: pgfplots.sourceforge.net/gallery.html

    For example, this will draw a quadratic function:

    \begin{tikzpicture}
    \begin{axis}[
    xlabel=$x$,
    ylabel={$f(x) = x^2 - x +4$}
    ]
    % use TeX as calculator:
    \addplot {x^2 - x +4};
    \end{axis}
    \end{tikzpicture}


  • Registered Users Posts: 5,619 ✭✭✭TheBody


    vanderlyle wrote: »
    I like TikZ. Here is a decent introduction: cremeronline.com/LaTeX/minimaltikz.pdf

    Or this could be what you are looking for, it has lots of samples of graphs, varying in complexity: pgfplots.sourceforge.net/gallery.html

    For example, this will draw a quadratic function:

    \begin{tikzpicture}
    \begin{axis}[
    xlabel=$x$,
    ylabel={$f(x) = x^2 - x +4$}
    ]
    % use TeX as calculator:
    \addplot {x^2 - x +4};
    \end{axis}
    \end{tikzpicture}


    Hi there!

    Thanks for the reply. That link with all those samples is great.

    One last thing. Do you know how to input vertical lines into the tex calulator? All the examples seem to need the statement in the form y= stuff. I need the line x=4. It doesn't seem to like that.


  • Registered Users Posts: 339 ✭✭vanderlyle


    TheBody wrote: »
    Hi there!

    Thanks for the reply. That link with all those samples is great.

    One last thing. Do you know how to input vertical lines into the tex calulator? All the examples seem to need the statement in the form y= stuff. I need the line x=4. It doesn't seem to like that.

    Try this, directly after/instead of the other addplot:

    \addplot[color=red,mark=none] coordinates {
    (4,-10)
    (4,90)
    };

    Or choose whatever coordinates are suitable for you.


  • Registered Users Posts: 5,619 ✭✭✭TheBody


    vanderlyle wrote: »
    Try this, directly after/instead of the other addplot:

    \addplot[color=red,mark=none] coordinates {
    (4,-10)
    (4,90)
    };

    Or choose whatever coordinates are suitable for you.

    That worked a treat! Thank you so much! You have no idea how much time I spent/wasted trying to get that to work.


  • Registered Users Posts: 339 ✭✭vanderlyle


    TheBody wrote: »
    You have no idea how much time I spent/wasted trying to get that to work.

    Oh believe me I know that feeling all too well. :)


  • Advertisement
Advertisement