basemap icon indicating copy to clipboard operation
basemap copied to clipboard

Load a region-specific Basemap, then load the shapefile file and save it in svg or svgz format, which is very slow and takes up a lot of space.

Open jiangzhiwei2018 opened this issue 4 years ago • 1 comments

I am using the multiple subplots in one image and loading shapefile files in the subplots, and then saving them in svg or svgz format by plt,savefig("xxx.svg") command is very slow and takes up a lot of disk space. How can I fix it?


    num_samples = 1
    num_frames = 2

    num_cols = num_frames
    num_rows = num_samples
    num_rows_s = 4
    gs = gridspec.GridSpec(num_rows + 1, 1, hspace=0.05,
                           height_ratios=[1] * num_rows + [0.035])

    for s in range(num_samples):
        gs_s = gridspec.GridSpecFromSubplotSpec(num_rows_s, num_cols,
                                                subplot_spec=gs[s, 0],
                                                wspace=0.05, hspace=0.05)
        for col in range(num_cols):
            for row in range(num_rows_s):
                data = np.random.random(size=(64, 64))

                plt.subplot(gs_s[row, col])
                ax = plt.gca()

                bmap = Basemap(llcrnrlon=115.5, urcrnrlon=117.25, llcrnrlat=39.25, urcrnrlat=41.)
                shp_info = bmap.readshapefile(r'F:\LargeDataset\bound_shape\gadm36_CHN_shp\gadm36_CHN_2', 'states',
                                              drawbounds=True)
                bmap.imshow(data)
        plt.savefig("xxx.svg")
        plt.show()

When I increase the number of subgraphs, the rendering of svg format images will become very slow

It may be that I reload a brand new shapefile each time and save the global region in svg format, but I only need a small part of the region

20211117194856

jiangzhiwei2018 avatar Nov 17 '21 12:11 jiangzhiwei2018

First, basemap is end-of-life, so consider cartopy

Second, I assume your shape file is huge, and largely outside your region of interest. You are plotting it 7 times, so your file will be very large. You can probably crop it using a tool like shapely?

jklymak avatar Nov 17 '21 16:11 jklymak