In order to get a more balanced diagram (of a certain specified metric size, width
times height
), I usually also specify some offsets or adjustment values around the canvas (aka picture) and axes as follows. Note the annotations are added only to ease our discussion.
POT
and AOT
, for example, stand for P icture O ffset (aka canvas offset) and A xes O ffset, respectively. Canvas size and all offsets are usually in centimeter.
The following is my MWE. The annotation related codes have been removed for the sake of simplicity.
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl,pstricks-add}
\usepackage[nomessages]{fp}
\newcommand\const[3][3]{%
\expandafter\FPeval\csname#2\endcsname{round(#3:#1)}%
\pstVerb{/#2 \csname#2\endcsname\space def}%
}
% User defined data:
\def\f(#1){2.5*cos(2*#1)}% function to plot
\const{Width}{8}% total width in cm
\const{Height}{7}% total height in cm
\const{POL}{-1.00}% pspicture left offset in cm
\const{POR}{ 0.75}% pspicture right offset in cm
\const{POB}{-1.00}% pspicture bottom offset in cm
\const{POT}{ 0.75}% pspicture top offset in cm
\const{AOL}{-0.50}% axis left offset in cm
\const{AOR}{ 0.75}% axis right offset in cm
\const{AOB}{-0.50}% axis bottom offset in cm
\const{AOT}{ 0.75}% axis top offset in cm
\const{DomL}{-2*pi}% domain left
\const{DomR}{pi}% domain right
\const{DomB}{-3}% domain bottom
\const{DomT}{ 3}% domain top
\const[0]{TrigLabelBase}{2}% denominator for a fraction of pi
% Internal used constants:
\const{XUnit}{(Width-POR+POL-AOR+AOL)/(DomR-DomL)}
\const{YUnit}{(Height-POT+POB-AOT+AOB)/(DomT-DomB)}
\const{PicL}{(POL+AOL)/XUnit+DomL}
\const{PicR}{(POR+AOR)/XUnit+DomR}
\const{PicB}{(POB+AOB)/YUnit+DomB}
\const{PicT}{(POT+AOT)/YUnit+DomT}
\const{AxiL}{AOL/XUnit+DomL}
\const{AxiR}{AOR/XUnit+DomR}
\const{AxiB}{AOB/YUnit+DomB}
\const{AxiT}{AOT/YUnit+DomT}
\const{DeltaX}{pi/TrigLabelBase}
\psset{xunit=\XUnit,yunit=\YUnit,algebraic,plotpoints=500}
\begin{document}
\begin{pspicture}(\PicL,\PicB)(\PicR,\PicT)
\psplot[linecolor=blue]{\DomL}{\DomR}{\f(x)}
\psaxes
[
trigLabels=true,
linecolor=gray,
labelFontSize=\scriptscriptstyle,
tickcolor=gray,
ticksize=-1.5pt 1.5pt,
xlabelsep=3pt,
arrowscale=1,
trigLabelBase=\TrigLabelBase,
dx=\DeltaX,% must come before xunit to avoid getting a strange output!
]{->}(0,0)(\AxiL,\AxiB)(\AxiR,\AxiT)[$x$,0][$y$,90]
\end{pspicture}
\end{document}
Now I know that psgraph
can do scaling automatically based on the specified metric size (in centimeter, e.g.) of canvas on which graphs and axes are drawn.
The problem is how to setup the psgraph
to get the same result as what I already got above with pspicture
and psaxes
? psgraph
seems to be a promising syntactical sugar that can reduce more keystrokes!