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

2

16

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?

Francesco answered 2/12, 2016 at 0:54 Comment(4)
try use "gridsize" as a parameter? there is a discussion about it. github.com/mwaskom/seaborn/pull/186Incorruptible
That worked! Really weird, I tried that earlier with no luck. Wonder what I was doing wrong. Thanks a ton!Francesco
nice, I'm glad that it works.Incorruptible
Did u add the bg image externally or is there any function in seaborn?Cosecant
T
14

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)
Tautomer answered 25/6, 2018 at 10:23 Comment(1)
Doesn't work for me: AttributeError: 'QuadMesh' object has no property 'gridsize'Spearhead
A
-1
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")
g = sns.jointplot(x="total_bill", y="tip", data=tips,kind="hex",gridsize=20)
Aeroballistics answered 19/3 at 7:21 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Kareenkarel

© 2022 - 2024 — McMap. All rights reserved.