Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the hex size in a seaborn jointplot? (the hexes themselves, not the bins)

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,

enter image description here

but here is one that doesn't work at all Bad Plot.

enter image description here

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?

like image 510
John Smith Avatar asked Dec 02 '16 00:12

John Smith


People also ask

How do you remove a histogram from a joint plot?

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.

How do you read a Jointplot?

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).

What is Joinplot in Seaborn?

countplot() method is used to Show the counts of observations in each categorical bin using bars.

When would you use a joint plot?

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.


1 Answers

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)
like image 159
Rutger Hofste Avatar answered Sep 25 '22 23:09

Rutger Hofste