首页 > 编程语言 > 详细

python 循环中使用多个subplot画子图像(python matplotlib use more than one subplot in loop)

时间:2019-11-29 11:46:41      阅读:120      评论:0      收藏:0      [点我收藏+]

在循环语句中画出多个subplot图像代码如下

http://jonathansoma.com/lede/data-studio/classes/small-multiples/long-explanation-of-using-plt-subplots-to-create-small-multiples/

https://www.howtobuildsoftware.com/index.php/how-do/mww/python-loops-matplotlib-subplot-subplots-in-matplotlib-creating-a-loop

import cv2
import matplotlib.pyplot as plt
import os
import numpy as np

path_image = ./picture

row_sum = []
count = 1
fig1 = plt.figure()
fig2 = plt.figure()

for i in [packing_list.png, packing_list90.png, packing_list180.png, packing_list270.png]:
    # 计算水平投影,即投影到y轴
    path_image_current = os.path.join(path_image, i)
    image = cv2.imread(path_image_current, 0)
    binary = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]

    row_sum_per = np.sum(binary, axis=1).tolist()
    row_sum.append(row_sum_per)
    
    # 画图
    ax1 = fig1.add_subplot(2, 2, count)
    ax1.imshow(image, gray)
    ax2 = fig2.add_subplot(2, 2, count)
    ax2.plot(row_sum_per)

    count = count + 1
plt.show()

结果图形:

技术分享图片技术分享图片

 

python 循环中使用多个subplot画子图像(python matplotlib use more than one subplot in loop)

原文:https://www.cnblogs.com/ttweixiao-IT-program/p/11956669.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!