Matplotlib
Matplotlib
Matplotlib
In [1]:
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
In [2]:
fig, ax = plt.subplots()
print(type(fig))
print(type(ax))
<class 'matplotlib.figure.Figure'>
<class 'matplotlib.axes._subplots.AxesSubplot'>
In [3]:
fig, ax = plt.subplots()
x = np.random.randint(1,10, size=10)
y = 2*x
plt.plot(x,y) # same as ax.plot(x,y)
plt.show()
localhost:8888/notebooks/Untitled42.ipynb?kernel_name=python3 1/8
3/16/23, 7:34 PM Untitled42 - Jupyter Notebook
In [4]:
fig, ax = plt.subplots()
x = np.linspace(0,10,1000)
y = 2*x
Out[4]:
[<matplotlib.lines.Line2D at 0x21bc069f970>]
localhost:8888/notebooks/Untitled42.ipynb?kernel_name=python3 2/8
3/16/23, 7:34 PM Untitled42 - Jupyter Notebook
In [5]:
Scatter Plot
In [6]:
import pandas as pd
df=pd.read_csv("happiness_Rank.csv")
In [7]:
df.head()
Out[7]:
localhost:8888/notebooks/Untitled42.ipynb?kernel_name=python3 3/8
3/16/23, 7:34 PM Untitled42 - Jupyter Notebook
In [8]:
Out[8]:
BarChart
In [10]:
df_19=df[df["Year"]==2019]
df_19.head()
Out[10]:
localhost:8888/notebooks/Untitled42.ipynb?kernel_name=python3 4/8
3/16/23, 7:34 PM Untitled42 - Jupyter Notebook
In [11]:
Histogram
localhost:8888/notebooks/Untitled42.ipynb?kernel_name=python3 5/8
3/16/23, 7:34 PM Untitled42 - Jupyter Notebook
In [12]:
fig = plt.figure(figsize=(8,6))
plt.hist(df_19['Corruption'], bins=6, density=True)
plt.grid(alpha=0.2)
plt.show()
Box Plot
localhost:8888/notebooks/Untitled42.ipynb?kernel_name=python3 6/8
3/16/23, 7:34 PM Untitled42 - Jupyter Notebook
In [13]:
# Create dataset
user_1 = [10, 3, 15, 21, 17, 14]
user_2 = [5, 13, 10, 7, 9, 12]
data = [user_1, user_2]
fig = plt.figure(figsize =(8, 6))
# Create plot
bp = ax.boxplot(data)
# Show plot
plt.xticks([1,2],['user_1','user_2'])
plt.show()
localhost:8888/notebooks/Untitled42.ipynb?kernel_name=python3 7/8
3/16/23, 7:34 PM Untitled42 - Jupyter Notebook
In [14]:
In [ ]:
localhost:8888/notebooks/Untitled42.ipynb?kernel_name=python3 8/8