This page has information about data visualization, containing types of plots, use cases, and how to implement using various python libraries.
Overview
PyPlot
fast
easy
only on figure
Object Oriented
better customization
friendly for multiple charts
more coding
Seaborn
based on matplotlib
integrated with pandas
speed
easy to use
customizable
Implementation
Importing libraries using the standard of the industry
Code
import matplotlib.pyplot as pltimport numpy as npimport seaborn as snsimport pandas as pd
PyPlot (matplotlib)
Code
fig, ax = plt.subplots() # Create a figure containing a single axesax.plot([1,2,3,4], [1,4,2,3]);# plot some data on the axes
Code
# linspace# Return evenly spaced numbers over a specified interval.# Returns num evenly spaced samples, calculated over the interval [start, stop].#The endpoint of the interval can optionally be excluded.x = np.linspace(0,5,11)y = x**2print(x)print(y)plt.plot(x,y,'rx')plt.show()
C:\Users\carlj\AppData\Local\Temp\ipykernel_42696\2806661265.py:3: UserWarning:
Matplotlib is currently using module://matplotlib_inline.backend_inline, which is a non-GUI backend, so cannot show the figure.
C:\Users\carlj\AppData\Local\Temp\ipykernel_42696\3333502070.py:4: UserWarning:
Matplotlib is currently using module://matplotlib_inline.backend_inline, which is a non-GUI backend, so cannot show the figure.
C:\Users\carlj\AppData\Local\Temp\ipykernel_42696\111565761.py:11: UserWarning:
Matplotlib is currently using module://matplotlib_inline.backend_inline, which is a non-GUI backend, so cannot show the figure.
C:\Users\carlj\AppData\Local\Temp\ipykernel_42696\4205225829.py:3: UserWarning:
Matplotlib is currently using module://matplotlib_inline.backend_inline, which is a non-GUI backend, so cannot show the figure.
C:\Users\carlj\AppData\Local\Temp\ipykernel_42696\518181344.py:4: UserWarning:
Matplotlib is currently using module://matplotlib_inline.backend_inline, which is a non-GUI backend, so cannot show the figure.
C:\Users\carlj\AppData\Local\Temp\ipykernel_42696\4260253020.py:7: UserWarning:
Matplotlib is currently using module://matplotlib_inline.backend_inline, which is a non-GUI backend, so cannot show the figure.
Code
fig, axes = plt.subplots(1,2, figsize=(8,5))axes[0].plot(x,y)axes[0].set_title('Relation X and Y')axes[0].set_xlabel('X')axes[0].set_ylabel('Y')axes[1].plot(y,x)axes[1].set_title('Relation Y and X')axes[1].set_xlabel('Y')axes[1].set_ylabel('X')fig.show()
C:\Users\carlj\AppData\Local\Temp\ipykernel_42696\256813773.py:12: UserWarning:
Matplotlib is currently using module://matplotlib_inline.backend_inline, which is a non-GUI backend, so cannot show the figure.
Code
plt.plot(x,y,label='sin(x)')plt.title('This is a title')plt.xlabel('X')plt.ylabel('Y')plt.legend() # plt.legend(loc='lower right')plt.show()