Showing posts with label psgraph. Show all posts
Showing posts with label psgraph. Show all posts

Tuesday, March 27, 2012

Plot in polar coordinate --- polarplot

With the option "polarplot=true", it is possible to use command "\psplot" to create a polar plot. The syntax is the same as usual --- "\psplot[polarplot=true,...]{x0}{x1}{function}" where "x0" and "x1" are the start and end angle. "function" is interpreted as a function r=f(theta) in the polar plotting. So if a circle with radius 1 is to be plotted, command "\psplot[polarplot=true]{0}{360}{1}" can be used.
Now we come to draw a cardioid. The function of a cardioid in polar coordinate reads "r=a(1+sin(x))". And we take a=1.5.

\documentclass{article}
\usepackage{pstricks}
\usepackage{pstricks-add}
\usepackage{pst-plot}
\begin{document}
  \psset{plotpoints=500}
  \begin{psgraph}{->}(0,0)(-0.5,-2)(3.5,2.5){5cm}{5cm}
    \psplot[polarplot=true]{0}{360}
      {x cos 1 add 1.5 mul}
  \end{psgraph}
\end{document}

Fig.1 Plot in polar coordinate --- cardioid.

The axesstyle can also be set to polar. The only thing need to do is setting "axesstyle=polar". This time we use a three-leaved rose curve (r=a*sin(3x),a=3.5) to shown it.

\documentclass{article}
\usepackage{pstricks}
\usepackage{pstricks-add}
\usepackage{pst-plot}
\begin{document}
\psset{plotpoints=500}
\begin{pspicture}(-4,-4)(4,4)
  \psaxes[axesstyle=polar,xAxisLabel=some,
    subticks=2,tickcolor=red,tickwidth=1pt,
    subtickcolor=green]{->}(0,0)(-4,4)(4,4)
  \psplot[polarplot=true,linewidth=2pt,
    linecolor=blue]{0}{360}
    {3 x mul sin 3.5 mul}
\end{pspicture}
\end{document}

Fig.2 Plot in polar coordinate — three leaved rose curve.
 
Files Download: tex ps pdf 

Sunday, February 26, 2012

Pstricks defined plotting suitable environment --- psgraph

Except allocating spaces for the pstricks elements just as what pspicture does, this new environment also does the scaling and draws the axes. It means that the axes drawing and transformation from physical coordinate to mathematical coordinate will be done automatically. The syntax is:

\begin{psgraph}[options]{arrowstyle}%
  (xorigin,yorigin)(xmin,ymin)(xmax,ymax){width}{height}
...
\end{psgraph}

where the options are similar to those of "\psaxes" macro. "arrowstyle" controls the arrwostyle of axes. "(xorigin,yorigin)", "(xmin,ymin)" and "(xmax,ymax)" define the coordinate system. "width" and "height" determine the physical width and height of the graph. Now we show the advantage of this new environment by the following example.

\documentclass{article}
\usepackage{pstricks}
\usepackage{pstricks-add}
\usepackage{pst-plot}
\begin{document}
  \psset{
    axesstyle=frame,ysubticks=2,
    xsubticks=4,subticksize=0.5,
    subtickcolor=black,xAxisLabel=Time(s),
    xAxisLabelPos={c,-1cm},
    yAxisLabel=Voltage(mV),
    yAxisLabelPos={-1cm,c}
    }
  \begin{psgraph}[Dx=2,Dy=10,Ox=-2,Oy=-10]
    {->}(-2,-10)(6,75){8cm}{5cm}
    \psplot[linecolor=red]{-2}{6}{2 x exp}
    \psplot[plotpoints=500,linecolor=blue]
      {-2}{6}{2 x exp 500 x mul sin add}
    \rput(-1.5,65){\psline[linecolor=red]
      (0,0)(0.75cm,0)}
    \rput[l](-0.5,65){Original Theory}
    \rput(-1.5,55){\psline[linecolor=blue]
      (0,0)(0.75cm,0)}
    \rput[l](-0.5,55){Improved Theory}
  \end{psgraph}
\end{document} 

Fig.1 Pstricks defined plotting suitable environment --- psgraph

Isn't it more convinient than pspicture?

Downloads: tex ps pdf

Creative Commons License
Except as otherwise noted, the content of this page is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.