4

Is it possible to get the following output where the upper graph is red and the lower one is blue

enter image description here

\documentclass[pstricks,border=17pt]{standalone}
\usepackage{pst-plot}
\psset{algebraic,linewidth=1pt}

\begin{document}

\begin{psgraph}{->}(0,0)(5,2.5){6cm}{5cm}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=orange]
{
  \psplot{1}{4}{sqrt(x)}
    \psplot{4}{1}{sqrt(x/2)}
}
\psplot[linecolor=red]{1}{4}{sqrt(x)}
\psplot[linecolor=blue]{4}{1}{sqrt(x/2)}
\end{psgraph}
\end{document}

only by using a single \pscustom inside \psgraph (no \psplot outside \pscustom for sure!)?

My attempt is as follows but it fails because both graphs are blue.

enter image description here

\documentclass[pstricks,border=17pt]{standalone}
\usepackage{pst-plot}
\psset{algebraic,linewidth=1pt}

\begin{document}

\begin{psgraph}{->}(0,0)(5,2.5){6cm}{5cm}
\pscustom[linestyle=none]
{
  \psplot{1}{4}{sqrt(x)}
    \stroke[linestyle=solid,linecolor=red]
    \gsave
  \psplot{4}{1}{sqrt(x/2)}
    \fill[fillstyle=solid,fillcolor=orange]
    \grestore
    \psplot[liftpen=2]{4}{1}{sqrt(x/2)}
    \stroke[linestyle=solid,linecolor=blue]
}
\end{psgraph}

\end{document}

Is it possible to construct more than one stroke with different colors inside a single \pscustom?

2 Answers 2

7

enter image description here

\documentclass[pstricks,border=17pt]{standalone}
\usepackage{pst-plot}
\psset{algebraic,linewidth=1pt}

\begin{document}

\begin{psgraph}{->}(0,0)(5,2.5){6cm}{5cm}
\pscustom[linestyle=none]
{
  \psplot{1}{4}{sqrt(x)}
    \gsave
    \stroke[linestyle=solid,linecolor=red]
  \psplot{4}{1}{sqrt(x/2)}
    \fill[fillstyle=solid,fillcolor=orange]
    \grestore
    \newpath
    \psplot[liftpen=2]{4}{1}{sqrt(x/2)}
    \stroke[linestyle=solid,linecolor=blue]
}
\end{psgraph}

\end{document}
5
  • Can you give some explanation how the code work? Why do we need to swap the first 3 rows? And why do we need a new path? Apr 24, 2013 at 12:39
  • @Bugbusters I guessed and got lucky:-) I can't really remember any pstricks but in postscript if you want to draw two paths with different stroke settings you need a newpath operator somewhere so I guessed there was a pstricks \newpath command and guessed putting it there might help.... Apr 24, 2013 at 12:44
  • that is wrong, because "one path -- one stroke". The read line has only the half width because the filling area is above the other half of the line.
    – user2478
    Apr 24, 2013 at 13:10
  • @Bugbusters if in doubt do what Herbert says:-) Apr 24, 2013 at 13:22
  • @Herbert yes I suppose subconsciously I noticed that and ignored it, I assume the red line could be stroked last to get back on top of the fill? Apr 24, 2013 at 13:36
0

Using \pscustom with gsave-grestore seems to be overkill.

\documentclass[pstricks,border=17pt]{standalone}
\usepackage{pst-plot}
\psset{algebraic,linewidth=1pt}

\begin{document}

\begin{psgraph}{->}(0,0)(5,2.5){6cm}{5cm}
\pscustom[linestyle=none]
{
  \gsave  
    \psplot{1}{4}{sqrt(x)}
    \psplot{4}{1}{sqrt(x/2)}
    \fill[fillstyle=solid,fillcolor=orange]
  \grestore 
  \newpath
  \psplot{1}{4}{sqrt(x)}
  \stroke[linestyle=solid,linecolor=red]
  \newpath
  \psplot{4}{1}{sqrt(x/2)}
  \stroke[linestyle=solid,linecolor=blue]
}
\end{psgraph}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .