# Drawing half a parabola using pstricks in LaTeX

I am trying to create some typed notes about Dynamical Systems, and as part of this I wish to draw a stability diagram; this requires me to have a parabola of the form $r = x^2$, however, one half of the parabola needs to be dashed and the other half needs to be solid.

I am using pstricks with dvips->ps2pdf and my code currently looks like this:

\begin{figure}[H]
\centering
\begin{pspicture}(5,5)
\psline{->}(0,2.5)(5,2.5)
\psline{->}(2.5,0)(2.5,5)
\rput(2.75,4.8){$r$}
\rput(4.8,2.25){$x$}
\psparabola(4.08,0)(2.5,2.5)
\end{pspicture}
\end{figure}


But I wish for one half of the parabola to be dashed and the other half to be solid. Is there an easy way to do this with pstricks?

• instead of dvips->ps2pdf you can your document with xelatex
– user2478
Dec 30, 2015 at 21:11

The pstricks and tikz solutions above use a parametric version of the parabola, plotting many points on a quadratic function. In both cases you can use a single Bézier instead, using the recipe from my solution here: How to draw rotated parabola in LaTeX with using tikz and Bezier curve?

Here is a modified version of your code:

\documentclass{standalone}
\usepackage{pstricks}
\begin{document}

\begin{pspicture}(5,5)
\psline{->}(0,2.5)(5,2.5)
\psline{->}(2.5,0)(2.5,5)
\rput(2.75,4.8){$r$}
\rput(4.8,2.25){$x$}
%     \psparabola(4.08,0)(2.5,2.5)
\psbezier(2.5,2.5)(3.027,2.5)(3.553,1.666)(4.08,0)
\psbezier[linestyle=dashed](2.5,2.5)(1.973,2.5)(1.447,1.666)(0.92,0)
\end{pspicture}

\end{document}


The control points for the first parabolic arc are from trisecting the intervals 2.5≤x≤4.08 and 0≤r≤2.5. If you were going to do several of these, you could write some code to do these calculations.

Here is how to do it easily with pst-plot. You just have to plot the function x² twice, once with a solid line, one with a dashed line. Note it can perfectly be compiled with pdflatex if you load auto-pst-pdf after pstricks, provided pdflatex is launched with the --enable-write18 switch (MiKTeX) or -shell-escape (TeX Live, MacTeX). Also, there exists a \psaxes command:

\documentclass[x11names, border=3pt]{standalone}
\usepackage{auto-pst-pdf}

\begin{document}

\psset{ algebraic, arrowinset=0.2, arrowsize=2.5pt, arrowlength=1, linejoin=1}
\begin{pspicture*}(-4.9,-1)(5,5)
\psaxes[arrows=->, linecolor=SlateGray3, ticks=none, labels=none]{->}(0,0)(-5,0)(5,5)[$x$, -120][$r$, -140]
\uput[dl](0,0){$O$}
\psset{linewidth=1.2pt, linecolor=IndianRed3, plotpoints=200}
\psplot{0}{5}{x^2}
\psplot[linestyle=dashed, dash=6pt 3pt]{-5}{0}{x^2}
\end{pspicture*}

\end{document}


I don't know PSTricks and think that pgfplots is state of the art by now :). But if you need to use PSTricks then I will delete my answer of course.

On the other hand - a quick Google search revealed that probably the linestyle=dashed option should do the trick. Just draw the parabola half by half.

There is a very powerful package called pgfplots (CTAN link). It has many many features and maybe in the beginning the documentation is overwhelming.

If you are new to LaTeX I would recommend to draw it with another software and just put the picture in the document.

But if you have enough time then you should consider to learn more about pgfplots and the underlying tikz/pgf package (CTAN link).

\documentclass{article}

% CTAN: https://www.ctan.org/tex-archive/graphics/pgf/contrib/pgfplots
\usepackage{pgfplots}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}
[
title={Stable System},
xlabel={$x$},
ylabel={$r(x)$},
]
%
% right half
[
domain={0:5},
]{x^2};
%
% left half
[
domain={-5:0},
dashed,
]{x^2};
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}


It seems, that it is difficult to compete with pgfplots with pstrick pst-plots ... In this pure TikZ can come closer:

\documentclass[border=3pt,tikz,preview]{standalone}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}[
L/.style = {draw = blue!50!gray!30!white,-{Stealth[]}}
]
\draw[L]    (-4, 0) -- (4,0) node[pos=1,below left] {$x$};
\draw[L]    (0,-.1) node[below] {$0$} -- (0,5) node[below left] {$r(x)$};
% right half
\draw[red,thick,domain={-3:0},dashed]   plot (\x,{0.5*(\x)^2});
% left half
\draw[red,thick,domain={0:3}]           plot (\x,{0.5*(\x)^2});
\end{tikzpicture}
\end{document}


Since question was aboutpstrick, this answer is more for exercise :-) (and for showing alternative possibilities).

• Frankly, I don't see in what respect pure TikZ comes closer than pgfplots or pst-plot. It mainly seems to be a matter of personal taste ;o) Dec 31, 2015 at 1:19
• Yes, it is personal opinion. In this particular -- simple -- case, the pgfplots is overwhelm with his rich features, which is not needed here. To draw present picture about one third code is needed for exclude automatic labeling etc. Maybe I'm wrong. Dec 31, 2015 at 1:34