Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to plot bubble chart using matplotlib, numpy and pandas in python?

Description

To plot bubble chart for given data sample using python.

Process

  Read the sample data.

  Import needed libraries.

  Assign x,y,z for plotting.

  Use plt.scatter() to plot the bubble chart.

Sample Code

#import libraries

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

#Read the sample data

data=pd.read_csv(‘/home/soft27/

Sathish/Pythonfiles/Employee.csv’)

#create data frame

df=pd.DataFrame(data)

#assign x variable

x = df[‘salary’]

#assign y variable

y = df[‘bonus’]

z = np.random.rand(10)

#pick random color

colors = np.random.rand(10)

#plot the bubble chart

plt.scatter(x, y, s=z*1000,c=colors)

plt.xlabel(‘salary’)

plt.ylabel(‘bonus’)

plt.show()

Screenshots
plot bubble chart using matplotlib, numpy and pandas in python
import pandas as pd