Notebook 1 - Matplotlib Basics
Notebook 1 - Matplotlib Basics
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns #using for builtin datasets
In [8]:
plt.style.use('seaborn-white')
print(plt.style)
In [2]:
plt.figure(figsize=(9, 3))
plt.subplot(131)
plt.bar(names, values)
plt.subplot(132)
plt.scatter(names, values)
plt.subplot(133)
plt.plot(names, values)
plt.suptitle('Categorical Plotting')
plt.show()
In [9]:
plt.plot([1, 9, 3, 4])
plt.show()
In [10]:
In [4]:
x = range(1,6)
plt.plot(x, [xi**2 for xi in x])
plt.show()
In [5]:
Multiline Plot
In [6]:
x = [0, 1, 2, 3, 4, 5]
y = [0, 5, 3, 2, 1, 2]
z = [4, 9, 3, 2, 8, 1]
plt.plot(x, y)
plt.plot(x, z)
plt.show()
In [7]:
x = [0, 1, 2, 3, 4, 5]
y = [0, 5, 3, 2, 1, 2]
plt.plot(x,y)
plt.grid(False)
plt.axis(xmin = 0, xmax = 9, ymin = 0, ymax = 7)
plt.show()
In [8]:
x = [0, 1, 2, 3, 4, 5]
y = [0, 5, 3, 2, 1, 2]
plt.plot(x,y)
plt.xlabel("Age")
plt.ylabel("Sales amount")
plt.title("Sales amount by Age")
plt.show()
In [11]:
x = [0, 1, 2, 3, 4, 5]
y = [0, 5, 3, 2, 1, 2]
plt.title("Legend Demo")
plt.plot(x,y, label="regular")
plt.plot(y,x, label="reverse")
plt.legend()
plt.show()
Complete Example
In [12]:
x = np.arange(1, 5)
plt.title("Matplotlib Graphs")
plt.grid(False)
plt.xlabel('numbers')
plt.ylabel('derived')
plt.legend()
plt.show()
Save to File
In [13]:
x = np.arange(1, 5)
plt.grid(False)
plt.xlabel('numbers')
plt.ylabel('derived')
plt.legend()
plt.savefig("complete_plot.png")
plt.show()
x = np.arange(1, 5)
plt.plot(x, 'y')
plt.plot(x + 1, 'g')
plt.plot(x + 2, 'r')
plt.grid(False)
plt.xlabel('numbers')
plt.ylabel('derived')
plt.show()
In [15]:
x = np.arange(1, 5)
plt.plot(x, '-')
plt.plot(x + 1, '*')
plt.plot(x + 2, '--')
plt.grid(False)
plt.xlabel('numbers')
plt.ylabel('derived')
plt.show()
In [16]:
x = np.arange(1, 5)
plt.plot(x, 'D')
plt.plot(x + 1, 'o')
plt.plot(x + 2, 's')
plt.grid(False)
plt.xlabel('numbers')
plt.ylabel('derived')
plt.show()
In [ ]:
x = np.arange(1, 5)
plt.plot(x, 'cD-')
plt.plot(x + 1, 'go')
plt.plot(x + 2, 'rs--')
plt.grid(False)
plt.xlabel('numbers')
plt.ylabel('derived')
plt.show()
In [17]:
x = np.arange(1, 5)
plt.grid(False)
plt.xlabel('numbers')
plt.ylabel('derived')
plt.show()
In [18]:
x = np.arange(1, 5)
plt.show()
In [ ]: