数据可视化
建立画布
# 导入matplotlib库中的pyplot并命名为plt
import matplotlib.pyplot as plt
# 让图表直接在Jupyter Notebook中展示出来
%matplotlib inline
# 解决中文乱码问题
plt.rcParams['font.sans-serif'] = ['Arial Unicode MS'] # Mac下字体Arial Unicode MS
# 解决负号无法正常显示问题
plt.rcParams['axes.unicode_minus'] = False
%config InlineBackend.figure_format = 'svg'
# 建立默认尺寸画布
fig = plt.figure()
>>>
<Figure size 432x288 with 0 Axes>
# 建立宽8高6的画布
fig = plt.figure(figsize = (8,6))
>>>
<Figure size 576x432 with 0 Axes>
- 注:画布不会直接显示,只会输出一串画布相关信息的代码
建立坐标系
add_subplot 函数建立坐标系
# 先绘制画布
# 绘制2X2个坐标,即4个坐标系
fig = plt.figure()
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,3)
ax4 = fig.add_subplot(2,2,4)
plt.subplot2grid 函数建议坐标系
不需要绘制画布,直接导入plt库调用subplot2grid函数
#将图表整个区域分成2行2列,且在(0,0)位置绘图
plt.subplot2grid((2,2),(0,0))
plt.subplot 函数建立坐标系
不需要绘制画布,直接导入plt库调用subplot函数
# 将图表