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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Graphs in Latex

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


    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,757 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, Registered Users 2 Posts: 5,633 ✭✭✭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,757 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, Registered Users 2 Posts: 5,633 ✭✭✭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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 5,633 ✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 5,633 ✭✭✭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, Registered Users 2 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