Using a hexagonal jointplot in Seaborn to produce some "heat maps" showing where on the court basketball players take the most shots. The data comes from a pandas dataframe, where LocX represents the player's horizontal position on the court (-250 and 250 are the sidelines, 0 is in line with the basket), and LocY is the length-wise distance from the basket. I use the same code to produce maps for multiple players, but the size of the hexagons varies wildly between players (even when two players have a similar number of total shots). Here is one that comes out just as I'd like Good Plot,
but here is one that doesn't work at all Bad Plot.
Here is my code generating it:
cmap=plt.cm.gist_heat_r
joint_shot_chart = sns.jointplot(shot_df.LocX, shot_df.LocY, stat_func=None, kind='hex', space=0, color=cmap(.2), cmap=cmap)
Is there a kwarg that I can use to change the size of the hexagons?
In case you want to remove the histogram/distribution plot appearing on the jointplot's axes the command that you need to use is? You cannot remove the distribution plot from the Jointplot. In case you don't want it, you can always use pyplot. scatter() or sns.
A Jointplot comprises three plots. Out of the three, one plot displays a bivariate graph which shows how the dependent variable(Y) varies with the independent variable(X). Another plot is placed horizontally at the top of the bivariate graph and it shows the distribution of the independent variable(X).
countplot() method is used to Show the counts of observations in each categorical bin using bars.
Jointplot is seaborn library specific and can be used to quickly visualize and analyze the relationship between two variables and describe their individual distributions on the same plot.
You can parse the gridsize
argument. A higher value results in smaller hexbins.
import numpy as np, pandas as pd; np.random.seed(0)
import seaborn as sns; sns.set(style="white", color_codes=True)
tips = sns.load_dataset("tips")
joint_kws=dict(gridsize=5)
g = sns.jointplot(x="total_bill", y="tip", data=tips,kind="hex", joint_kws= joint_kws)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With