python 用matplotlib.pyplot 绘制图像,在循环的时候只显示一张图片,如何解决?求大佬帮忙支招!

import shapefile
import geopandas as gpd
from shapely.geometry import shape
from shapely.geometry import box
from shapely.geometry import Polygon
import matplotlib.pyplot as plt

sf = shapefile.Reader('shapefiles/SAL_2021_AUST_GDA2020.shp')

c = 0
with open('wrong_edge_answer.csv',encoding='utf_8_sig') as f:

    while(c < 2):
        for shapeRec in sf.iterShapeRecords():
            flag_1 = False
            flag_2 = False
            if shapeRec.shape.shapeTypeName == None:
                continue
            if shapeRec.record[1] == "Aag":
                si = shapeRec.shape
                g = si.__geo_interface__  ##类型转换
                src_shp = shape(g)    ## shapely.geometry.polygon.Polygon
                x=[]
                y=[]
                for i,j in src_shp.boundary.coords[:]:
                    x.append(i)
                    y.append(j)
                plt.plot(x,y,color="yellow")
                flag_1 = True

            if shapeRec.record[1] == "Wer":
                si = shapeRec.shape
                g = si.__geo_interface__  ##类型转换
                tar_shp = shape(g)    ## shapely.geometry.polygon.Polygon
                n=[]
                m=[]
                for i,j in tar_shp.boundary.coords[:]:
                    n.append(i)
                    m.append(j)
                plt.plot(n,m,color="red")
                flag_2 = True
            if flag_1 == True and flag_2 == True:
                plt.show()
                break
        input()
        c += 1

想实现这样一个功能:while循环,每次等程序plot显示一张图,人为地input一个数字,直到c满足条件就截止。但是运行了之后最后只输出了最后一张图 ,想请大家帮忙看看~

你可能感兴趣的:(python)