Exploration on hexagonal binning and contour areas



To use a CSV file, click here .

Loading libraries

import numpy as np

import pandas as pd

import seaborn as sns

import matplotlib.pyplot as plt

Loading data

data = pd.read_csv ( "kc_tax.csv" )

  

print (data.head ())

Exit:

 TaxAssessedValue SqFtTotLiving ZipCode 0 NaN 1730 98117.0 1 206000.0 1870 98002.0 2 303000.0 1530 98166.0 3 361000.0 2000 98108.0 4 459000.0 3150 98108.0 

Data information

print (data.shape)

print ( "" , data.info ())

Exit:

 (498249, 3) RangeIndex: 498249 entries, 0 to 498248 Data columns (total 3 columns): TaxAssessedValue 497511 non-null float64 SqFtTotLiving 498249 non-null int64 ZipCode 467900 non-null float64 dtype s: float64 (2), int64 (1) memory usage: 11.4 MB 

Data selection

# Take a subset of King County, Washington
# Tax data for assessed values ​​for tax purposes
# & lt; $ 600,000 and Legs Total Living Area & gt; 100 & amp;
# & lt; 2000

 

data = data.loc [(data [ `TaxAssessedValue` ] & lt; 600000 ) & amp; 

(data [ `SqFtTotLiving` ] & gt; 100 ) & amp; 

(data [ `SqFtTotLiving` ] & lt; 2000 )]

Check for zero value

# As you can see in the information
# that the posts are incomplete

data [ `TaxAssessedValue` ]. isnull (). values. any ()

Exit:

False

Code # 1: Hexagonal Binning

x = data [ `SqFtTotLiving` ]

y = data [ `TaxAssessedValue` ]

 

fig = sns.jointplot (x, y, kind = " hex "

color = "# 4CB391" )

  

fig.fig.subplots_adjust (top = 0.85 )

  

fig.set_axis_labels ( ` Total Sq.Ft of Living Space`

`Assessed Value for Tax Purposes` )

 

fig.fig.suptitle ( `Tax Assessed vs. Total Living Space`

size = 18 ); 

Output:

Outline Site:
Outline diagram — it is a curve along which a function of two variables has a constant value. This is a flat section of the 3D plot of the function f (x, y), parallel to the x, y plane. A contour line connects points of equal height (elevation) above a given level. Contour map — this is the map illustrated in the code below. Contour map contour spacing — this is the difference in height between successive contour lines.

Code # 2: contour section

fig2 = sns.kdeplot (x, y, legend = True )

 

plt.xlabel ( `Total Sq.Ft of Space` )

 

plt.ylabel ( `Assessed Value for Taxes` )

  

fig2.figure.suptitle ( `Tax Assessed vs. Total Living` , size = 16 ); 

Output: