Skip to main content

Bubble plot - data visualization package

Project description

bubble_plot

Hi everyone!

I love data visualizations! And if you love them too, I think you will find this bubble plot very nice and useful.

How to install

Very simple - just write in your command line:

pip install bubble_plot

Motivation & Usage

The goal for the bubble plot is to help us visualize linear and non-linear connections between numerical/categorical features in our data in an easy and simple way. The bubble plot is a kind of a 2-dimensional histogram using bubbles. It suits every combination of categorical and numerical features.

The bubble size is proportional to the frequency of the data points in this point.

Function signature:

bubble_plot(df, x, y, z_boolean=None, ordered_x_values=None, ordered_y_values=None, bins_x=10, bins_y=10, fontsize=16, 
            figsize=(15,10), maximal_bubble_size=5000, normalization_by_all = False, log=False)

For numerical features the values will be presented in buckets (ten equally spaced bins will be used as default, you can provide the specific bins / bins number through the bin_x and bins_y parameters).

For categorical features the features will be presented according to their categories. If you would like a specific order for the categories presentation please supply a list of the values by order using the ordered_x_values / ordered_y_values parameters.

You can plot a numerical feature vs. another numerical feature or vs. a categorical feature or a categorical feature vs another categorical feature or numerical feature. All options are possible.

Setting the log parameter to True would apply the natural log function - element wise - on the counts which will make the differences between the largest bubble to the smallest bubble much smaller, so if you have large differences between the frequencies of different values you might want to use that.

Setting the z_boolean parameter to a name of categorical field with two categories / boolean field would make the color of the bucket be proportional to the ratio ( (boolean_z==value_1).sum()/(boolean_z==value_1).sum() + (boolean_z==value_2).sum()) of the z values for this bucket.

Usage Example

import pandas as pd                             
from sklearn.datasets import load_boston                            
data = load_boston()                            
df = pd.DataFrame(columns=data['feature_names'], data=data['data'])                            
df['target'] = data['target']                            
bubble_plot(df, x='RM', y='target')    

The resulting bubble plot will look like this:

Dependencies

  • pandas
  • numpy
  • matplotlib

Contact

More usage examples and explanations can be found at: https://medium.com/@DataLady/exploring-the-census-income-dataset-using-bubble-plot-cfa1b366313b

Please let me know if you have any questions. My email is meir.shir86@gmail.com.

Enjoy, Shir

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

bubble_plot-0.2-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file bubble_plot-0.2-py3-none-any.whl.

File metadata

  • Download URL: bubble_plot-0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.29.1 CPython/3.7.2

File hashes

Hashes for bubble_plot-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1b6cd929ab52af57071b026b02280952df335f2900a83b4f9f4fadbf94974625
MD5 52b41527ec4cb6d277e2e8d7191c692a
BLAKE2b-256 8144ea63665403e2f51c4b8b0429d579e50e5e17b959a97bf95143245c7a5b01

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page