3

I want to create a coordinate place with \psgrid and \psaxes. I am using the labels of \psaxes and suppressing those of \psgrid. My issue is that the negative signs (for negative labels) tend to be obscured by the lines of \psgrid. Here is my starting code:

\documentclass{article}
\usepackage{pstricks-add}

\begin{document}
\begin{center}
  \psset{xunit=1cm,yunit=1cm}
  \begin{pspicture}(-7.5,-5.5)(7.5,5.5)
    \psgrid[gridwidth=0.2pt, gridlabels=0pt, subgriddiv=2](-7,-5)(7,5)
    \psaxes[labelFontSize=\scriptstyle, ticks=none,
    linewidth=0.8pt]{->}(0,0)(-7.5,-5.5)(7.5,5.5) [$x$,-120]
    [$y$,-40]
  \end{pspicture}
\end{center}

What I would like to do is have the labels displayed in their boxes with solid white (or any other color) background in order to make the labels more readable. (I want to achieve something similar to what \ncput* does for node connectors.)

Thanks

EDIT: After looking at @Bernard's solution and his use of \psframebox*, I fiddled some more with \psvlabel and came up with a solution that doesn't require me to enter individual labels.

\documentclass{article}
\usepackage{pstricks-add}

\begin{document}
\begin{center}
  \psset{xunit=1cm,yunit=1cm}
  \renewcommand{\psvlabel}[1]{\psframebox*{\scriptsize $#1$}}
  \renewcommand{\pshlabel}[1]{\psframebox*[framesep=2pt]{$#1$}}
  \begin{pspicture}(-7.5,-5.5)(7.5,5.5)
    \psgrid[gridwidth=0.2pt, gridlabels=0pt, subgriddiv=2](-7,-5)(7,5)
    \psaxes[labelFontSize=\scriptstyle, ticks=none,
    linewidth=0.8pt]{->}(0,0)(-7.5,-5.5)(7.5,5.5) [$x$,-120]
    [$y$,-40]
  \end{pspicture}
\end{center}

But that raised an unexpected (buggy?) behavior of the \pshlabel and \psvlabel commands. You will notice there is no \scriptsize in the second label command, because when I put it in, the corresponding labels get scaled down even more (i.e. script size relative to script size). result

1

Use the ylabelOffset key:

\documentclass{article}
\usepackage{pstricks-add}
\usepackage{auto-pst-pdf}

\begin{document}

\begin{center}
  \psset{xunit=1cm,yunit=1cm}
 \begin{pspicture}(-7.5,-5.5)(7.5,5.5)
    \psgrid[gridwidth=0.2pt, gridlabels=0pt, subgriddiv=2](-7,-5)(7,5)
    \psaxes[labelFontSize=\scriptstyle, ticks=none, ylabelOffset=0.08, linewidth=0.8pt]{->}(0,0)(-7.5,-5.5)(7.5,5.5) [$x$,-120]
    [$y$,-40]
  \end{pspicture}
\end{center}

\end{document} 

enter image description here

Another solution, with \psframebox*:

\documentclass[x11names]{article}
\usepackage{pstricks-add}
\usepackage{auto-pst-pdf}
\newcommand\mylabel[1]{\psframebox*[framesep=1pt]{\scriptstyle#1}}

\begin{document}

\begin{center}
  \psset{xunit=1cm,yunit=1cm}
  \begin{pspicture}(-7.5,-5.5)(7.5,5.5)
    \psgrid[gridwidth=0.4pt, subgridwidth=0.2pt, gridlabels=0pt, subgriddiv=2, gridcolor=SteelBlue4, subgridcolor =LightSteelBlue3](-7,-5)(7,5)
    \psaxes[labelFontSize=\scriptstyle, ticks=none, labels=x]{->}(0,0)(-7.5,-5.5)(7.5,5.5) [$x$,-120]
    [$y$,-40]
    \psset{ticks=none, linewidth=0pt, linestyle=none}
    \psaxes[yLabels = {,\mylabel{1},\mylabel{2},\mylabel{3},\mylabel{4},\mylabel{5}}]{-}(0,5.5)
    \psaxes[yLabels={\mylabel{-5},\mylabel{-4}, \mylabel{-3}, \mylabel{-2}, \mylabel{-1}}]{-}(0,-5)(0,-5.5) (0,0)
  \end{pspicture}
\end{center}

\end{document} 

enter image description here

  • This is a nice way around the minus signs being obfuscated. However, I would like a solution that creates a little white box around the labels, in order to use that approach when the graph is smaller and the grid lines closer together. – Minh Nov 10 '15 at 20:10
  • @Minh: I've added another solution. Is that more like you want? – Bernard Nov 10 '15 at 21:22
1
\documentclass{article}
\usepackage{pstricks-add}

\begin{document}

\psset{psgrid,gridcoor={(-7,-5)(7,5)},
    gridpara={gridlabels=0pt,gridcolor=red!30,
              subgridcolor=green!30,
              subgridwidth=0.5\pslinewidth,
              subgriddiv=2,labelFontSize=\scriptstyle}%
}
\begin{psgraph}{->}(0,0)(-7.5,-5.5)(7.5,5.5){\linewidth}{0.7\linewidth}
  \uput[0](7.5,0){$x$}\uput[90](0,5.5){$y$}
\end{psgraph}

\end{document}

enter image description here

  • While this solution doesn't exactly answer my question, it's still a nice bit of code and I especially appreciate an example of how to use psgraph. It's a way to solve my problem if the graph is to be displayed on the screen or printed in color. Unfortunately I'm looking to print black and white. I've fiddled with '\psvlabel' and '\pshlabel', but my system (MacTeX full and updated) returns an error. – Minh Nov 10 '15 at 20:05

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.