Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

enter image description here

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!

share|improve this question
    
To be more exciting, I will present a bounty of 500 for the first satisfied answer. –  cyanide-based food Mar 8 '13 at 20:57

1 Answer 1

up vote 3 down vote accepted
+500
\documentclass[pstricks,border=0pt]{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}

\psset{unit=1cm}
\psset{llx=\POL cm,urx=\POR cm,lly=\POB cm,ury=\POT cm}

\begin{psgraph}[
        trigLabels=true,
        linecolor=gray,
        labelFontSize=\scriptscriptstyle,
        tickcolor=gray,
        ticksize=-1.5pt 1.5pt,
        xlabelsep=3pt,
        arrowscale=1,
        trigLabelBase=\TrigLabelBase,
        dx=\DeltaX]{->}(0,0)(\AxiL,\AxiB)(\AxiR,\AxiT)
         {\dimexpr \Width cm +\POL cm - \POR cm}
         {\dimexpr\Height cm +\POB cm - \POT cm}
    \psplot[linecolor=blue]{\DomL}{\DomR}{\f(x)}
\end{psgraph}

\end{document}
share|improve this answer
    
+1 but oh my ghost. You also made it depend on my defined \POR, etc. :-) I thought it can be simplified much. –  cyanide-based food Mar 11 '13 at 12:02
    
sure! nobody needs your definitions. psgraph can be used without all that. –  Herbert Mar 11 '13 at 12:06
    
So how dod you make use of \psgraph without using my defined \Axi*? –  cyanide-based food Mar 11 '13 at 12:15
    
use simple values and set the border with llx,lly,... that's all ... –  Herbert Mar 11 '13 at 12:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.