Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Low efficiency when plotting a large amount of contours on a single axis in python with matplotlib

$
0
0

The objective of my code is to plot soil pressure from data extracted from another software. The output of this other software gives me the value of this pressure for each of the joints of a shell that must be interpolated to present the pressure throughout this shell. As each shell can have different shapes and the set of shells can have concavities and openings in the geometry, I am plotting the stress for each of the shells separately on the axis.

The problem is that as the number of shells increases, the plotting time increases exponentially, so that plotting 10 images with 100 shells each is faster than plotting an image with 1000 shells. An image with 4000 shells, for example, takes tens of minutes and as I will need to plot several images this execution time is impractical for daily use.

I would like to know if it is possible to speed up this plotting process. If my approach to the problem is not the best, I also accept suggestions.

Below is the portion of the code that does what I described above:

# Plotagem da tensão no solo no gráfico        fig, ax = plt.subplots()        levels = np.linspace(tensaoInf, tensaoSup, num=14).tolist()        levels = [num * fator for num in levels]        norm = mpl.colors.BoundaryNorm(levels, coresSAP.N, extend='both')        print('  Desenhando a imagem...')        comp = len(shellgroup.id_shells)        i = 0        for shell in shellgroup.id_shells:            i += 1            print(f'  Concluído {round(i * 100/comp, 1)}%', end='\r')            plotx = []            ploty = []            plotz = []            for joint in shellgroup.lista_joints[shell]:                plotx.append(pontos_x[joint])                ploty.append(pontos_y[joint])                plotz.append(dicTensaoJoint[joint] * fator)            xpt = np.array(plotx)            ypt = np.array(ploty)            zpt = np.array(plotz)            linhas = ax.tricontour(xpt, ypt, zpt, levels=levels, colors='k', linewidths=esp_linha, linestyles='dashed')            colorido = ax.tricontourf(xpt, ypt, zpt, levels=levels, norm=norm, cmap=coresSAP, extend='both')            # ax.plot(xpt, ypt, 'ko', ms=2)            pontos = np.array([(plotx[i], ploty[i]) for i in range(len(plotx))])            hull = ConvexHull(pontos)            for simplex in hull.simplices:                ax.plot(pontos[simplex, 0], pontos[simplex, 1], 'k-', linewidth=esp_linha)        # Desenho da escala de cores        fig.colorbar(mpl.cm.ScalarMappable(norm=norm, cmap=coresSAP),                     ax=ax, orientation='vertical', extendrect=True,                     ticks=levels, extendfrac='auto', label=textoEscala,                     fraction=fracao, pad=0.04, format="{x:.2f}")        if not os.path.exists("./FigurasPySAP"):            os.makedirs("./FigurasPySAP")        fig.savefig(f"./FigurasPySAP/tensao-{grupo}-{combsolo}.png", dpi=400, bbox_inches='tight')

And an example of the type of image I'm generating


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>