Précédent   Forum du club des développeurs et IT Pro > Environnements de développement > MATLAB > Téléchargez
Téléchargez Récupérez et commentez les sources et outils mis à disposition par la rubrique MATLAB
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 01/03/2008, 18h31   #1
Dut
Responsable MATLAB & Hardware/PC

 
Avatar de Dut
 
Inscription : novembre 2006
Messages : 15 106
Détails du profil
Informations personnelles :
Localisation : France

Informations forums :
Inscription : novembre 2006
Messages : 15 106
Points : 31 184
Points : 31 184
Par défaut Graphique de type Radar (toile d'araignée)

Le code suivant permet d'obtenir une représentation données de type radar :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function radar(P,col,str,ax)
% RADAR Radar plot
%   RADAR(P,COL,STR) draws a radar plot of the data in the matrix P.
%   COL is an Mx3 colormap where M = size(P,2) and STR is a 1xN cell
%   array of string where N = size(P,1).
%
%   RADAR(P,COL,STR,AX) draws the radar plot in the axes object AX.
%
%   Exemple :
%
%       P = [30 18 23 52 69 ; 20 45 38 85 34].';
%       color = [1 0 0 ; 0 0 1];
%       str = {'Perf' 'Rapidité' 'Communauté' 'Simplicité' 'Portabilité'};  
%       radar(P,color,str)
%
%   See also POLAR, ROSE, COMPASS

%   Author: Jérôme Briot
%           http://www.developpez.net/forums/member.php?u=125006
%           http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1094934&objectType=author
%   Contact: dutmatlab#yahoo#fr
%   Version: 1.0 - 11 Feb 2008
%   Comments:
%

error(nargchk(3,4,nargin));

if nargin == 3 % RADAR(P,COL,STR)
    figure
elseif nargin == 4 & ~ishandle(ax) % RADAR(P,COL,STR,AX) and AX is not a valid handle
    error('Last argument in RADAR(P,COLOR,STR,AX) must be a handle of a valid axes object');
elseif nargin == 4 & ishandle(ax) % RADAR(P,COL,STR,AX) and AX is a valid handle
    axes(ax) 
end

[nPVal,nP] = size(P);

th = linspace(0,2*pi,nPVal+1).';
r = linspace(0,100,6);
x = sin(th);
y = cos(th);

% Set backgound color to white
fill(x*r(end),y*r(end),'w');
hold on
% Draw concentric lines
line(x*r(2:end),y*r(2:end), ...
    'color','k', ...
    'linestyle',':');

% Plot data
for n=1:nP
    patch('xdata',x(1:end-1).*P(:,n),...
        'ydata',y(1:end-1).*P(:,n), ...
        'facecolor','none',...
        'edgecolor',col(n,:));
    
    text(1.05*x(1:end-1).*P(:,n),1.05*y(1:end-1).*P(:,n),strcat(num2str(P(:,n),'%d'),' %'), ...
        'color',col(n,:));
end

% Add labels add
text(1.1*x(1:end-1)*r(end),1.1*y(1:end-1)*r(end),str, ...
    'hor','center', ...
    'vert','middle');
% Plot radial lines from the center of the graphic
line([zeros(1,numel(x)-1);r(end)*x(1:end-1).'],[zeros(1,numel(y)-1);r(end)*y(1:end-1).'], ...
    'color','k');

axis equal off
Exemple :

Code :
1
2
3
4
P = [30 18 23 52 69 ; 20 45 38 85 34].';
color = [1 0 0 ; 0 0 1];
str = {'Perf' 'Rapidité' 'Communauté' 'Simplicité' 'Portabilité'};  
radar(P,color,str)
Résultat :
Images attachées
Type de fichier : gif radar.gif (5,5 Ko, 105 affichages)
__________________
Identification de processeur sous MATLAB (3/3) Identification de processeur sous MATLAB (2/3) Mes contributions MATLAB (R2009a - Windows & Linux)

J'étais le meilleur ami que le vieux Jim avait au monde. Il fallait choisir. J'ai réfléchi un moment, puis je me suis dit : "Tant pis ! J'irai en enfer" (Saint Huck)
Dut est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/03/2008, 18h28   #2
mr_samurai
Membre Expert
 
Avatar de mr_samurai
 
Inscription : décembre 2007
Messages : 958
Détails du profil
Informations personnelles :
Âge : 29
Localisation : France

Informations forums :
Inscription : décembre 2007
Messages : 958
Points : 1 030
Points : 1 030
très joli,

marche super chez moi .
__________________
Matlab 2008b / Vista
| FileExchange | Matlab: FAQ, Tutoriels |
geny course, pronostic pmu
mr_samurai est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 31/01/2011, 19h26   #3
agilles
Invité de passage
 
Inscription : janvier 2011
Messages : 2
Détails du profil
Informations forums :
Inscription : janvier 2011
Messages : 2
Points : 0
Points : 0
Par défaut changer les échelles

Bonjour,

Serait-il possible de modifier le code du diagramme radar pour avoir la liberté d'échelle sur les différents axes?
Je recherche un outil qui me permettrait de faire un diagramme radar avec des échelles différentes sur les axes du type :
http://www.minefi.gouv.fr/directions...france0612.jpg

Merci
agilles est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/02/2011, 22h52   #4
Dut
Responsable MATLAB & Hardware/PC

 
Avatar de Dut
 
Inscription : novembre 2006
Messages : 15 106
Détails du profil
Informations personnelles :
Localisation : France

Informations forums :
Inscription : novembre 2006
Messages : 15 106
Points : 31 184
Points : 31 184
Voici une version améliorée :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
function [h_patch,h_line,h_text] = radar(P,L,col,str,bg,ax)
% RADAR Radar plot
%   RADAR(P,L,COL,STR,BG) draws a radar plot of the data in the MxN matrix
%   P where N is the number of curves to draw and M is the number of points
%   per curves. Values in P are expressed in percent so the graphic radius
%   is 100.
%
%   L is a Mx2 matrix that control the scaling along each radial direction.
%   First column of L specifies the value at the center of the graphic. 
%   Second column specifies the value at the end of the radius. If the 
%   second value is greater than the first, values decrease when radius 
%   increases. No scaling is performed when first columns contain 0s and 
%   second row contains 100s.
%
%   COL is an Nx3 colormap that specifies one RGB color per curve.
%
%   STR is a 1xM cell array of string labelling each radial direction.
%
%   BG is a string that specifie the shape of the background as :
%       'tight'  : polygonal shape
%       'circle' : circular shape
%
%   RADAR(P,L,COL,STR,BG,AX) draws the radar plot in the axes object AX.
%
%   See also POLAR, ROSE, COMPASS

%   Author: Jerome Briot
%   http://www.developpez.net/forums/member.php?u=125006
%   http://www.mathworks.com/matlabcentral/fileexchange/authors/21984
%   Contact: dutmatlab#at#yahoo#dot#fr
%   Version: 1.0 - 11 Feb 2008
%            2.0 - 02 Feb 2011 Add scaling and  background shape feature
%                              Function returns graphical object handles
%   Note : post your comments (in french only) here :
%          www.developpez.net/forums/d501214/environnements-developpement/matlab/contribuez/graphique-type-radar-toile-daraignee/
%
%   Comments:
%

error(nargchk(5,6,nargin));

if nargin == 5 % RADAR(P,L,COL,STR,BG)
    get(gca);
elseif nargin == 6 && ~ishandle(ax) % RADAR(P,L,COL,STR,BG,AX) but AX is not a valid handle
    error('Last argument in RADAR(P,L,COLOR,STR,BG,AX) must be a handle of a valid axes object');
elseif nargin == 6 && ishandle(ax) % RADAR(P,L,COL,STR,BG,AX) and AX is a valid handle
    axes(ax)
end

[nPVal,nP] = size(P);
r = 100;

if strcmpi(bg,'tight')
    
    th = linspace(0,2*pi,nPVal+1);
    x = sin(th(:));
    y = cos(th(:));
    h_patch(1) = fill(x*r,y*r,'w');
    
elseif strcmpi(bg,'circle')
    th = linspace(0,2*pi,200);
    x = sin(th);
    y = cos(th);
    h_patch(1) = fill(x*r,y*r,'w');
    
    th = linspace(0,2*pi,nPVal+1);
    x = sin(th(:));
    y = cos(th(:));
else
    error('5th argument must be "tight" or "circle"');
end

hold on

dL = diff(L,1,2);
sL = sort(L,2);

for n=1:nP
    
    f = (P(:,n)-sL(:,1))./abs(dL);
    idx = dL<0;
    f(idx) = 1-f(idx);
    
    h_patch(n+1) = patch('xdata',x(1:end-1).*f*100,...
        'ydata',y(1:end-1).*f*100, ...
        'facecolor','none',...
        'edgecolor',col(n,:),...
        'linewidth',2);
    
    h_text{n} = text(1.05*x(1:end-1).*f*100, ...
        1.05*y(1:end-1).*f*100, ...
        strcat(num2str(P(:,n),'%g'),' %'), ...
        'color',col(n,:));
    
end

h_text{n+1} = text(1.1*x(1:end-1)*r, 1.1*y(1:end-1)*r, ...
    str, 'hor','center', 'vert','middle');

h_line = line([zeros(1,numel(x)-1);r*x(1:end-1).'], ...
    [zeros(1,numel(y)-1);r*y(1:end-1).'], ...
    'color','k');

axis equal off
C'est un peu plus complexe à utiliser...

La matrice L sert à appliquer les échelles sur les différentes directions radiales. La première colonne de L donne pour chaque direction la valeur au centre du graphique et la seconde colonne donne la valeur à la périphérie du graphique. Si la première valeur est inférieure à la seconde, les valeurs décroissent quand le rayon augmente.

La fonction renvoie les identifiants des objets graphiques pour pouvoir améliorer le rendu du tracé :
Code :
[h_patch,h_line,h_text] = radar(P,L,col,str,bg,ax)
  • h_patch(1) : fond du graphique
  • h_patch(2:end) : les courbes
  • h_line : les directions radiales
  • h_text{1:end-1} : les labels (en %)
  • h_text{end} : les étiquettes en périphérie du graphique

Les positions des textes à l'intérieur du graphique ne sont pas optimales, je dois bien l'avouer

Deux demo :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function demo_radar

% DEMO 1
P = [30 18 23 52 69 ; 20 45 38 85 34].';
L = [0 0 0 0 0 ; 100 100 100 100 100].';
color = [1 0 0 ; 0 0 1];
str = {'Perf' 'Rapidité' 'Communauté' 'Simplicité' 'Portabilité'};
bg = 'tight';

figure('numbertitle','off','name','Radar Demo 1')
ax = axes;
radar(P,L,color,str,bg,ax);

% DEMO 2
P = [2.3 8.8 2.7 5.9 0.1 2.7 2.9 ; 1.2 9.8 1.8 4.7 7.5 1.4 3.7].';
L = [-1.5 12 0 0 -4 -1.5 5 ; 3 4  3 10 12 3 0].';
color = [0 0.7059 0.9451 ; 0 0 1];
str = {'CR' 'EM' 'CO' 'IN' 'EX' 'PA' 'FP'};
bg = 'circle';

figure('color','w','numbertitle','off','name','Radar Demo 2')

[p,h,t] = radar(P,L,color,str,bg);

set(p(1),'edgecolor','none','facecolor',[1 0.9686 0.9216])
set(p(2:3),'linewidth',3)
set([t{1:2}],'fontsize',8)
legend(p(2:3),{'2006' '2005'})
(voir ci-dessous les deux graphiques obtenus)

Voilou... n'hésitez pas à donner vos remarques à propos de ce nouveau code
Images attachées
Type de fichier : gif demoradar1.gif (5,0 Ko, 23 affichages)
Type de fichier : gif demoradar2.gif (6,0 Ko, 30 affichages)
__________________
Identification de processeur sous MATLAB (3/3) Identification de processeur sous MATLAB (2/3) Mes contributions MATLAB (R2009a - Windows & Linux)

J'étais le meilleur ami que le vieux Jim avait au monde. Il fallait choisir. J'ai réfléchi un moment, puis je me suis dit : "Tant pis ! J'irai en enfer" (Saint Huck)
Dut est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 10h12.


 
 
 
 
Partenaires

Hébergement Web