4

Case 1

The labels in y axis are multiples of \frac{\sqrt{3}}{3} while the labels in x axis are multiples of \frac{\pi}{4}.

I want to rename \pi as \sqrt{3} only for y axis without affecting the original meaning of \pi used in x axis. How to do so?

enter image description here

\documentclass[pstricks,border={3pt 3pt 15pt 15pt},12pt]{standalone}
\usepackage{pst-plot,pst-calculate}
\usepackage[nomessages]{fp}

\FPset\EPSILON{0.3}

\FPeval\Const{root(2,3)}

\FPeval\Left{0-pi}
\FPeval\Right{2*pi}

\FPeval\Top{Const}
\FPeval\Bottom{0-Const}


\FPset\xTrigLabelBase{4}
\FPset\yTrigLabelBase{3}

\FPset\Dx{1}
\FPset\Dy{1}

\FPeval\dx{pi/xTrigLabelBase*Dx}
\FPeval\dy{Const/yTrigLabelBase*Dy}

\FPeval\XUnit{15/(Right-Left)}
\FPeval\YUnit{6/(Top-Bottom)}

\psset
{
    xunit=\XUnit,
    yunit=\YUnit,
    dx=\dx,
    Dx=\Dx,
    dy=\dy,
    Dy=\Dy,
    xtrigLabels,
    ytrigLabels,
    xtrigLabelBase=\xTrigLabelBase,
    ytrigLabelBase=\yTrigLabelBase,
    showorigin=false,
}



\begin{document}
\begin{pspicture}(\pscalculate{\Left-\EPSILON},\pscalculate{\Bottom-\EPSILON})(\pscalculate{\Right+\EPSILON},\pscalculate{\Top+\EPSILON})
    \psplot[algebraic,linecolor=red,plotpoints=100,linewidth=2\pslinewidth]{\Left}{\Right}{\Const*sin(x)}
    %\def\pi{\sqrt{3}}
    \psaxes{<->}(0,0)(\pscalculate{\Left-\EPSILON},\pscalculate{\Bottom-\EPSILON})(\pscalculate{\Right+\EPSILON},\pscalculate{\Top+\EPSILON})[$x$,0][$y$,90]
\end{pspicture}
\end{document}

Case 2

Red-Cloud's answer works for the first case in which the constant is \sqrt{3}. Unfortunately, if I change to 1, the output does not make sense as follows. Instead of making an new question, could you make it work as well for 1?

enter image description here

\documentclass[pstricks,border={3pt 3pt 15pt 15pt},12pt]{standalone}
\usepackage{pst-plot,pst-calculate}
\usepackage[nomessages]{fp}

\FPset\EPSILON{0.3}

\FPeval\Const{1}%{root(2,3)}

\FPeval\Left{0-pi}
\FPeval\Right{2*pi}

\FPeval\Top{2*Const}
\FPeval\Bottom{0-Const}


\FPset\xTrigLabelBase{4}
\FPset\yTrigLabelBase{3}

\FPset\Dx{1}
\FPset\Dy{1}

\FPeval\dx{pi/xTrigLabelBase*Dx}
\FPeval\dy{Const/yTrigLabelBase*Dy}

\FPeval\XUnit{15/(Right-Left)}
\FPeval\YUnit{6/(Top-Bottom)}

\psset
{
    xunit=\XUnit,
    yunit=\YUnit,
    dx=\dx,
    Dx=\Dx,
    dy=\dy,
    Dy=\Dy,
    xtrigLabels,
    ytrigLabels,
    xtrigLabelBase=\xTrigLabelBase,
    ytrigLabelBase=\yTrigLabelBase,
    showorigin=false,
}

\makeatletter
\let\pst@@VLabels\pst@@vlabels
\def\pst@@vlabels{\def\pi{1}\pst@@VLabels}
\makeatother

\begin{document}
\begin{pspicture}(\pscalculate{\Left-\EPSILON},\pscalculate{\Bottom-\EPSILON})(\pscalculate{\Right+\EPSILON},\pscalculate{\Top+\EPSILON})
    \psplot[algebraic,linecolor=red,plotpoints=100,linewidth=2\pslinewidth]{\Left}{\Right}{\Const*sin(x)}
    \psaxes{<->}(0,0)(\pscalculate{\Left-\EPSILON},\pscalculate{\Bottom-\EPSILON})(\pscalculate{\Right+\EPSILON},\pscalculate{\Top+\EPSILON})[$x$,0][$y$,90]
\end{pspicture}
\end{document}
0

2 Answers 2

2
\makeatletter
\let\pst@@VLabels\pst@@vlabels
\def\pst@@vlabels{\def\pi{\sqrt3}\pst@@VLabels}
\makeatother
\begin{document}
[...]
\end{document}
1
  • page 39 of the pst-plot documentation
    – user187802
    May 9, 2019 at 19:43
5

I don't think there is (that is, I didn't find) a built-in way to do that. With etoolbox you can patch the code for the x and y labels to add arbitrary definitions:

\usepackage{etoolbox}
\makeatletter
\patchcmd\pst@@vlabels
  {\vbox to -\psk@ylabelOffset}
  {\YAxis@labelHook@code\vbox to -\psk@ylabelOffset}
  {}{\FailedToPatch}
\define@key[psset]{pst-plot}{ExecuteBeforeYLabels}[]{\def\YAxis@labelHook@code{#1}}
\patchcmd\pst@@hlabels
  {\ifcase\psk@xlabelPos}
  {\XAxis@labelHook@code\ifcase\psk@xlabelPos}
  {}{\FailedToPatch}
\define@key[psset]{pst-plot}{ExecuteBeforeXLabels}[]{\def\XAxis@labelHook@code{#1}}
\psset{
  ExecuteBeforeYLabels={},
  ExecuteBeforeXLabels={},
}
\makeatother

then you just need:

\psset{ExecuteBeforeYLabels={\def\pi{\sqrt{3}}}}

enter image description here

Full code:

\documentclass[pstricks,border={3pt 3pt 15pt 15pt},12pt]{standalone}
\usepackage{pst-plot,pst-calculate}
\usepackage[nomessages]{fp}

\FPset\EPSILON{0.3}

\FPeval\Const{root(2,3)}

\FPeval\Left{0-pi}
\FPeval\Right{2*pi}

\FPeval\Top{Const}
\FPeval\Bottom{0-Const}

\FPset\xTrigLabelBase{4}
\FPset\yTrigLabelBase{3}

\FPset\Dx{1}
\FPset\Dy{1}

\FPeval\dx{pi/xTrigLabelBase*Dx}
\FPeval\dy{Const/yTrigLabelBase*Dy}

\FPeval\XUnit{15/(Right-Left)}
\FPeval\YUnit{6/(Top-Bottom)}

\usepackage{etoolbox}
\makeatletter
\patchcmd\pst@@vlabels
  {\vbox to -\psk@ylabelOffset}
  {\YAxis@labelHook@code\vbox to -\psk@ylabelOffset}
  {}{\FailedToPatch}
\define@key[psset]{pst-plot}{ExecuteBeforeYLabels}[]{\def\YAxis@labelHook@code{#1}}
\patchcmd\pst@@hlabels
  {\ifcase\psk@xlabelPos}
  {\XAxis@labelHook@code\ifcase\psk@xlabelPos}
  {}{\FailedToPatch}
\define@key[psset]{pst-plot}{ExecuteBeforeXLabels}[]{\def\XAxis@labelHook@code{#1}}
\psset{
  ExecuteBeforeYLabels={},
  ExecuteBeforeXLabels={},
}
\makeatother

\psset
{
    xunit=\XUnit,
    yunit=\YUnit,
    dx=\dx,
    Dx=\Dx,
    dy=\dy,
    Dy=\Dy,
    xtrigLabels,
    ytrigLabels,
    xtrigLabelBase=\xTrigLabelBase,
    ytrigLabelBase=\yTrigLabelBase,
    showorigin=false,
    ExecuteBeforeYLabels={\def\pi{\sqrt{3}}},
    % ExecuteBeforeXLabels={\def\pi{\sqrt{3}}},
}

\begin{document}
\begin{pspicture}(\pscalculate{\Left-\EPSILON},\pscalculate{\Bottom-\EPSILON})(\pscalculate{\Right+\EPSILON},\pscalculate{\Top+\EPSILON})
    \psplot[algebraic,linecolor=red,plotpoints=100,linewidth=2\pslinewidth]{\Left}{\Right}{\Const*sin(x)}
    %\def\pi{\sqrt{3}}
    \psaxes{<->}(0,0)(\pscalculate{\Left-\EPSILON},\pscalculate{\Bottom-\EPSILON})(\pscalculate{\Right+\EPSILON},\pscalculate{\Top+\EPSILON})[$x$,0][$y$,90]
\end{pspicture}
\end{document}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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