Python数据分析--数据可视化

本文介绍了Python数据分析中的数据可视化,包括如何建立画布、坐标系,如add_subplot、subplot2grid和subplots函数的使用,以及如何设置坐标轴标题、刻度和范围。此外,还涵盖了图表格式的设置,如网格线、图例、标题、数据标签和图表注释等细节。
摘要由CSDN通过智能技术生成

建立画布

# 导入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函数

# 将图表
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值