Graphics, Figures & TablesResize pspicture (not using \resizebox or \psscalebox)

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
smr01cmh
Posts: 14
Joined: Thu May 13, 2010 1:23 am

Resize pspicture (not using \resizebox or \psscalebox)

Post by smr01cmh »

Hi all,
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}
Last edited by smr01cmh on Wed Mar 02, 2011 9:07 pm, edited 3 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Re: Resize pspicture (not using \resizebox or \psscalebox)

Post by frabjous »

Could you simply change the value of pstricks's unit? (It suggests doing this to scale graphics on p. 6 of the pstricks manual.)
smr01cmh
Posts: 14
Joined: Thu May 13, 2010 1:23 am

Re: Resize pspicture (not using \resizebox or \psscalebox)

Post by smr01cmh »

Yes, that's what my code does, according to the value of xmin, xmax, and the desired width.

I just wondered if there was an in-built way of doing it.
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

Resize pspicture (not using \resizebox or \psscalebox)

Post by CrazyHorse »

smr01cmh wrote:Yes, that's what my code does, according to the value of xmin, xmax, and the desired width.

I just wondered if there was an in-built way of doing it.
eg, before pspicture:

Code: Select all

\psset{unit=2}
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Resize pspicture (not using \resizebox or \psscalebox)

Post by frabjous »

CrazyHorse wrote: eg, before pspicture:

Code: Select all

\psset{unit=2}
smr01cmh's code is already using that command. I should have looked at it more carefully; it's a neat way of accomplishing something more like \resizebox, whereas using \psset{unit=X} alone only accomplishes something similar to \scalebox. I think it's pretty clever, and I for one don't know of a better way to accomplish this, at least not for pstricks. Maybe someone else will.
smr01cmh
Posts: 14
Joined: Thu May 13, 2010 1:23 am

Resize pspicture (not using \resizebox or \psscalebox)

Post by smr01cmh »

The trouble with \resizebox is that everything gets scaled, including labels and text, which can make for an ugly picture in the context of the document.

Using \psset{unit=...} on its own is fine, but one has no idea how big the picture is going to end up; I have a lot of pspictures and I don't want to have to worry about tweaking \psset{unit=...} for each one individually, hence my code.
smr01cmh
Posts: 14
Joined: Thu May 13, 2010 1:23 am

Resize pspicture (not using \resizebox or \psscalebox)

Post by smr01cmh »

I think that the newly-defined psgraph in pst-plot accomplishes this. The latest pst-plot.pdf describes it; it was only released a month ago, so I don't feel too bad for missing it. :)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Resize pspicture (not using \resizebox or \psscalebox)

Post by localghost »

smr01cmh wrote:I think that the newly-defined psgraph in pst-plot accomplishes this. The latest pst-plot.pdf describes it; it was only released a month ago, so I don't feel too bad for missing it. […]
The psgraph environment is not new and has been part of pstricks-add for a long time before it was moved to pst-plot.


Thorsten
Post Reply