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

Saturday, February 4, 2012

More options on pstricks plotting (2)

When a Logarithmic scale graph is plot, "x(y)logBase=num|empty", and "logLines=none|x|y|all" are useful. The first one controls the logBse of corresponding axes. The later one controls the log grid line.

Let us plot a logarithmic scale graph to shown how these options are used.

\documentclass{article}
\usepackage{pstricks}
\usepackage{pstricks-add}
\usepackage{pst-plot}
\begin{document}
  \begin{pspicture}(0,0)(6,5)
  \psaxes[axesstyle=frame,ylogBase=10,
    subticks=5,logLines=y](0,0)(6,5)
  \psplot[linecolor=red]{0}{5}{x}
  \psplot[linecolor=blue,linestyle=dotted,
    linewidth=1.5pt,dotsep=1pt]
    {0}{6}{0.5 x mul}
  \psplot[linecolor=green,linestyle=dashed]
    {1}{6}{x log 4 mul}
  \rput(3.5,4.25){\color{red}$y=10^{x}$}
  \rput(3,2.25){\color{green}$y=x^{4}$}
  \rput(3.5,1.25){\color{blue}$y=10^{x/2}$}
  \rput(3,-0.75){$x$}
  \rput(-1,2.5){$y$}
  \end{pspicture}
\end{document}

Fig.1 Plotting Logarithmic scale graph using Pstricks.

Options "nStep, nStart, nEnd, xStep, XStart, xEnd, yStart, yEnd" controls the plot range.

By default the plot macros expect x|y data records, but when data files contains more than one y value, like:
x y1 y2 ... yMax
x y1 y2 ... yMax
...
one can select the column to be plotted using "plotNo" and "PlotNoMax". "plotNo=num" tells pst-plot to plot the num-th y-column. "plotNoMax" tells pst-plot how many y-column are present.

Files: 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.