The formatted output is enclosed by rframe. But for a certain case, the grid label of pspicture goes beyond the frame. The grid label of pspicture might be rendered outside TeX engine so TeX does not know the exact dimension for it.
Shortly speaking, how to enlarge \fboxsep for rframe? Bonus: Also let me know how to change its \fboxrule.

\documentclass{article}
\usepackage[paperwidth=13cm,paperheight=8cm,margin=0.5cm]{geometry}
\pagestyle{empty}
\usepackage{accsupp}
\newcommand*{\noaccsupp}[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}}
\usepackage{xcolor}
\usepackage{showexpl}
\makeatletter
% Add [t] to the parbox
\renewcommand\SX@CodeArea[2]{%
\parbox[t]{#1}{#2}
\rlap{\parbox[t]{#1}{\SX@attachfile}}}
% Add [t] to the parbox
\renewcommand\SX@ResultArea[2]{%
\SX@justification%
\parbox[t]{#1}{#2}%
}
% Add \hbox{} at the creation of \SX@ResBox, look up the comment
\renewcommand*\SX@put@code@result{%
\begingroup
\expandafter\lstset\expandafter{\SX@explpreset}%
\let\lst@float=\relax\let\SX@float=\relax
\expandafter\lstset\expandafter{\SX@@explpreset}%
\ifx\lst@float\relax\else
\let\SX@float=\lst@float\let\lst@float=\relax
\g@addto@macro\SX@@explpreset{,float=false}%
\edef\@tempa{\noexpand\lst@beginfloat{lstlisting}[\SX@float]}%
\expandafter\@tempa
\fi
\ifx\lst@caption\@empty
\lstset{nolol=true}%
\fi
\if@SX@wide\def\SX@overhang{\marginparwidth+\marginparsep}\fi
\trivlist\item\relax
\stepcounter{ltxexample}\label{\SX@IDENT}%
\SX@defaultWD\SX@width{\SX@width}%
\ifdim\SX@width<\z@
\@tempswatrue
\def\@tempa{t}%
\ifx\@tempa\SX@pos\@tempswafalse\fi
\def\@tempa{b}%
\ifx\@tempa\SX@pos\@tempswafalse\fi
\setlength\@tempdima{\linewidth+\SX@overhang}%
\if@tempswa\@tempdima=.5\@tempdima\fi%
\edef\SX@width{\the\@tempdima}%
\fi
\ifx\SX@rframe\@empty
\long\def\SX@frame##1{##1}%
\else
\let\SX@frame\fbox
\setlength\@tempdima{\SX@width-2\fboxsep-2\fboxrule}%
\edef\SX@width{\the\@tempdima}%
\fi
\isSX@odd{\def\@tempa{l}}{\def\@tempa{r}}%
\makebox[\linewidth][\@tempa]{%
\parbox{\linewidth+\SX@overhang}{%
\let\@addtofilelist\@gobble
\let\lst@ifdisplaystyle=\iftrue
\SX@KillAboveCaptionskip\lst@MakeCaption{t}%
\lst@belowskip=\z@
\let\SX@MakeCaption\lst@MakeCaption
\let\lst@MakeCaption\@gobble
\setbox\SX@ResBox\vtop{\hbox{}\hbox{% <---- HERE, modified line
\SX@frame{%
\@nameuse{\if@SX@varwidth varwidth\else minipage\fi}%
\SX@width\relax\SX@resultInput%
\@nameuse{end\if@SX@varwidth varwidth\else minipage\fi}}}}% <-- Also here, to close a brace
\edef\SX@width{\the\wd\SX@ResBox}%
\@ifundefined{SX@put@\SX@pos}%
{\@latex@error{Parameter `\SX@pos' undefined}\@ehd}%
{\@nameuse{SX@put@\SX@pos}%
{\SX@width}{\box\SX@ResBox}{\SX@codeInput}}%
\let\lst@MakeCaption\SX@MakeCaption
\lst@MakeCaption{b}\SX@KillBelowCaptionskip
}%
}%
\endtrivlist
\ifx\SX@float\relax\else\expandafter\lst@endfloat\fi
\gdef\SX@@explpreset{}%
\endgroup
}
\makeatother
\lstset
{
language={[LaTeX]TeX},
alsolanguage={PSTricks},
numbers=left,
numbersep=1em,
numberstyle=\tiny\color{red}\noaccsupp,
frame=single,
framesep=\fboxsep,
framerule=\fboxrule,
rulecolor=\color{red},
xleftmargin=\dimexpr\fboxsep+\fboxrule\relax,
xrightmargin=\dimexpr\fboxsep+\fboxrule\relax,
breaklines=true,
basicstyle=\scriptsize\ttfamily\null,% <--- Add \hbox{} here too
keywordstyle=\color{blue},
%identifierstyle=\color{magenta},
commentstyle=\color[rgb]{0.13,0.54,0.13},
backgroundcolor=\color{yellow!10},
tabsize=2,
columns=flexible,
explpreset={pos=r,hsep=2\fboxsep,preset=\centering},
morekeywords={
graphicspath,
includegraphics,
},
,
}
\usepackage{pstricks}
\begin{document}
\LTXexample
\begin{pspicture}[showgrid](5,5)
\end{pspicture}
\endLTXexample
\end{document}
If we can change rframe's \fboxsep=12pt, for example, we can have an output as follows:


pspicturesaves a box of the given size at the TeX level. In your case 5x5 cm. LaTeX nor XeLaTeX know the result of the postscript run. I know the labels are printed by TeX but outside of the given box. – Marco Daniel Jul 28 '12 at 20:02\llap{5}. Some days ago Herbert wrote this in a German community. – Marco Daniel Jul 28 '12 at 20:07