Basic Visualisation
COMP2420/COMP6420 – Introduction to Data Management, Analysis and Security
Lecture – Basic Visualisation
Copyright By PowCoder代写 加微信 powcoder
Matplotlib – Line Plots¶
from matplotlib import pyplot as plt
%matplotlib inline
1. Plot the Line¶
time = [0, 1, 2, 3, 4]
revenue = [200, 400, 650, 800, 850]
costs = [150, 500, 550, 550, 560]
2. Changing the appearance of the line¶
3. Zooming in on different parts of the axis¶
4. Putting labels on titles and axes¶
x = range(12)
y = [3000, 3005, 3010, 2900, 2950, 3050, 3000, 3100, 2980, 2980, 2920, 3010]
5. Creating a more complex figure layout¶
x = [1, 2, 3, 4]
y = [1, 2, 3, 4]
z = [3, 2, 1, 1]
6. Arranging Sub-Plots¶
x = range(7)
straight_line = [0, 1, 2, 3, 4, 5, 6]
parabola = [0, 1, 4, 9, 16, 25, 36]
cubic = [0, 1, 8, 27, 64, 125, 216]
6. Adding legends to graphs¶
months = range(12)
Data1 = [63, 65, 68, 70, 72, 72, 73, 74, 71, 70, 68, 64]
Data2 = [52, 52, 53, 68, 73, 74, 74, 76, 71, 62, 58, 54]
Data3 = [98, 99, 99, 100, 99, 100, 98, 101, 101, 97, 98, 99]
Matplotlib & Pandas¶
import pandas as pd
df = pd.DataFrame({
‘name’:[‘john’,’mary’,’peter’,’jeff’,’bill’,’lisa’,’jose’],
‘age’:[23,78,22,19,45,33,20],
‘gender’:[‘M’,’F’,’M’,’M’,’M’,’F’,’M’],
‘state’:[‘california’,’dc’,’california’,’dc’,’california’,’texas’,’texas’],
‘num_children’:[2,0,0,3,2,1,4],
‘num_pets’:[5,1,0,5,2,2,3]
1. Plot two dataframe columns as a scatter plot¶
2. Plot column values as a bar plot¶
3. Line plot with multiple columns¶
4. Bar plot with group by¶
5. Plot histogram of column values¶
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com