3

Is there a way to make the grid in \psgrid look the same as the one in the tikzpicture?

\documentclass[12pt,pstricks]{exam}
\usepackage{tikz}
\usepackage{pst-all}
\begin{document}
 \psset{unit=0.5cm}
 \begin{pspicture}(12,14)
  \psgrid[gridcolor=red,subgridcolor=green,gridlabels=0](0,0)(10,12)
  \psaxes[Dx=2,Dy=4,showorigin=false]{->}(0,0)(0,0)(11,13)
  \psplot{0.5}{9.5}{36 x mul sin 5 mul 6 add}
 \end{pspicture}\\\vspace{1cm}

 \begin{tikzpicture}[scale=0.5]
    \draw [ultra thick,<->] (0,13) -- (0,0) -- (11,0);
    \foreach \y in {2,4,...,12}{\draw [color=red] (0,\y) -- (10,\y);}
    \foreach \x in {2,4,...,10}{\draw [color=red] (\x,12) -- (\x,0) node [below,color=black] {\x};}
    \foreach \y in {1,3,...,11}{\draw [color=green] (0,\y) -- (10,\y);}
    \foreach \y in {4,8,12}{\draw (0,\y) node [left] {\y};}
    \foreach \x in {0.5,1,1.5,2.5,3,3.5,4.5,5,5.5,6.5,7,7.5,8.5,9,9.5}{\draw [color=green] (\x,0) -- (\x,12);}
    \draw [domain=0.5:9.5,samples=100,thick,<->] plot (\x,{5*sin(36*\x)+6});
 \end{tikzpicture}
\end{document}
3

Can also be done by \psaxes instead of \psgrid. It needs two calls of \psaxes in fact of the two different label distance.

\documentclass[12pt]{exam}
\usepackage{pst-all}
\begin{document}

    \psset{unit=0.5cm}
    \begin{pspicture}(-1,-1)(12,14)
    \psaxes[Dx=2,Dy=4,showorigin=false,ticksize=0,]{->}(0,0)(11,13)% without ticks
    \psaxes[Dy=2,Dx=2,showorigin=false,labels=none,%  with ticks
      yticksize=0 10,xticksize=0 12,tickcolor=red,
      subticksize=1,ysubticks=2,xsubticks=4,subtickcolor=green,](0,0)(10,12)
    \psplot[algebraic,arrows=<->]{0.5}{9.5}{5*sin(Pi/5*x)+6}
    \end{pspicture}

\end{document}

enter image description here

  • Thank you. I particularly like the easy function naming and the fact that you included the arrows. – Garth Fleming Jun 30 '15 at 13:42
  • As I play with this code further it really does do what I want and offers more flexibility because it is easier to understand therefore manipulate to do other grids. – Garth Fleming Jun 30 '15 at 14:25
5

This is the Tikz plot:

enter image description here

Here is a PStricks version:

enter image description here

\documentclass{article}
\usepackage{pst-plot}

\begin{document}

\psset{unit=0.5cm}
\begin{pspicture}(12,14)
  \psgrid[gridcolor=red,subgridcolor=green,gridlabels=0,subgriddiv=4,gridwidth=.4pt,unit=2](0,0)(5,6)
  \psaxes[Dx=2,Dy=4,showorigin=false]{->}(0,0)(0,0)(11,13)
  \psplot{0.5}{9.5}{36 x mul sin 5 mul 6 add}
\end{pspicture}

\end{document}

Note the use of subgriddiv=4, gridwidth=.4pt (default is .8pt) and unit=2. The last key-value stretches the grid out (twice as far), so we only need to go to coordinate (5,6) instead of (10,12).

  • The grid is drawn at the PostScript level and assumes an equal layout in both x and y directions. If you insist on having a different subgriddiv for x and y, then one would have to rewrite the/add to/ create a new Grid function in pstricks.pro. Alternatively, draw the grid manually... – Werner Jun 30 '15 at 6:57

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.