美文网首页stata绘图与估计结果输出
Stata&Python--PIL库多个图片拼接

Stata&Python--PIL库多个图片拼接

作者: 古城路揸fit人 | 来源:发表于2020-03-07 21:21 被阅读0次

    两张图

    import os
    from PIL import Image
    
    
     
    def join(png1, png2, name):
    
        img1, img2= Image.open(png1), Image.open(png2)
        size1, size2 = img1.size, img2.size  
        joint = Image.new('RGB', (size1[0]+size2[0], size1[1]))
        #joint = Image.new('RGB', (size1[0]+size2[0]+size3[0], size1[1])) 如果是三张图就这么写
        loc1, loc2 = (0, 0), (size1[0], 0) #如果是三张图,这里第三个数组是(size1[0]+size2[0], 0)
        
        joint.paste(img1, loc1)
        joint.paste(img2, loc2)
        #joint.paste(img3, loc3) 如果有三张图的话就再加一个
        joint.save(name)
    
    if __name__ == '__main__':    
            for i in [1,2,3,7,8,9,10]:
                png1 = "D:\\毕业论文\\output\\三水\\Figure"+str(i)+".png"
    
                png2 = "D:\\毕业论文\\output\\顺德\\Figure"+str(i)+".png"
    
                os.chdir("D:\\毕业论文\\output")
    
                name = "map"+str(i)+".png"
                join(png1, png2, name)
    

    三张图

    ## 平减后结果201912月  挑出来 的高质量结果的拼接
    import os
    from PIL import Image
    
    '''
    def croop(pngg):
        png=Image.open(pngg)
        half_the_width = png.size[0] 
        half_the_height = png.size[1] 
        png = png.crop((2,2,half_the_width - 2, half_the_height - 2))
        png.save(pngg)
    for i in ["Guangdong","Chongqing","Hubei"]:
        for j in range(1,25):
            croop("D:\\碳交易试点评估\\sectoral_approach_deflator\\sectoral_approachsectoral_approach1432\\output\\"+i+"\\Figure"+str(j)+".png")
    ''' 
    def join(png1, png2, png3, name):
    
        img1, img2 ,img3= Image.open(png1), Image.open(png2), Image.open(png3)
        size1, size2, size3 = img1.size, img2.size, img3.size    
        joint = Image.new('RGB', (size1[0]+size2[0]+size3[0], size1[1]))
        
        loc1, loc2, loc3 = (0, 0), (size1[0], 0),(size1[0]+size2[0], 0)
        
        joint.paste(img1, loc1)
        joint.paste(img2, loc2)
        joint.paste(img3, loc3)
        joint.save(name)
    #定义循环列表
    
    
    ls=[311,411]
    
    
    ## 图片拼接
    if __name__ == '__main__':
        for j in ls:
        
            for i in range(1,43):
                png1 = "D:\\碳交易试点评估\\sectoral_approach_deflator\\sectoral_approach"+str(j)+"-deflator\\output\\Guangdong\\Figure"+str(i)+".png"
    
                png3 = "D:\\碳交易试点评估\\sectoral_approach_deflator\\sectoral_approach"+str(j)+"-deflator\\output\\Hubei\\Figure"+str(i)+".png"
    
    
                png2 ="D:\\碳交易试点评估\\sectoral_approach_deflator\\sectoral_approach"+str(j)+"-deflator\\output\\Chongqing\\Figure"+str(i)+".png"
    
                os.chdir("D:\碳交易试点评估\\sectoral_approach_deflator\\sectoral_approach"+str(j)+"-deflator\\output")
    
                name = "map"+str(i)+".png"
                join(png1, png2, png3, name)       
     
    
    

    相关文章

      网友评论

        本文标题:Stata&Python--PIL库多个图片拼接

        本文链接:https://www.haomeiwen.com/subject/vjckdhtx.html