Pandas DataFrame Plot hexbin graph

Pandas.DataFrame.plot to generate hexbin using data
DataFrame hexbin chart
import pandas as pd 
import numpy as np 
n = 10000
df=pd.DataFrame({'x': np.random.randn(n),
                'y': np.random.randn(n)})
ax=df.plot.hexbin(x='x',y='y',gridsize=20)

hexbin chart with options

There are several options we can add to above hexbin diagram.

title :

title='hexbin Plot' String used as Title of the graph.

figsize :

figsize=(6,3)
Size of the graph , it is a tuple saying width and height in inches, figsize=(6,3). Here width is 6 inches and height is 3 inches.
df.plot.hexbin(x='x',y='y',gridsize=20,figsize=(6,3))

fontsize

fontsize=20 , we can set the font size used labels in x and y axis. fontsize=20
df.plot.hexbin(x='x',y='y',gridsize=20,fontsize=20)

color

color option for hexbin diagram We can use the option colors to give different colors to line . We can use one tuple to define the colours.

df.plot.hexbin(x='x',y='y',gridsize=20,title='hexbin Plot',color=[(.9,.2,.6)])

grid

We will show grid ( grid=True ) or not ( grid=False) grid=True option grid=False option






df.plot.hexbin(x='x',y='y',gridsize=20,title='grid=True',grid=True)

logx logy loglog

option logy=True We can specify log scaling or symlog scaling for x ( logx=True ) or y ( logy=True ) or for both x & y ( loglog=True)



df.plot.hexbin(x='x',y='y',gridsize=20,title='loglog=True',loglog=True)
Pandas plot plot.barh()
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer