python-数据可视化

基础设置

#准备工作
import matplotlib.pyplot as plt
%matplotlib inline 
#让图表直接在jupyter notebook中展示出来
plt.rcParams["font.sans-serif"]='SimHei' # 解决中文乱码问题
plt.rcParams["axes.unicode_minus"]=False #解决负号无法正常显示问题
%config InlineBackend.figure_format='svg'
#设置矢量图格式显示,更加清晰

建立画布与坐标系

法一 add_subplot函数

fig=plt.figure(figsize=(4,3)) 
ax1=fig.add_subplot(1,1,1)

#在fig2上同时绘制2*2个坐标
fig2=plt.figure()
ax21=fig2.add_subplot(2,2,1)
ax22=fig2.add_subplot(2,2,2)
ax23=fig2.add_subplot(2,2,3)
ax24=fig2.add_subplot(2,2,4)

结果如图:

法二 plt.subplot2grid()函数

不需要手动建立画布 直接调用即可

#基础语句
plt.subplot2grid((2,2),(0,0)) #将整个区域划分为2列2行,并在(0,0)位置作图

#case
import numpy as np
x=np.arange(6)
y=np.arange(6)

plt.subplot2grid((2,2),(0,1))
plt.plot(x,y) #折线图

plt.subplot2grid((2,2),(0,0))
plt.bar(x,y) #折线图

结果如图:
在这里插入图片描述

法三plt.subplot函数

plt.subplot(2,2,1)
plt.plot(x,y)

plt.subplot(2,2,4)
plt.bar(x,y)

结果如图:
在这里插入图片描述

法四plt.subplots函数

fig,axes=plt.subplots(2,2)
axes[0,0].plot(x,y)
axes[1,0].bar(x,y)

结果如图:
在这里插入图片描述

设置坐标轴

其他图表设置

绘制常用图表

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值