python使用matplotlib:subplot绘制多个子图的示例 您所在的位置:网站首页 多个子图共用一个colorbar python使用matplotlib:subplot绘制多个子图的示例

python使用matplotlib:subplot绘制多个子图的示例

#python使用matplotlib:subplot绘制多个子图的示例| 来源: 网络整理| 查看: 265

数据可视化的时候,常常需要将多个子图放在同一个画板上进行比较,python 的matplotlib包下的subplot可以帮助完成子功能。

part1

绘制如下子图

import matplotlib.pyplot as plt plt.figure(figsize=(6,6), dpi=80) plt.figure(1) ax1 = plt.subplot(221) plt.plot([1,2,3,4],[4,5,7,8], color="r",linestyle = "--") ax2 = plt.subplot(222) plt.plot([1,2,3,5],[2,3,5,7],color="y",linestyle = "-") ax3 = plt.subplot(223) plt.plot([1,2,3,4],[11,22,33,44],color="g",linestyle = "-.") ax4 = plt.subplot(224) plt.plot([1,2,3,4],[11,22,33,44],color="b",linestyle = ":")

其中:

plt.figure(figsize=(6,6), dpi=80) figsize表示画板的大小,dpi为图形的分辨率 plt.plot(x,y)plot函数内可以传入两个数据,一个表示横轴一个表示y轴 ax1 = plt.subplot(221) 221表示将画板分成两行两列,取第一个区域,即左上角区域 -plt.figure(1)表示取第一块画板,一个画板即一张图,如果有多个画板,运行完就会打开多张图(多个窗口) color为线的颜色 linestyle为线的形状

part2

如果要绘制如下图

import matplotlib.pyplot as plt plt.figure(figsize=(6,6), dpi=80) plt.figure(1) ax1 = plt.subplot(221) plt.plot([1,2,3,4],[4,5,7,8], color="r",linestyle = "--") ax2 = plt.subplot(222) plt.plot([1,2,3,5],[2,3,5,7],color="y",linestyle = "-") ax3 = plt.subplot(212) plt.plot([1,2,3,4],[11,22,33,44],color="g",linestyle = "-.")

第三幅图的坐标写成212即可,即把画板分成两行一列取第二行

part3

要画成如下的样子,根据part2是一个道理

import matplotlib.pyplot as plt plt.figure(figsize=(6,6), dpi=80) plt.figure(1) ax1 = plt.subplot(221) plt.plot([1,2,3,4],[4,5,7,8], color="r",linestyle = "--") ax2 = plt.subplot(223) plt.plot([1,2,3,5],[2,3,5,7],color="y",linestyle = "-") ax3 = plt.subplot(122) plt.plot([1,2,3,4],[11,22,33,44],color="g",linestyle = "-.")

以上就是python使用matplotlib:subplot绘制多个子图的示例的详细内容,更多关于python matplotlib:subplot绘图的资料请关注脚本之家其它相关文章!

您可能感兴趣的文章:Python使用add_subplot与subplot画子图操作示例python matplotlib中的subplot函数使用详解Python figure参数及subplot子图绘制代码Python plt 利用subplot 实现在一张画布同时画多张图python中subplot大小的设置步骤


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有