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.

pgfplots is not quite comfortable plotting sqrt(x) near x=0. The graphic can be improved by setting samples=2000 (not less), but this seems overkill to me.

Is there a way to plot x as a function of y, while keeping the x axis horizontal and the y axis vertical? This would solve the issue of plotting sqrt(x) by simply replacing it with x=y^2.

\documentclass{article}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
 \begin{axis}
  \addplot[] {sqrt(x)};
  \addplot[] {-sqrt(x)};
 \end{axis}
\end{tikzpicture}

\end{document}
share|improve this question

4 Answers 4

up vote 15 down vote accepted

You could use a parametrized plot:

enter image description here

Code:

\documentclass{article}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
 \begin{axis}
  \addplot[red, ultra thick] (x*x,x);
 \end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer
    
Great suggestion, thank you! Got me thinking outside of the box :) –  nemarona Sep 16 '12 at 6:57

Just for a comparison purpose how PSTricks does it with swapaxes option.

enter image description here

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}

\begin{document}

\begin{pspicture}(-3,-3)(5,5)
\psaxes[linecolor=gray]{->}(0,0)(-3,-3)(5,5)
\parabola[linecolor=blue](2,4)(0,0)
\parabola[linecolor=red,swapaxes](2,4)(0,0)
\end{pspicture}

\end{document}

Note:

\parabola[linecolor=red,swapaxes](2,4)(0,0)

passes through the point (2,4) with a critical point (0,0).

share|improve this answer
    
That's exactly what I was looking for. Is there a way to do the same in pgfplots? –  nemarona Sep 16 '12 at 6:58
    
@nemarona: If such an option does not exist in pgf/tikz, then you might have to use a transformation (rotation is enough). –  In PSTricks we trust Sep 16 '12 at 8:36
    
"swap axes" in pgfplots means to use a parametric plot as in the answer of Peter Grill - and exchanging the X and Y expressions manually. –  Christian Feuersänger Sep 16 '12 at 16:59
    
@ChristianFeuersänger: Thank you for the useful information. –  In PSTricks we trust Sep 16 '12 at 17:01

Use rotation. Here is the minimal code:

enter image description here

\documentclass[tikz,border=12pt]{standalone}

\begin{document}
\begin{tikzpicture}
\begin{scope}[rotate=-90]
    \draw[domain=-2:2] plot (\x,\x*\x);
\end{scope}
\end{tikzpicture}
\end{document}
share|improve this answer
1  
Rotations are not inverse functions! E.g. y=x –  strpeter Jan 22 at 21:53
    
@strpeter: Yes of course but nobody knows if you just see the image. –  In PSTricks we trust Mar 20 at 3:04
1  
@strpeter: The problem is that the question is misleading so I just followed what the questioner wanted to get no matter his incorrect usage of the term "inverse function". I understand that inverse function must have a single value for each input. –  In PSTricks we trust Mar 20 at 22:52

I don't quite understand the mathematics side of it, but I often use R to produce my graphics using tikzDevice.

R code (produces tex then graphic):

library(tikzDevice)
tikz('normal.tex', standAlone = TRUE, width=5, height=5)
x <- seq (-50, 50, length = 50)
xx <-x^2
plot(xx, type="l")
dev.off()

enter image description here

share|improve this answer
    
One step more is needed to rotate the graph 90 degree clockwise. –  In PSTricks we trust Sep 16 '12 at 9:08

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.