matplotlib自定义图表
matplotlib 模块是最基本的 Python 模块,在它上面还有更加高级的 API 封装库,比如 seaborn 模块和pyechart 模块。所以,matplotlib 模块可以轻松的完成自定义图表的设置。
准备工作
导入我们下面用到的相关的库和模块。
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
%matplotlib inline
import matplotlib.pyplot as plt
创建子图
matplotlib绘制的图像在 figure对象中,通过figure() 函数可以创建一个新的figure,而它的参数figsize 可以设置图表的长宽比。下面,通过add_subplot() 函数创建子图。
fig = plt.figure(figsize=(10,6))
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,3)
其中,每一个ax对象都代表一个子图。
图表布局
把三个ax对象都