[pstricks] Radar
Jean-Côme Charpentier
jean-come.charpentier at wanadoo.fr
Sat Mar 3 22:37:18 CET 2007
*** From ctt ***
Herbert Voss a écrit :
> Jean-Côme Charpentier schrieb:
>> Jim a écrit :
>>> On Mar 2, 10:21 am, sic... at sicher.at wrote:
>>>> hello,
>>>>
>>>> i'm looking for a source/package to draw a spider/radar chart
-http://en.wikipedia.org/wiki/Radar_chart
>>> Have you had a look at PS Tricks?
>>> http://tug.org/PSTricks
>> There is also other toolsfor that, though I prefer PSTricks.
>>
>>> A lot of people like it for things like this.
>> Indeed! In fact, this problem was very funy. I tried something:
[code below]
> very nice ... :-)
> please do a cc to pstricks at tug.org for such examples.
>
> Herbert
*************
\documentclass{article}
\usepackage[a4paper,top=1.4cm,left=1cm,noheadfoot]{geometry}
\usepackage{pstricks}
\usepackage{multido}
\makeatletter
\newcounter{nbtarget}
% Empty the target
\newcommand*\radarreset{%
\setcounter{nbtarget}{0}%
}
% Set one target.
\def\radarsetpoint(#1){%
\@namedef{point@\the\c at nbtarget}{#1}%
\stepcounter{nbtarget}%
\ignorespaces
}
% Color serie for echo area (green to black)
\definecolorseries{echo}{rgb}{last}{green}{black}
\SpecialCoor
\def\radar(#1)#2#3#4{%
% #1 center coordinates
% #2 radar radius
% #3 start angle for green area
% #4 total angle of area
% we use \psset => \begingroup...\endgroup
\begingroup
% All the picture is translated at (#1)
\rput(#1){%
% radar background (black circle)
\pscircle*[linecolor=black](0,0){#2}
% We use #4 colors from green to black
\resetcolorseries[#4]{echo}%
% Each color for a wedge of 1 degree.
\multido{\i=#3+1}{#4}{%
\rput{\i}(0,0){%
\pswedge[fillstyle=solid,fillcolor=echo!!+,linestyle=none]
(0,0){#2}{0}{1}
}
}%
% Edge of echo area is white (more beautiful!)
\psline[linecolor=white,linewidth=2pt](0,0)(#2;#3)
% We display only the taget inside the echo area
\begin{psclip}{\pswedge[linestyle=none](0,0){#2}{#3}{!#3 #4 add}}
\multido{\i=0+1}{\the\c at nbtarget}{%
\psdots[linecolor=white,dotstyle=*,dotsize=3pt]
(\csname point@\i\endcsname)
}
\end{psclip}
% Radar rules
\psset{linecolor=blue,linewidth=1pt}
\psline(-#2,0)(#2,0)
\psline(0,-#2)(0,#2)
% graduations 1/10
\multido{\r=-0.9+0.1}{19}{%
\psline(!#2 \r\space mul 0.1 neg)(!#2 \r\space mul 0.1)
\psline(!0.1 neg #2 \r\space mul)(!0.1 #2 \r\space mul)
}
% it's all folk
}
\endgroup
% No space after PSTricks object
\ignorespaces
}
\makeatother
\pagestyle{empty}
\begin{document}
\radarsetpoint(-1,-3.2)
\radarsetpoint(-2,-1)
\radarsetpoint(-3,0.5)
\radarsetpoint(-1.5,1.8)
\radarsetpoint(-0.5,1)
\radarsetpoint(0.3,0.7)
\radarsetpoint(3,0.2)
\radarsetpoint(2,-1.5)
\begin{pspicture}(-4,-4)(14,22)
\radar(0,18){4}{0}{150}
\radar(10,18){4}{-30}{150}
\radar(0,9){4}{-60}{150}
\radar(10,9){4}{-90}{150}
\radar(0,0){4}{-120}{150}
\radar(10,0){4}{-150}{150}
\end{pspicture}
\newpage
\begin{pspicture}(-4,-4)(14,22)
\radar(0,18){4}{-180}{150}
\radar(10,18){4}{-210}{150}
\radar(0,9){4}{-240}{150}
\radar(10,9){4}{-270}{150}
\radar(0,0){4}{-300}{150}
\radar(10,0){4}{-330}{150}
\end{pspicture}
\radarreset % For a new set :-)
% ...
\end{document}
Jean-Côme Charpentier
More information about the PSTricks
mailing list