Adding these requires a couple of extra matplotlib tools. Our base figure provides the canvas for the club badges. Adding badges will hopefully add more value and information to our plot. Super simple chart, and without annotations or visual cues we cannot tell who any of the points are. We have covered scatter plots before here, so let’s get straight into it. Once we have this, we can get fancy with our badges and other cosmetic changes. This gives us the correct dimensions of the plot, the axes and other benefits of working with a matplotlib figure in Python. Let’s save this in a new column called ‘path’: df = df + ‘.png’īefore making our plot with the badges, we need to create a regular scatter plot. As we took the time to match the badge file names against the team names, this is really simple – we just add ‘images/‘ before and ‘.png’ after the team name. We have our numbers to plot, but we need to add a reference for each team’s badge location in a new column. Let’s import our modules, data and check the first few lines of the dataframe: import pandas as pdįrom matplotlib.offsetbox import OffsetImage, AnnotationBbox To start with, our data has three columns: team name, xG for and xG against. All of this is already prepared for you in the Github folder. The team names match up to the data that we are going to use soon. The simplest way to do this is to keep them all in a folder alongside our code and have a naming convention of ‘team name’.png. To automate plotting each image, we need to have some order to our image locations and names.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |