import matplotlib.pyplot as plt
Basic functions
plt.figure(figsize=(width_inch,height_inch))
Bar chart
plt.bar(x=df['col1'], height=df['col2'],label="col2 count")
plt.plot()
plt.xlabel('col1')
plt.ylabel('col2')
plt.title('chart title')
plt.legend()
plt.show()
Rotate x Lables
plt.xticks(rotation=45,horizontalalignment='right')
Histogram
plt.hist([df['col1'],df['col2']], bins=range(1,101,10))
plt.xticks(range(10,101,10))
plt.yticks(range(10,101,10))
plt.xlabel(['col1','col2'])
plt.ylabel('coly')
plt.title('chart title')
plt.show()
df['col'].hist()
Scatter Plot
plt.scatter(x=df['col1'],y=df['col2']);
Q-Q Plot
import statsmodels.api as sm
import matplotlib.pyplot as plt
g = sm.qqplot(residuals,line='s')
plt.show()
Subplot
fig, axes = plt.subplots(1,2)
sns.histplot(df['col1],ax = axes[0])
axes[0].set_xlabel('xlabel')
axes[0].set_ylabel('ylabel')
axes[0].set_title('title')
sns.histplot(df['col1],ax = axes[1])
axes[1].set_xlabel('xlabel')
axes[1].set_ylabel('ylabel')
axes[1].set_title('title')
plt.show()
Read Image
img = plt.imread(image_filepath)
Show Image
plt.imshow(img)
Turn off axis on sides
plt.axis('off');
Convert 2D image array to 1D image array
img1D = img.reshape(img.shape[0]*img.shape[1],3)
Construct 1D image dataframe
imgdf = pd.DataFrame(img1D,columns=['r','g','b'])