<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shivank Batra on Medium]]></title>
        <description><![CDATA[Stories by Shivank Batra on Medium]]></description>
        <link>https://medium.com/@shivank56batra?source=rss-3e2d44d96db3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*YEuHC1PkCCG81_lL</url>
            <title>Stories by Shivank Batra on Medium</title>
            <link>https://medium.com/@shivank56batra?source=rss-3e2d44d96db3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 08:05:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shivank56batra/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Arsenal Vs Tottenham Pre-Match Analysis]]></title>
            <link>https://medium.com/@shivank56batra/arsenal-vs-tottenham-pre-match-analysis-4ae1bd2926db?source=rss-3e2d44d96db3------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ae1bd2926db</guid>
            <category><![CDATA[football]]></category>
            <category><![CDATA[tactics]]></category>
            <category><![CDATA[premier-league]]></category>
            <category><![CDATA[arsenal]]></category>
            <dc:creator><![CDATA[Shivank Batra]]></dc:creator>
            <pubDate>Thu, 28 Sep 2023 18:13:59 GMT</pubDate>
            <atom:updated>2023-09-28T18:16:36.616Z</atom:updated>
            <content:encoded><![CDATA[<p>A tactical overview of both sides from north London before the big derby day and how the match may pan out potentially from a tactical viewpoint. I have already done an extensive data analysis of both sides here:</p><p><a href="https://colab.research.google.com/drive/1aqh2Jj3ckIiWXCyPhsfaiqlUjDP_2HLc?usp=sharing">https://colab.research.google.com/drive/1aqh2Jj3ckIiWXCyPhsfaiqlUjDP_2HLc?usp=sharing</a></p><p>I was able to detect patterns and some really interesting trends from the data and I am going to use that as a reference point for my analysis in this piece as well.</p><p>The structure of this blogpost would be like this:</p><ol><li>Arsenal In and Out Of Possession Structure</li><li>Tottenham In and Out Of Possession Structure</li><li>Key Tactical Battles When Both Will Face Each Other</li></ol><h3>Arsenal In Possession Structure</h3><p>Arsenal start out in a classic 4–3–3 shape on paper but transition into a 2–3–5 (when Zinchenko inverts as a full-back) or into a 2–4–2 shape (where Havertz drops in the double pivot alongside Rice). In both these possession systems we see a common theme of Odegaard pushing really high and almost acting like a second striker while Saka and Martinelli hold the width of the pitch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*EmC4qhPEBozkNbT8oYtu8A.jpeg" /><figcaption>Arsenal typical 2–3–5 structure in possession</figcaption></figure><p>The typical Arsenal strategy is to overload the wide areas and then attack the half-spaces and then use cutbacks/low crosses to attack the penalty box.</p><p>The typical patterns which we saw in our data report can be traced in the video as well: Zinchenko as the primary progressor from the first phase, Odegaard making run in the right half-space and a lot of left sided bias while overloading + attacking in the final third area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i0xj7zhpGnoVI0rc-GW6yA.jpeg" /><figcaption>Havertz drops to create a 2v1 against Bruno and receives a direct vertical pass from Ramsdale</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w0YUOOiXn8hk_HWkgO8hIA.jpeg" /><figcaption>Zinchenko and Rice as the double pivot attract United’s first line of press. Zinchenko inverted attracting Antony inside also means there is a potential switch to the wide left space.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vaBIqtg9qAjcjMiCZpCoSQ.jpeg" /><figcaption>left side overload taking advantage of Antony(RW) sub-optimal high and narrow position to create a 2v1 against Wan-Bissaka(RB). This also lead to the goal later on with Martinelli putting a low cross for Odegaard to score.</figcaption></figure><h3>Arsenal Out Of Possession Structure</h3><p>Without the ball Arsenal 4–3–3 structure morphs to a 4–4–2 or a 4–3–1–2 with Odegaard and Havertz pushing upfield to support the press.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*6IXesdPEbgAYE46MBzK3Tg.jpeg" /><figcaption>typical 4–4–2 high press from Arsenal</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*gNKWcgfpw17h563Ujy_eWQ.jpeg" /><figcaption>A narrow 4–3–1–2 structure with wingers tucked inside while Havertz pushes high</figcaption></figure><p>Arsenal strategy is to aggressively press high man to man and then force the ball out-wide and trap the opposition in the limited space. Here is a very nice sequence against United buildup play:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mBEynSmB8ZhYLjlMYw2o7A.jpeg" /><figcaption>narrow man to man press pushing the ball out-wide and backwards</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4JVfECiKsluHZXPHIjIwLw.jpeg" /><figcaption>few seconds later from the same sequence and Arsenal are able to successfully trap United out-wide</figcaption></figure><p>Arsenal were solid off the ball while high pressing and otherwise as well for most part of the game but there were still some instances where United were able to overload and progress the ball. And as you will see in the next section as well, Spurs have a slightly unusual buildup play and are masters of overloading in the initial phase, it will be great to see who comes out on top during this phase of play. This is something which we will hypothesise and try to simulate in the last section of this blog.</p><h3>Tottenham In Possession Structure</h3><p>Spurs have seen a stark difference in almost all the areas this season: new coach, new system, new players, department of Harry Kane etc. but they have adjusted very well and have a very interesting philosophy in possession. Also, their average possession numbers have gone high compared to last season.</p><p>Spurs also have a somewhat similar structure to Arsenal and like most of the ‘big’ sides in possession. Their initial 4–2–3–1 transitions to a 2–3–5 with both the full-backs inverted. But there is a lot of fluidity within the system + combined with personnel that are best suited in their positions which has so far led to some really smooth and strong possession play.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/363/1*ITmJ8sh066uVTlVv069I6w.jpeg" /><figcaption>Spurs typical narrow and deep buildup play</figcaption></figure><p>Bissouma is really key here with the key quality of being highly press-resistant (almost gives flashback to another Spurs legend Moussa Dembele). The whole backline is really comfortable and calm on the ball. The fullbacks are really dynamic in nature, they are not only good on the ball but also make runs from deep which has led to some really nice attacking sequences. Then finally comes James Maddison, who does it all: drops deep in buildup, makes movement behind the press to receive the ball in free space and also connects with the frontline in the final third and oh, he also has an eye for the goal and is a tremendous shooter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T1Gxrp5yZgRiQmotDhZ8sg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qoVLfBjcU2Ko3NR5l9tEGw.jpeg" /><figcaption>Spurs typical buildup structure with fullbacks inverted and Maddison roaming around and dropping deep</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-XY_xcdjqlg4WVXAfpxrTQ.jpeg" /><figcaption>Spurs overloading wide areas with Maddison drifting wide and Udogie (LB) making run into vacant space.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3QKtRacjdGc48p9GD_OLmQ.jpeg" /><figcaption>Maddison intelligent movement between the lines from the blinside to escape his marker</figcaption></figure><p>The image below will seem a lot strange but goes to show Spurs fluidity and creativity to come up with solutions and there great affinity to play deep and attract the opposition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tFAnlmcy4bcxocXQMqUiOA.jpeg" /><figcaption>Spurs building up with 7 players in their own half and baiting the opposition to press and open spaces in behind</figcaption></figure><p>This is what I mentioned in the previous section and you can see why it would be such an interesting battle between Arsenal’s high press and Spurs creative deep buildup play. But before that, just a brief word on Spurs off the ball play.</p><h3>Spurs Off The Ball Possession Structure</h3><p>Spurs don’t have a very complex structure off the ball, they press in a standard 4–4–2 shape or a 4–5–1 shape when sitting in a mid block.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*RQXAg1h93IFHyBib3ebLEA.jpeg" /></figure><p>They usually don’t press high and as aggressive compared to Arsenal and prefer to close off spaces in midfield.</p><p>One thing they should take care against Arsenal is having their wingers helping a lot in defensive situations so as to prevent the classic wide overloads by Arsenal. Arsenal always tries to isolate Saka and Martinelli outwide in a 1v1 situation against the opposition full-back and Spurs should try to avoid these situations.</p><h3>Key Tactical Battles</h3><p>There are a lot of things that we can narrow down on and look but as described earlier as well and I am pretty sure it will definitely be a crucial battle that can decide the nature and outcome of the game, I will be deep diving into Spurs buildup play vs Arsenal high press. Both teams are good at these respective things, but what happens when these structures will come face to face against each other?</p><p>As already shown in the previous section as well, Spurs are pretty good technically under pressure + the tactical advantage their structure provides against high press, it is Arsenal that would need to decide on their strategy as to how they are gonna react against Spurs shape.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*VbOdfc6-7VyLBaRMdWgjgg.jpeg" /></figure><p>Spurs will try to overload by dropping Maddison to create a 2v1 against Havertz or Odegaard (whoever will be marking Bissouma), the only option in this case would be to push Rice up to press as well since the wingers are narrow and are already occupied by the high and inverted positions of Spurs fullbacks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*VbOdfc6-7VyLBaRMdWgjgg.jpeg" /></figure><p>Though this is very risky, as it will leave space in between the defense and midfield lines but for Spurs to actually exploit that space, it would be very unlikely because of the intense pressure and high man-oriented press of Arsenal. The only ‘free man’ on the ball will be the Vicario (GK). They would need somehow, through smart combination play attract and then finally generate a ‘free man’ higher up the pitch to exploit this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*3VvvkkPBMibgsCQKR_45wg.jpeg" /></figure><p>Finally, as generic as it might sound, it may all come down to who is actually able to execute this better. I have been really impressed with Spurs possession play from the games that I have analysed (hard to say this openly as an Arsenal fan but credit where it is due…) and also when it comes to these 1v1 situations where you have to depend on individual quality in tight space to break the press, Spurs also have the personnel for that in the form of Bissouma and Maddison and hence I think Spurs will definitely create a threat.</p><p>I expect it to be a pretty close game but considering some other additional factors such as home advantage for Arsenal, better depth on the bench, I would go for a 2–1 Arsenal win as the most probable outcome. If that does not happen I am expecting a 2–2 or a 1–1 draw.</p><p>Anyways, I had a lot of fun analysing the game both from data and tactical perspective. I believe I could have gone even more in-depth in certain areas but I am fairly happy with what I have come up with and would love to see how it plays out this weekend at the Emirates!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ae1bd2926db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Mysterious ‘this’ keyword in Javascript Explained:]]></title>
            <link>https://medium.com/@shivank56batra/the-mysterious-this-keyword-in-javascript-explained-eabf6c3b7e0f?source=rss-3e2d44d96db3------2</link>
            <guid isPermaLink="false">https://medium.com/p/eabf6c3b7e0f</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[this-keyword]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[advanced-javascript]]></category>
            <dc:creator><![CDATA[Shivank Batra]]></dc:creator>
            <pubDate>Fri, 09 Sep 2022 18:42:20 GMT</pubDate>
            <atom:updated>2022-09-09T18:42:20.211Z</atom:updated>
            <content:encoded><![CDATA[<p>Although most programming languages share the same core concepts(variables, conditional statements, functions, loops etc), there also happens to be some features that are unique to a specific language only.</p><p>While recently learning Javascript, I have encountered quite a few quirky and novel features. One of these novel (and very important) feature is the ‘this’ keyword in Javascript. I vividly remember encountering the ‘this’ keyword when I came across the following piece of code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca899f27d6014ca04bfed436f6e0a7a5/href">https://medium.com/media/ca899f27d6014ca04bfed436f6e0a7a5/href</a></iframe><p>What should be the output of the code? (if we invoke the sayHi function) You probably guessed it, it is: “<em>Ash says hello!</em>”, but what is the use-case of the ‘this’ keyword here? What happens if we simply use “firstName” instead of “this.firstName”?</p><p>Well, if we don’t use the keyword ‘this’ then our code will throw a referenceError since the sayHi() function cannot access the “firstName” of the friend object. What the ‘this’ keyword does is that it refers to the object ‘friend’ hence when we use “this.firstName” it does not throw an error and gives us the value of Ash as the first name.</p><p>This is a very high level overview of the ‘this’ keyword but you get some idea as I did it initially. I had to dig further to fully understand the concept and other related concepts as well like: default binding, implicit binding, the ‘new’ keyword. Now, I am going to explain all this to you in concise form below.</p><h3>Default Binding</h3><p>At its core, ‘this’ refers to some object. However the value of the keyword this or the object it is referring to depends on where in our code we are placing it.</p><p>The default binding of the ‘this’ keyword is with the the global ‘window’ object. Check the following code to get a better understanding of default binding:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33e58f0c672bc1ba418a7cde95d80892/href">https://medium.com/media/33e58f0c672bc1ba418a7cde95d80892/href</a></iframe><h3>Implicit Binding</h3><p>If the word ‘this’ is being called as a method on some object. In this case, the call site has some parent object, and according to the implicit binding rule, this will refer to this parent object. The example of this would be the very first example that was showcased at the start of the article:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca899f27d6014ca04bfed436f6e0a7a5/href">https://medium.com/media/ca899f27d6014ca04bfed436f6e0a7a5/href</a></iframe><p>Here the closing function is associated parent object when the object is called i.e. the ‘friend object’ hence the ‘this’ keyword will refer to the friend object in this specific case.</p><h3>Explicit Binding + A Brief Overview Of Call, Apply And Bind:</h3><p>So far we have looked at default and implicit binding, now we are going to take a look at explicit binding. When doing explicit binding, we would like to explicitly set the context of the keyword ‘this’.</p><p>To use explicit binding, we would be using three keywords: call, apply and bind. A brief overview:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iSlSQ-7cr5RonhQEinu24w.png" /></figure><p>Here is an example of explicit binding using the ‘call’ keyword:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a38fb78b37ed8c71bcb1ab6ab6673ce6/href">https://medium.com/media/a38fb78b37ed8c71bcb1ab6ab6673ce6/href</a></iframe><p>Here, in the second and third line of console.log(), the ‘this’ eyword has been explicitly bind to person2 object. Inside the second console.log(), we don’t provide any arguments and hence it outputs “Hi, undefined” whereas it outputs “Hi, Shivank” in the next console.log() in which we did provide an argument.</p><h3>Apply</h3><p>Apply is similar to call, the only difference being that it takes a list/array of parameters as the second argument. Apply at maximum only takes two parameters: thisArg(which sets the context of the keyword this) and an array of parameters.</p><h3>Bind</h3><p>Bind is similar to call wih the only difference it does not immediately invoke the function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31862cff92269d4b3d01f3f08fb492bf/href">https://medium.com/media/31862cff92269d4b3d01f3f08fb492bf/href</a></iframe><p>A very common use case of bind is when we are using a setTimeOut() function inside an object. When the callback inside bind executes, it does not do so as a method on the parent object hence the ‘this’ keyword inside it refers to the global ‘window’ object. The example code below will make it more clear:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98bc3f03f00da805097c26bea98d2aff/href">https://medium.com/media/98bc3f03f00da805097c26bea98d2aff/href</a></iframe><p>If we didn’t use bind(this) then the context of the keyword ‘this’ would have been lost i.e. it would not longer refer to the parent object i.e. the parent “obj”. If we didn’t use bind(this) then the reference to the parent object i.e. “obj” would have been lost.</p><h3>The ‘New’ Keyword</h3><p>We have so far seen default, implicit and explicit ways of binding/determining the value of ‘this’ keyword but there is another way and that is through the use of the new keyword.</p><p>What does the ‘new’ keyword exactly do?</p><ol><li>It creates an empty object.</li><li>It sets the value of ‘this’ to that empty object.</li><li>It adds an implicit ‘return this’ statement to the function.</li></ol><p>You can see all this in action in the following piece of code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0d6523a7f300af224d043ff061ab25c/href">https://medium.com/media/b0d6523a7f300af224d043ff061ab25c/href</a></iframe><p>Congrats! we have covered everything related to the this keyword in this article. We went over what this keyword actually is and then various way of binding/determining its value.</p><p>Hope you were able to understand it all in a smooth way. Lastly, I would like to thank <a href="https://www.rithmschool.com/">https://www.rithmschool.com/</a> from where I learnt these concepts initially.</p><p>For any doubts or queries contact me on twitter: <a href="https://twitter.com/shvnk_12">https://twitter.com/shvnk_12</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eabf6c3b7e0f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Guide To Create Dumbbell Charts In Python]]></title>
            <link>https://medium.com/@shivank56batra/a-guide-to-create-dumbbell-charts-in-python-8687e8439f1?source=rss-3e2d44d96db3------2</link>
            <guid isPermaLink="false">https://medium.com/p/8687e8439f1</guid>
            <dc:creator><![CDATA[Shivank Batra]]></dc:creator>
            <pubDate>Sun, 03 Oct 2021 16:05:45 GMT</pubDate>
            <atom:updated>2021-10-03T16:05:45.432Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial I will be walking you through the process of creating dumbbell charts in Python using data analysis and plotting libraries: Pandas, Numpy and Matplotlib. Some basic knowledge of python, pandas, numpy and matplotlib is required. This guide will give you an overview of the methodology followed by me so I won’ t be explaining each and every piece of code. If you get stuck or are unable to understand any piece of code, you can refer to lot of awesome websites such as <a href="https://stackoverflow.com/">stackoverflow</a> or <a href="https://www.geeksforgeeks.org/">geeksforgeeks</a>. If your problem is still not solved, you can leave you comment below and I will try to help.</p><p>The notebook containing the whole code and the data file is available here: <a href="https://github.com/Shivank12batra/dumbbell-chart-plot">https://github.com/Shivank12batra/dumbbell-chart-plot</a> and also on this open source community website: <a href="https://sharmaabhishekk.github.io/mpl-footy/contribution-guide.html">https://sharmaabhishekk.github.io/mpl-footy/contribution-guide.html</a> (Do check other tutorial guides from this website as well if you are just getting started into football analytics or Python/data analytics in general). Now, let’s start with our tutorial!</p><h3>But What Exactly Are Dumbbell Charts?</h3><p>A dumbbell plot(also called a barbell plot) is ideal for illustrating change and comparing the distance between two groups of data points. It looks like a dumbbell, hence the name.</p><p>In the example used in this tutorial, I have visualized the top two goalscorers of each team in La Liga for the season 20/21 through the use of Dumbbell Charts. The end product will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CERpNFrwfpOyeS8-KqwjiQ.png" /><figcaption>Dumbbell Chart For LaLiga 20/21 Top Goalscorers</figcaption></figure><p>Now let’s jump right into the code!</p><h3>Importing The Necessary Libraries</h3><p>The first step before we begin is to import all the necessary libraries that will be required in the process ahead. Pandas and Numpy will be used for data pre-processing and Matplotlib will be used for plotting our dumbbell chart.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee2cd1dfa45d20ea4451580fb293c187/href">https://medium.com/media/ee2cd1dfa45d20ea4451580fb293c187/href</a></iframe><h3>Data Pre-processing</h3><p>The first step will be loading the data. The dataset which I have used here is the shots data scraped from <a href="https://understat.com/">https://understat.com/</a>. The csv file is available in the github repo link which I have provided at the beginning of the article.</p><p>Btw, if you want to make the chart for a different league and don’t know how to scrape data, I have created this easy to use library known as <a href="https://pypi.org/project/understatscraper/">understatscraper</a> which scrapes data for either a single or a whole season(for a specific league/team/player). You can check the documentation on how to use its API calls.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bec2d0da4570bb943be8255607390bb8/href">https://medium.com/media/bec2d0da4570bb943be8255607390bb8/href</a></iframe><p>The first step will be altering the ‘player’ column to only store their second names(or only the first one for player names with length one.) We are doing this so that our chart does not get cluttered with player names overlapping with each other.</p><p>We will apply the lambda function to the whole column. If length of player name is greater than one, the function will split the name into a list and then only store the second one as the player name. If the length is one then no changes will be made:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82dc7559f3c13096b65ddc60ee2299f0/href">https://medium.com/media/82dc7559f3c13096b65ddc60ee2299f0/href</a></iframe><p>The code output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*qWgVdOXTPnqEIQlaUonAzA.jpeg" /></figure><p>Now, we are going to store all the teams in a list. We are creating a list so that we can loop over it and plot the dumbbells plot for each team one by one.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6cc5a3a4dfa089b98677b40eaa426d01/href">https://medium.com/media/6cc5a3a4dfa089b98677b40eaa426d01/href</a></iframe><p>Code Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/165/1*swQyrgPl6bMqRyWMkM-VMQ.jpeg" /></figure><h3>Initial Plot Settings</h3><p>Now, we will be setting up our initial plot using the awesome Matplotlib library.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dda74950cb87eb997bb439c93a68eceb/href">https://medium.com/media/dda74950cb87eb997bb439c93a68eceb/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4tdMJl5JEyzqKMhXHgDeUg.png" /></figure><p>The above is our initial plot setup. Now, we will be removing the spines and adding labels to both axis ticks + the y axis.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edfdcc2e5da416018ba71acae5575359/href">https://medium.com/media/edfdcc2e5da416018ba71acae5575359/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yqCGWvzNV-I0cIaoGkMLtg.png" /></figure><p>Great work! We are slowly getting there. Now, our next steps will be to loop over the teams list that we created earlier and plot the dumbbell lines.</p><h3>A Bit Of Data Manipulation</h3><p>We won’t start with the plotting part just yet since we need to manipulate and get the dataframe in our desired form for each team. This is how we are going to do it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12a568091ff0b73a42559e0a32b33ad2/href">https://medium.com/media/12a568091ff0b73a42559e0a32b33ad2/href</a></iframe><p>Let’s do a walkover of the code step by step:</p><p>First, we start with looping over our teams list then we filter the dataframe for the specific team.</p><p>After the team filtering is done, we further filter out for only goals in the “result” column so that we get the columns which only contains goals as the final result. Then we groupby by the “player” column name and use the agg and the sort_values function to show all the goalscorers of that team corresponding to their number of goals scored in descending order. And then we are done!</p><p>Here what our dataframe for a specific team will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*Aojz4TmNfP84bLkQ-5hGXw.jpeg" /></figure><h3>Final Part: Main Plotting</h3><p>Now we can finally start our main plotting after we do the necessary data manipulation and get the desired dataframe output.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8fe3f3cf5c5e5050bf1a5aad9aae5c26/href">https://medium.com/media/8fe3f3cf5c5e5050bf1a5aad9aae5c26/href</a></iframe><p>We have used the scatter() method to plot the two scatter points which will represent the top two goalscorers for each team. To connect the two scatter points, we use the plot() method to create a line connecting the two. text() method is used to plot the player’s name near the scatter points and the number of goals scored inside the scatter point.</p><p>Note, that the whole plotting code is inside the loop alongside the previous data manipulation one.</p><p>Now, we will make some more additions and our final plot will be ready!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cae66732745714fa542aef75214353c/href">https://medium.com/media/3cae66732745714fa542aef75214353c/href</a></iframe><p>The code is pretty much self-explanatory. We have set the y limits of the plot using the plt.ylim() function call, setup a grid with low transparency and added the text for title and some more text at the bottom of the chart. Then finally, we use the savefig() function call to save our dumbbell plot.</p><p>And we have our final product</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CERpNFrwfpOyeS8-KqwjiQ.png" /></figure><p>Hope you enjoyed this tutorial and were able to learn something new. Have a great day!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8687e8439f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>