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

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically