I'd like the ability to re-size my pspicture to a specified width, but I don't want to use \resizebox or \psscalebox. The reason I don't want to use either of these options is that they both scale the font size of the labels, and any other text within the graphic.
I've found a way to do this (see MWE below), but I'm interested to see if anyone has a better way of doing it.
PS: I realize that my code doesn't account for cases when xmin & xmax are less than 1 in absolute value (and probably others too).
Code: Select all
\documentclass{article}
\usepackage{pstricks}
\usepackage{pstricks-add}
\newlength{\figurewidth}
\makeatletter
\newcommand{\setwindow}[5]{\def\xmin{#1}%
\def\ymin{#2}%
\def\xmax{#3}%
\def\ymax{#4}%
\pstFPsub\viewingwidth{#3}{#1}%
\pstFPdiv\result{\strip@pt#5}{\viewingwidth}%
\psset{unit=\result pt}}
\makeatother
\begin{document}
\setlength{\figurewidth}{5cm}
\setwindow{-10}{-10}{10}{10}{\figurewidth}
\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)
\psgrid[subgriddiv=0,gridcolor=lightgray,gridlabels=0]
\psaxes{<->}(0,0)(\xmin,\ymin)(\xmax,\ymax)
\psplot{-10}{10}{x}
\end{pspicture}
\end{document}