4

In R it's easy to do something like

x <- seq(0, 2*pi, 0.01)
plot(sin(x), cos(3*x), type='line')

to get the plot

enter image description here

How can I make such a plot using tikz/pgfplots?

percusse
  • 157,807

1 Answers1

12

It is also easy with pgfplots

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot+[domain=0:360,samples=101,no marks] ({sin(x)},{cos(3*x)});
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

percusse
  • 157,807
  • I'd say: easier and prettier. – Sigur Aug 22 '15 at 15:09
  • 2
    +1 . Since this is an answer to a beginner question, I would like to advertise that \pgfplotsset{trig format plots=rad} in the preamble would reconfigure all plots to use radians. In this case, one could also write domain=0:2*pi to get the same outcome. – Christian Feuersänger Aug 22 '15 at 15:13
  • @ChristianFeuersänger Also may I suggest an alias for the compat key as assume version or somoething along those lines? That would make the users aware that there are compatibility options and also assume version=newest becomes a literal. – percusse Aug 22 '15 at 15:36
  • In principle: yes... but I am not sure if I want to substitute its occurrences in all examples. But that, in turn, would be necessary in order to make people aware of its existence. [...] – Christian Feuersänger Aug 22 '15 at 18:43
  • [...] And if they are not aware of it, it will add confusion rather than clarification, especially since compat is an established best-practise and people are used to it. And since assume version=newest sounds as if that would be a good idea, I would even more say that I would rather discourage people from it and not at the alias (newest is often a bad idea, see http://tex.stackexchange.com/questions/139690/dos-and-donts-of-pgfplotssetcompat-newest/139695#139695). With this reasoning, I would rather not follow the suggestion. If in doubt, let us discuss it by email. – Christian Feuersänger Aug 22 '15 at 18:44
  • @ChristianFeuersänger Probably, I wasn't clear. I didn't mean to replace compat. I was thinking along the lines of no marks and no markers situation. I don't think you should replace anything because it is well established. I'll think about it a little more on this. For the newest, I agree it is a little bit abused by the newcomers. – percusse Aug 23 '15 at 08:28