Change language

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
# "$ 600,000 and Legs Total Living Area" 100 & amp;
# "2000

 

data = data.loc [(data [ ’TaxAssessedValue’ ] " 600000 ) & amp; 

(data [ ’SqFtTotLiving’ ]" 100 ) & amp; 

(data [ ’SqFtTotLiving’ ] " 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:

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method