数据可视化(六)多个子图及seaborn使用

1.多个子图绘制

python 复制代码
#绘制多个子图
#subplot(*args,**kwargs)  每个subplot函数只能绘制一个子图
#subplots(nrows,ncols)
#fig_add_subplot(行,列,区域)
#绘制子图第一种方式
plt.subplot(2,2,1)#第一个绘图区域两行两列
#plt.subplot(221)简写方式
plt.plot([1,2,3,4,5],[random.randint(1,10) for i in range(5)])
plt.subplot(2,2,2)#两行两列绘图区的第二个绘图区
plt.plot([1,2,3,4,5],[random.randint(1,10) for i in range(5)],'ro')
plt.subplot(2,1,2)#两行一列  ,第二行绘制
x=[1,2,3,4,5]
y=[random.randint(10,50) for i in range(5)]
plt.bar(x,y)
plt.show()
python 复制代码
#绘制的第二种方式
#两行三列的画图区域
#figure画布,axes坐标轴对象
figure,axes=plt.subplots(2,3)
plt.show()

figure,axes=plt.subplots(2,2)
axes[0,0].plot([1,2,3,4,5],[random.randint(1,10) for i in range(5)])
axes[0,1].plot([1,2,3,4,5],[random.randint(1,10) for i in range(5)],'ro')
x=[1,2,3,4,5]
y=[random.randint(10,50) for i in range(5)]
axes[1,0].bar(x,y)
x=[random.randint(10,50) for i in range(5)]
axes[1,1].pie(x,autopct='%1.1f%%')
plt.show()
python 复制代码
#绘制子图的第三种方式
#绘制画布
fig=plt.figure()
ax1=fig.add_subplot(2,2,1)  #两行两列第一个绘图区域
ax1.plot([1,2,3,4,5],[random.randint(1,10) for i in range(5)])
ax2=fig.add_subplot(2,2,2)  #两行两列第二个绘图区域
ax2.plot([1,2,3,4,5],[random.randint(1,10) for i in range(5)],'ro')
ax3=fig.add_subplot(2,2,3)
ax3.bar([1,2,3,4,5],[random.randint(1,10) for i in range(5)])
ax4=fig.add_subplot(2,2,4)
ax4.pie([random.randint(1,10) for i in range(5)],autopct='%1.1f%%')
plt.show()
python 复制代码
#图表的保存
#图表保存格式jpeg,tiff,png
#plt.savefig(图名)

3.seaborn使用,首先安装。如果在pycharm中安装报错,先安装Scipy

python 复制代码
import matplotlib.pyplot as plt
import seaborn as sns
#seaborn绘图
#绘制简单柱状图
sns.set_style('darkgrid')#设置风格样式
x=[1,2,3,4,5]
y=[20,6,50,9,56]
sns.barplot(x,y)
plt.show()
相关推荐
HuashuiMu花水木20 小时前
Matplotlib笔记4----------图像处理
图像处理·笔记·matplotlib
程序员阿超的博客2 天前
Python 数据分析与机器学习入门 (五):Matplotlib 数据可视化基础
python·信息可视化·数据分析·matplotlib·数据可视化·python教程·pyplot
音程14 天前
Matplotlib绘制矩阵图,plt.matshow/imshow 与 ax.pcolor(pcolormesh)方法的使用
matplotlib
搏博15 天前
基于Python、tkinter、sqlite3 和matplotlib的校园书店管理系统
python·信息可视化·sqlite·matplotlib
勤奋的知更鸟17 天前
Matplotlib 绘图库使用技巧介绍
开发语言·python·matplotlib
@小红花18 天前
Matplotlib快速入门
matplotlib
仟濹21 天前
「Matplotlib 入门指南」 Python 数据可视化分析【数据分析全栈攻略:爬虫+处理+可视化+报告】
python·信息可视化·数据分析·matplotlib
Jay_2724 天前
cloudstudio腾讯云:matplotlib 设置中文字体
腾讯云·matplotlib
Gyoku Mint1 个月前
机器学习×第二卷:概念下篇——她不再只是模仿,而是开始决定怎么靠近你
人工智能·python·算法·机器学习·pandas·ai编程·matplotlib
搏博1 个月前
将图形可视化工具的 Python 脚本打包为 Windows 应用程序
开发语言·windows·python·matplotlib·数据可视化