Friday , March 31 2023
Home / Data Science (page 3)

Data Science

Histogram using Matplotlib

Histogram using Matplotlib

7 Histogram Plot a Histogram Plot using Matplotlib¶A histogram is a graphical representation of a set of data points arranged in a user-defined range. Similar to a bar chart, a bar chart compresses a series of data into easy-to-interpret visual objects by grouping multiple data points into logical areas or …

Read More »

Stack Plot using Matplotlib

Stack Plot using Matplotlib

6 Stack Plot Plot a Stack Plot using Matplotlib¶Stack Plots are used to visualize multiple linear plots, stacked on top of each other. With a regular line plot, you’d plot the relationship between X and Y. Here, we’re plotting multiple Y features on a shared X-axis, one on top of …

Read More »

Scatter Plot using Matplotlib

Scatter Plot using Matplotlib

5. Scatter Plot Plot Scatter Plot Using Matplotlib¶With Pyplot, you can use the scatter() function to draw a scatter plot. The scatter() function plots one dot for each observation. It needs two arrays of the same length, one for the values of the x-axis, and one for values on the …

Read More »

Pie Plot using Matplotlib

Pie Plot using Matplotlib

4. Pie Plot Plot a Pie Chart using Matplotlib¶Pie charts represent data broken down into categories/labels. They’re an intuitive and simple way to visualize proportional data – such as percentages. To plot a pie chart in Matplotlib, we can call the pie() function of the PyPlot or Axes instance. The …

Read More »

Line Plot using Matplotlib

Line Plot using Matplotlib

2. Line Plot Plot a Line Plot Using Matplotlib¶To plot a line plot in Matplotlib, you use the generic plot() function from the PyPlot instance. There’s no specific lineplot() function – the generic one automatically plots using lines or markers. In [2]: import matplotlib.pyplot as plt X = [2,4,6,8,10] Y = …

Read More »

Bar Plot using Matplotlib

Bar Plot using Matplotlib

3 Bar Plot Plot a Bar Plot Using Matplotlib¶Plotting a Bar Plot in Matplotlib is as easy as calling the bar() function on the PyPlot instance, and passing in the categorical and numerical variables that we’d like to visualize. In [2]: import matplotlib.pyplot as plt x = ['A', 'B', 'C'] y …

Read More »

Introduction to Matplotlib

Introduction to Matplotlib

1. Introduction to Matplotlib What Is Python Matplotlib?¶ Matplotlib is a low level graph plotting library in python that serves as a visualization utility. Matplotlib was created by John D. Hunter. Matplotlib is open source and we can use it freely. Matplotlib is mostly written in python, a few segments …

Read More »

Suicide Case Study – NumPy

Suicide Case Study – NumPy

13 Suicide Case Study – Numpy Import Libraries¶ In [2]: import numpy as np Read CSV¶ In [3]: data = np.genfromtxt('Suicidesindia2001-2012.csv',delimiter=',',dtype=str) data Out[3]: array([['State', 'Year', 'Type_code', ..., 'Gender', 'Age_group', 'Total'], ['A & N Islands', '2001', 'Causes', ..., 'Female', '0-14', '0'], ['A & N Islands', '2001', 'Causes', ..., 'Female', '0-14', '0'], ..., ['West …

Read More »

NumPy Set Operations

NumPy Set Operations

11 – Set Operations Numpy Set Operations¶ In [1]: import numpy as np select the unique elements from an array¶ In [2]: arr = np.array([1,1,2,2,3,3,4,5,6]) print(np.unique(arr)) [1 2 3 4 5 6] In [3]: # return the number of times each unique item appears arr = np.array([1,1,2,2,3,3,4,5,6]) uniques, counts = np.unique(arr, return_counts=True) print(uniques) …

Read More »

Combine & Split an Array

Combine & Split an Array

10 – Combine & Split an Array In [2]: import numpy as np In [3]: arr1 = np.array([[1,2,3,4], [1,2,3,4]]) arr2 = np.array([[5,6,7,8], [5,6,7,8]]) np.concatenate((a, b), axis=0)¶ In [4]: arr1 Out[4]: array([[1, 2, 3, 4], [1, 2, 3, 4]]) In [5]: arr2 Out[5]: array([[5, 6, 7, 8], [5, 6, 7, 8]]) In [6]: # concat along …

Read More »