# Scaling a pst-3dplot to fit a Beamer frame

I'm new to pstricks. I was looking for an automatic way of resizing a plot.

I'm trying to fit a 3d plot, generated using pst-3dplot, into a beamer frame. However, I'm not able to make it look good automatically.

If I set some frame coordinates to the pspicture then just a part of the plot appears. And if I set no coordintaes, then there is no plot. I also try using \psset(unit=1mm) but it compresses the plot and doesn't look good. Is there a way to figure it out without having to recompile hundreads of times? Is there a way to make it resize automatically to the frame size?

This is an example of what I'm doing:

\documentclass{beamer}

% For the figures
\usepackage[pdf]{pstricks}
\usepackage{auto-pst-pdf}
\usepackage{pst-node, pst-plot, pst-circ, pst-3dplot}
\usepackage{moredefs}

\begin{document}

\begin{frame}{3D}
\begin{center}

\begin{pspicture}%(-5,3)(5,-3)%<-uncomment this and just a part appears
\pstThreeDCoor[linecolor=black, IIIDticks,IIIDlabels,xMin=-20,xMax=20,yMin=-20, yMax=20,zMin=0,zMax=35]
\fileplotThreeD[linecolor=blue,plotstyle=line]{data.txt}
\end{pspicture}
\end{center}
\end{frame}

\end{document}


The data.txt file is here

-
You can use \resizebox. –  Marco Daniel Oct 29 '11 at 10:47
@MarcoDaniel: thanks, that solve the resizing problem of the graphic. However, the text (ticks, legends, labels, etc.) is not readable if I just scale down. That's why I was asking for an automatic way using pstricks. Or should I just increase the size, or better do it somewhere else and just import as a figure. –  adn Oct 29 '11 at 11:04

I use PSTricks a lot, and have struggled with this issue as well. It seems that when you use \psset you don't really have complete control over the size of the resultant figure.

Below is a solution that I use to specify the size of the figure that will calculate the appropriate value of xunit and yunit.

The \setwindow command that I have defined takes 5 arguments, most of which should be self-explanatory: in order they are

• \xmin
• \ymin
• \xmax
• \ymax
• \figurewidth

Here is the MWE

\documentclass{beamer}

% For the figures
\usepackage[pdf]{pstricks}
\usepackage{auto-pst-pdf}
\usepackage{pst-node, pst-plot, pst-circ, pst-3dplot}
\usepackage{moredefs}

\newlength{\figurewidth}
% setwindow command: takes 6 arguments (1st is optional)
%       [1]. aspect ratio (height = aspect ratio * width) default=1
%         2. xmin (number)
%         3. ymin (number)
%         4. xmax (number)
%         5. ymax (number)
%         6. figurewidth (length)
\makeatletter
\newcommand{\setwindow}[6][1]{\def\xmin{#2}%
\def\ymin{#3}%
\def\xmax{#4}%
\def\ymax{#5}%
% set up xunit
\pstFPsub\viewingwidth{#4}{#2}%
\pstFPdiv\result{\strip@pt#6}{\viewingwidth}%
\psset{xunit=\result pt}
% set up yunit
\pstFPsub\viewingheight{#5}{#3}%
\pstFPdiv\result{\strip@pt#6}{\viewingheight}%
% set up aspect ratio
\pstFPmul\result{\result}{#1}%
\psset{yunit=\result pt}%
}
\makeatother

\begin{document}

\begin{frame}{3D}

\centering
\setlength{\figurewidth}{9cm}
\setwindow{-20}{-20}{20}{30}{\figurewidth}
%\begin{pspicture}(-5,3)(5,-3)%<-uncomment this and just a part appears
\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)
\pstThreeDCoor[linecolor=black, IIIDticks,IIIDlabels,xMin=\xmin,xMax=\xmax,yMin=\ymin, yMax=\ymax,zMin=0,zMax=35]
\fileplotThreeD[linecolor=blue,plotstyle=line]{data.txt}
\end{pspicture}

\end{frame}

\end{document}


The \setwindow command takes an optional argument which you can use to tweak the aspect ratio. For example, if you use

\setwindow[0.25]{-20}{-20}{20}{30}{\figurewidth}


then the height of the picture will be 1/4 the width.

The nice thing about this approach is that you choose the width and then calculate the values of xunit and yunit and not vice-versa. It removes the guess work involved with \psset.

-
Thanks this those the scaling of the figure. However, when reducing the size of the figure, the labels are all overlapped. Is there a way to automatically reduce the number of ticks that appear if the figure is smaller. Because all the time appear all the ticks (1 step apart). –  adn Oct 30 '11 at 7:40
@adn I have struggled with that issue too. I don't think there is a way to do it automatically- you have to scale the picture and then check the ticks. –  cmhughes Oct 30 '11 at 14:58
Thanks, I think I will do that then. By the way, this command is really useful. It would be great if it is in a package. –  adn Oct 31 '11 at 1:28
...
\psset{unit=0.2}
\begin{pspicture}(-5,-1)(5,20)
...

-