MATLAB Community

MATLAB, community & more

Soccer Passing Networks

Posted by Ned Gulley,

I saw another fun MATLAB-related tweet go by, this time about soccer rather than doughnuts. The Euro 2016 tournament is going on right now, and José Pedro Silva tweeted a cool MATLAB-generated visualization about passing between the players. This is showing the passing in the Portugal-Iceland match.

passing_network_1

https://twitter.com/ZPedro10/status/743115988581896192

The game resulted in a 1-1 draw, but just looking at the passing! The line weights show how many more touches Portugal had than Iceland. And indeed, Iceland only managed 28% of possession.

Digraphs in MATLAB

I don’t have access to the fancy code that generated that plot, but I can use this opportunity to show off MATLAB’s graphing capability. Let’s make up some totally random names and passing statistics for a five-man soccer team.

names = { ...
            'Lionel Alpha', 
            'Cristiano Bravo',
            'Gareth Charlie',
            'Zlatan Delta',
            'Sergio Echo'};

Now we can show the edges of the graph: who passed the ball (source), who received it (target) and how many passes they made (numPasses). The number of passes will be assigned to the weight of each edge. So we can see that Alpha passed to Bravo exactly once during the match. Bravo never returned the favor.

        source    = [1 1 1 2 3 3 3 3 4 4 4 5 5 5 5];
        target    = [2 4 5 4 1 2 4 5 2 3 5 1 2 3 4];
        numPasses = [1 2 1 1 5 2 2 3 2 2 1 4 6 4 8];
        weight = numPasses;
        G = digraph(source,target,weight,names);
        G.Nodes
ans = 
          Name       
    _________________

    'Lionel Alpha'   
    'Cristiano Bravo'
    'Gareth Charlie' 
    'Zlatan Delta'   
    'Sergio Echo'    


        G.Edges
ans = 
                   EndNodes                   Weight
    ______________________________________    ______

    'Lionel Alpha'       'Cristiano Bravo'    1     
    'Lionel Alpha'       'Zlatan Delta'       2     
    'Lionel Alpha'       'Sergio Echo'        1     
    'Cristiano Bravo'    'Zlatan Delta'       1     
    'Gareth Charlie'     'Lionel Alpha'       5     
    'Gareth Charlie'     'Cristiano Bravo'    2     
    'Gareth Charlie'     'Zlatan Delta'       2     
    'Gareth Charlie'     'Sergio Echo'        3     
    'Zlatan Delta'       'Cristiano Bravo'    2     
    'Zlatan Delta'       'Gareth Charlie'     2     
    'Zlatan Delta'       'Sergio Echo'        1     
    'Sergio Echo'        'Lionel Alpha'       4     
    'Sergio Echo'        'Cristiano Bravo'    6     
    'Sergio Echo'        'Gareth Charlie'     4     
    'Sergio Echo'        'Zlatan Delta'       8     


Look how easy it is to make a simple directed graph. Sergio Echo is clearly a passing machine. For Bravo, it was far better to receive than to give.

        plot(G,'Layout','circle','LineWidth',G.Edges.Weight,'ArrowSize',15)
        axis off

passing_network_2

5 views (last 30 days)  | |

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.