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.

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?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

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}
share|improve this answer
    
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? –  Who is crazy first Apr 24 '13 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.... –  David Carlisle Apr 24 '13 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. –  Herbert Apr 24 '13 at 13:10
    
@Bugbusters if in doubt do what Herbert says:-) –  David Carlisle Apr 24 '13 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? –  David Carlisle Apr 24 '13 at 13:36

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}
share|improve this answer

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.