# Having difficulty with pstricks box plot, psaxes, pspicture

a TeX noob here. I wish to plot performance test results once every two weeks (or sooner) displaying a 2 week window. I saw a similar question: Can I use pgfplots to make a boxplot

and the following answer looks very appealing:

\documentclass{article}
\usepackage{pst-plot}
\begin{document}

\begin{pspicture}(-1,-1)(12,14)
\psset{yunit=0.1,fillstyle=solid}
\psaxes[dy=1cm,Dy=10,ticksize=4pt 0,axesstyle=frame](0,0)(12,130)
\rput(1,0){\psBoxplot[fillcolor=red!30]{
100 90 120 115 120 110 100 110 100 90 100 100 120 120 120}}\rput(1,105){2001}
\rput(3,0){\psBoxplot[arrowlength=0.5,fillcolor=blue!30]{
90 120 115 116 115 110 90 130 120 120 120 85 100 130 130}}\rput(3,107){2008}
\rput(5,0){\psBoxplot[barwidth=40pt,arrowlength=1.2,fillcolor=red!30]{
35 70 90 60 100 60 60 80 80 60 50 55 90 70 70}}\rput(5,65){2001}
\rput(7,0){\psBoxplot[barwidth=40pt,fillcolor=blue!30]{
60 65 60 75 75 60 50 90 95 60 65 45 45 60 90}}\rput(7,65){2008}
\rput(9,0){\psBoxplot[fillcolor=red!30]{
20 20 25 20 15 20 20 25 30 20 20 20 30 30 30}}\rput(9,22){2001}
\rput(11,0){\psBoxplot[fillcolor=blue!30,linestyle=dashed]{
20 30 20 35 35 20 20 60 50 20 35 15 30 20 40}}\rput(11,25){2008}
\end{pspicture}
\end{document}


except that it does not quite do what I want it to do. I have obviously tried to modify this example to produce what I want, but I have been so unsuccessful, that I do not have anything else to share, since it won't help a bit. My attempts to re-adjust the coordinates (say to bound a rectangle at left bottom point (12, 40) and right upper point (27,45)) just would not do what I want it to do. They would still start at 0, or would show nothing or garbage. I did not feel like I can change one or two things and get closer to my goal. Too many settings that can potentially conflict, perhaps ... Below is a sample picture that I would like to generate (I drew it manually using Dia). The box plots in my picture all look the same only because it was simpler to copy and paste them. In reality they will be generated with three real numbers - run 1, run 2 and run 3 in minutes, for example: 42.456, 44.123, 43.854. Occasionally a test will not run correctly and I will need to display an error. I would highly appreciate if you could provide me with code that can generate something that looks like the picture below.

UPDATE: This worked with MikTeX 2.9 but not MikTeX 2.8 under Windows.

UPDATE2: Set Oy=4 if you want to raise the plot.

-

EDIT

I recommend the environment psgraph provided by the package pst-plot. In this way you can simple adjust the graph.

I build an example which produces a basis and hope it helps.

First the result ;-)

To simplify the work I created three new commands. The first one \weekday provided the day of the week whereby 1 represent Monday. In this way the labels of the axis are done.

The next two commands draw the rectangles. The command \simpleframe has the following syntax:

\simpleframe[options]
( coordinates of lower left corner )
( coordinates of upper right corner )
{text inside the frame}


The second new command is \complexframe which has the following syntax.

\complexframe[global options]
( coordinates of lower left corner )
( coordinates of upper right corner )
[options for the first line]
{y value of the first line}
[options for the second line]
{y value of the second line}
{text}


The default values are shown in the image.

\documentclass{article}
\usepackage[landscape]{geometry}
\usepackage{pst-plot}
\usepackage{xparse}
\newcount\daycount
\ExplSyntaxOn
\makeatletter
\DeclareDocumentCommand \weekday { m }
{
\prg_case_int:nnn
{  \int_mod:nn { #1 } { 7 }   }
{
{ 1 } {Mo}
{ 2 } {Tue}
{ 3 } {Wed}
{ 4 } {Thu}
{ 5 } {Fri}
{ 6 } {Sat}
{ 0 } {Son}
}
{error}
%}
}
\ExplSyntaxOff
\NewDocumentCommand \simpleframe { O{linecolor=black,linewidth=1pt,fillcolor=red!70,fillstyle=solid} r() r() m }
{
\begingroup
\psset{#1}
\pst@getcoor{#2}\pst@tempA
\pst@getcoor{#3}\pst@tempB
\psframe(!%
\pst@tempA /YA exch \pst@number\psyunit div def
/XA exch \pst@number\psxunit div def
XA YA
)(!
\pst@tempB /YB exch \pst@number\psyunit div def
/XB exch \pst@number\psxunit div def
XB YB
)
\rput(!%
\pst@tempA /YA exch \pst@number\psyunit div def
/XA exch \pst@number\psxunit div def
\pst@tempB /YB exch \pst@number\psyunit div def
/XB exch \pst@number\psxunit div def
){#4}
\endgroup
}

\NewDocumentCommand \complexframe { %
O{linecolor=black,linewidth=1pt,fillcolor=red!20,fillstyle=solid}% default option
r() r() %coordinates of the frame
O{linecolor=blue,linewidth=2pt} m  %y-value of the first line+option
O{linecolor=yellow,linewidth=2pt,linestyle=dashed} m % y-value of the second line+option
m %Text
}
{
\begingroup
\psset{#1}
\pst@getcoor{#2}\pst@tempA
\pst@getcoor{#3}\pst@tempB
\psframe(!%global frame
\pst@tempA /YA exch \pst@number\psyunit div def
/XA exch \pst@number\psxunit div def
XA YA
)(!
\pst@tempB /YB exch \pst@number\psyunit div def
/XB exch \pst@number\psxunit div def
XB YB
)
\rput(!%text
\pst@tempA /YA exch \pst@number\psyunit div def
/XA exch \pst@number\psxunit div def
\pst@tempB /YB exch \pst@number\psyunit div def
/XB exch \pst@number\psxunit div def
){#8}
\begingroup
\psset{#4}
\pst@getcoor{0,#5}\pst@tempC
\psline (!%first line
\pst@tempA /YA exch \pst@number\psyunit div def
/XA exch \pst@number\psxunit div def
\pst@tempC /YC exch \pst@number\psyunit div def
/XC exch \pst@number\psxunit div def
XA  YC)(!%
\pst@tempB /YB exch \pst@number\psyunit div def
/XB exch \pst@number\psxunit div def
\pst@tempC /YC exch \pst@number\psyunit div def
/XC exch \pst@number\psxunit div def
XB YC )
\endgroup
\begingroup
\psset{#6}
\pst@getcoor{0,#7}\pst@tempC
\psline (!%first line
\pst@tempA /YA exch \pst@number\psyunit div def
/XA exch \pst@number\psxunit div def
\pst@tempC /YC exch \pst@number\psyunit div def
/XC exch \pst@number\psxunit div def
XA  YC)(!%
\pst@tempB /YB exch \pst@number\psyunit div def
/XB exch \pst@number\psxunit div def
\pst@tempC /YC exch \pst@number\psyunit div def
/XC exch \pst@number\psxunit div def
XB YC )
\endgroup
\psframe[fillstyle=none](!%global frame again
\pst@tempA /YA exch \pst@number\psyunit div def
/XA exch \pst@number\psxunit div def
XA YA
)(!
\pst@tempB /YB exch \pst@number\psyunit div def
/XB exch \pst@number\psxunit div def
XB YB
)
\endgroup
}

\makeatother

\begin{document}
\psset{%
xAxisLabel={Day}, yAxisLabel={Whatever},
xAxisLabelPos={16,-15pt},yAxisLabelPos={-0.4in,c},
}

\begin{psgraph}[,Oy=0,labels=y]{->}(0,0)(16,21){0.8\linewidth}{10cm}
\psframe(0,0)(15,20.5)
\multido{\iA=1+1,\iB=14+1}{14}{%
\psxTick(\iA){\weekday{\iA}}%
\psxTick[labelsep=20pt](\iA){\iB}%
}

\simpleframe(3,3)(4,6){foo}

\complexframe(10,10)(12,20){14}{18}{foobar}

\end{psgraph}
\end{document}

-
Very cool! Final touch - what f I wanted to draw my own box? Since I only have 3 values and their average, it would not make sense for me to have the 25th and the 75th percentile. I would want the similar look and feel though - a colored rectangle with two lines in the middle and text. – The Dude May 11 '12 at 21:04
@TheDude: Do I understand it correct that you simple need a rectangle at a special position with some text? – Marco Daniel May 11 '12 at 21:08
That for the error (in red) plus a rectangle with two lines going across it in the middle of different color. Case 1: red rectangle from (3,3) to (4, 6) with text inside of it. Case 2: pink rectangle from (10, 10) to (12, 20) with some text inside of it, and also a line from (10, 14) to (12, 14) of the same color and thickness as the border plus another line from (10, 18) to (12, 18) of different color, dashed, and of different thickness. I will stop bugging you after that, I swear. – The Dude May 11 '12 at 21:37
@TheDude: I edited my example. – Marco Daniel May 12 '12 at 10:35
Thanks! Can you recommend some documents to go through so that I can understand some of that pstricks macro magic? Whatever is between \begin{document}' and \end{document}` is pretty readable to me. I'd like to find a document or two that would clue me in on syntax and details of the rest of what you did, so that I could modify the behavior of the macros/defs myself. – The Dude May 13 '12 at 15:02