top of page
Writer's pictureBen Ballard

NBA Power Rankings: Using Heat Maps with Seaborn on NBA data

Updated: Nov 22, 2023

As of November 22nd, we are almost 20% into the regular season. No doubt teams can improve, injuries unfortunately happen, and trades will occur, but this point is a great time to step back and see where teams are performing well and in what categories. To do this we take a look at statistical rankings, i.e. 1-30, for each team. It is a lot of data to sort through, and it can be hard to process as a visualization. One way I like to view this data is through heatmaps.

Heatmaps are an incredibly useful tool in data visualization, especially in displaying complex data in a simple and intuitive format. They are particularly effective in the following scenarios:

  1. Comparing Variables: Heatmaps are ideal for comparing multiple variables across different categories or entities. For instance, comparing the performance of sports teams across various statistical metrics.

  2. Identifying Patterns: They excel in highlighting trends and patterns in data, such as spotting high or low performance areas at a glance.

  3. Data with Varying Magnitude: Heatmaps can effectively represent data where the values have significant variations, as the color intensity quickly conveys this information.

  4. Correlation Analysis: When exploring the relationship between different variables, heatmaps can help in identifying correlated or inversely correlated trends.

I pulled data from the NBA API, specifically the teamdashboardbygeneralsplits end point. Feel free to try my CustomGPT to help navigate the NBA API. I split the data into Eastern and Western graphics. Although the statistical rankings are where the team ranks in the league, 1 being the best and 30 being the worst. The tables are sorted in descending order of Win Percentage Rank.


In the Western Conference, the Timberwolves current have the best win percentage. The heatmap highlights that the Timberwolves have a unique stat profile for being in first. They have extreme strengths and weaknesses. The Timberwolves strength lie in Overall Field Goal (FG) Percentage, Plus Minus, and Personal Fouls. In those categories they are top 5, but they are also bottom 5 in FGs Made, FGs Attempted, Three Pointers Made and Attempted. Interesting setup in Minnesota, I’ll have to come back shortly to see what they’re doing.

As a Mavs fan, I’m happy to see there are a lot of overall #1 ranks appearing on the page. The addition of Derek Lively has been a real boost not just on the defensive end, and rebounding, but in FG efficiency. Luka is great at finding him as a rim-runner.


Heatmap showing NBA Statistical Rankings
Western Conference Statistical Rankings

Golden State jumped off the graphic for me. It looks like they are statistically number one in a lot of areas, however, they are losing a lot of games. Not sure what’s going on in Golden State, but that has to give some optimistic to fans that they’ll start picking up games soon.


In the Eastern Conference, Boston and the Bucks are both looking great across the board. Philadelphia appears to have some real weakness made and attempted.

Heatmap Comparing Statistical Rankings
Eastern Conference Statistical Rankings

Please let me know if the heatmaps were interesting views to you. What do you see that I didn’t comment on? Any unique trends I missed?

Below is the python code that I used to to create the above graphics.


import seaborn as sns
import matplotlib.pyplot as plt

# Assume eastern_df is already defined and contains the necessary data
eastern_df = eastern_df.set_index('TEAM_NAME')

# Sort the DataFrame by a specific column in descending order
eastern_df.sort_values(by='Plus_Minus_Rank', ascending=False, inplace=True)

# Replace underscores with spaces in column names for better readability
eastern_df.columns = [col.replace('_', ' ') for col in eastern_df.columns]

# Create a custom colormap: green for low values, red for high values
cmap = sns.diverging_palette(150, 10, as_cmap=True)

# Creating and displaying the heatmap
plt.figure(figsize=(10, 8))
sns.heatmap(eastern_df, annot=True, fmt="d", cmap=cmap, linewidths=.5)
plt.title('Eastern Conference Stat Ranks')
plt.xticks(rotation=45, ha='right') 
plt.show()

Sometimes I write about data science and the NBA over at medium as well. Feel free to reach out with any questions, comments, or collaborations!

33 views0 comments

Comments


bottom of page