Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

To plot functions in the form of y=f(x), we simply write‎

‎\draw ‎[‎smooth,‎samples=100‎,domain=0:‎‎2‎‎] ‎plot(\x,‎‎‎‎‎‎‎‎{(\x)...‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎});‎‎

But how about functions like x=f(y)? How to plot them? How to specify their domains ‎in terms of "y"‎?

\documentclass{article}
\usepackage{tikz} 
\begin{document}
\begin{tikzpicture}
\draw [smooth,samples=100,domain=0:2] plot(???);
\end{tikzpicture}
\end{document}
share|improve this question
2  
I'm not sure I understand your question properly. Do you have an expression for f(y) or do you want to determine the inverse of a function f(x)? Or do you just want to change the name of the variable in your plot? Would \draw[domain=0:2,variable=\y] plot({f(\y)},\y); work for you? –  benwilfut Mar 27 '13 at 16:05
    
I agree with benwilfut's comment. I did not read this comment when I posted my answer. I can delete this answer –  Alain Matthes Mar 27 '13 at 17:07

4 Answers 4

up vote 14 down vote accepted
\begin{tikzpicture}
  \draw[->] (-3,0) -- (4.2,0) node[right] {$x$};
  \draw[->] (0,-3) -- (0,4.2) node[above] {$y$};
  \draw[scale=0.5,domain=-3:3,smooth,variable=\x,blue] plot ({\x},{\x*\x});
  \draw[scale=0.5,domain=-3:3,smooth,variable=\y,red]  plot ({\y*\y},{\y});
\end{tikzpicture}

enter image description here

share|improve this answer

This will work with the gnuplot backend.

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  \tikzset{swapaxes/.style = {rotate=90,yscale=-1}}
  \draw[red] plot[samples=200,domain=-1:2] function {x**2};
  \draw[blue,swapaxes] plot[samples=200,domain=-1:2] function {x**2};
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer

I agree that parametric is the way to go, but one really should be using pgfplots for this kind of thing:

enter image description here

Code:

\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[xmax=9,ymax=9, samples=50]
  \addplot[blue, ultra thick] (x,x*x);
  \addplot[red,  ultra thick] (x*x,x);
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer

With PSTricks' swapaxes.

enter image description here

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}
\psset{algebraic}
\begin{document}
\begin{pspicture}[showgrid](-2,-2)(2,2)
    \psplot{-1}{1}{x^2}
    \psplot[linecolor=red,swapaxes]{-1}{1}{x^2}
\end{pspicture}
\end{document}

Or with PSTricks' \rput and \psscalebox.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}
\psset{algebraic}
\begin{document}
\begin{pspicture}[showgrid](-2,-2)(2,2)
    \psplot{-1}{1.4}{x^2}
    \psscalebox{1 -1}{\rput{-90}(0,0){\psplot[linecolor=red]{-1}{1.4}{x^2}}}
\end{pspicture}
\end{document}

Unfortunately, PSTricks has another method with parametric curve as follows.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}
\psset{algebraic}
\begin{document}
\begin{pspicture}[showgrid](-2,-2)(2,2)
    \psplot{-1}{1.4}{x^2}
    \psparametricplot[linecolor=red]{-1}{1.4}{t^2|t}
\end{pspicture}
\end{document}
share|improve this answer
    
I meant TikZ, not PSTricks. –  Sisabe Mar 27 '13 at 16:02
1  
@Sisabe: Yes. It is only for those who are using or interested in PSTricks. –  In PSTricks we trust Mar 27 '13 at 16:03
    
Aren't you missing a reflexion with the \rput version? –  cjorssen Mar 27 '13 at 17:25
    
@cjorssen: done! –  In PSTricks we trust Mar 28 '13 at 0:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.