Showing posts with label \psdot. Show all posts
Showing posts with label \psdot. Show all posts

Saturday, June 9, 2012

Pie Chart --- three useful nodes defined by command "\psChart"

The macro \psChart defines for every value three nodes at the half angle and in distances from chartNodeI (default 0.75), 1 and chartNodeO(default 1.25) times of the radius from the origin (chartNodeI and chartNodeO will be discussed in the next post). The nodes are named as psChartInum, psChartnum and psChartOnum, where num is the number of the pie pieces (num have a value between 1 to the numbers of pie pieces, Letter I stands for Inner and O stands for Outer). These nodes will be very usefull when you add labels to the pie pieces. The following shows these nodes visually.

\documentclass{article}
\usepackage{pstricks}
\usepackage{pstricks-add}
\usepackage{pst-plot}
\begin{document}
  \begin{pspicture}(-5,-5)(5,5)
    \psChart{2,2,3,2}{}{3}
    \psdot[linecolor=red](psChart2)
    \uput[r](psChart2){\textcolor{red}{psChart2}}
    \psdot[linecolor=green](psChartI2)
    \uput[r](psChartI2){\textcolor{green}{psChartI2}}
    \psdot[linecolor=blue](psChartO2)
    \uput[r](psChartO2){\textcolor{blue}{psChartO2}}
    \psdot[linecolor=red](psChart3)
    \uput[r](psChart3){\textcolor{red}{psChart3}}
    \psdot[linecolor=green](psChartI3)
    \uput[r](psChartI3){\textcolor{green}{psChartI3}}
    \psdot[linecolor=blue](psChartO3)
    \uput[r](psChartO3){\textcolor{blue}{psChartO3}}
  \end{pspicture}
\end{document}

Fig.1 Three useful nodes defined by command \psChart.

Files Downloads: tex ps pdf

Now a practical example of plotting a pie chart will be presented.

\documentclass{article}
\usepackage{pstricks}
\usepackage{pstricks-add}
\usepackage{pst-plot}
\begin{document}
  \begin{pspicture}(-5,-5)(5,5)
    \psChart{5,4,4,3,3}{}{3}
    \rput(psChartI1){\textcolor{red}{5}}
    \rput(psChartI2){\textcolor{red}{4}}
    \rput(psChartI3){\textcolor{red}{4}}
    \rput(psChartI4){\textcolor{red}{3}}
    \rput(psChartI5){\textcolor{red}{3}}
    \psset{nodesepA=5pt,nodesepB=-10pt}
    \rput(psChartO1){{US}}
    \rput(psChartO2){{EU}}
    \rput(psChartO3){{China}}
    \rput(psChartO4){{Japan}}
    \rput(psChartO5){{Others}}
  \end{pspicture}
\end{document}

Fig.2 A practical example of pie chart plotting.

In this example, we put the labels using the nodes which have been defined by "\psChart".

Files Downloads: tex ps pdf

Tuesday, November 29, 2011

Some basic graph objects in pstricks (1) ---- Dots

In this and the next few posts some basic graph objects will be introduced. And the first one to be talked is "dots".

Commands "\psdot[parameters](x1,y1)" and "\psdots[parameters](x1,y1)(x2,y2)...(xn,yn)" both draw dots on the canvas. The only difference is that the first one draw only one dot each time, while the second one can draw more than one.

What the dots looks like is depend on the parameters used. The most used parameters are "dotstyle","dotsize","linecolor","fillcolor". Dotstyle determine the style of the dots, for example "*" for a solid circle, "o" for a hollow circle, "x" for a x symbol,"square" for a square and so on. For a complete set of dotstyles you may refer to the official documents. The dotsize determine the size of the dots. The color of the dots is determined by linecolor. If the dots is with a hollow center, the center is colored with fillcolor except for dotstyle "diamond". There are also some other parameters, you can find them in the official document. And at last an example is shown below:

\documentclass{article}
\usepackage{pstricks}
\begin{document}
\begin{pspicture}(5,5)
  \psdot[linecolor=red,dotstyle=*,
    dotsize=24pt](1,4)
  \psdot[linecolor=blue,fillcolor=red,
  dotstyle=o,dotsize=24pt](1,3)
  \psdots[fillcolor=blue,dotstyle=square,
    dotsize=12pt](1,2)(2,2)(3,2)
  \psset{dotsize=24pt,linecolor=yellow}
  \psdots[dotstyle=x](2.5,4)
  \psdot[dotstyle=+](2.5,3)
\end{pspicture}
\end{document}   

The picture these code draw looks like this:
Fig.1 Draw dots using Pstricks

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