21.12.2022 Views

python_para_desenvolvedores_2ed

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

206 Processamento numérico

# Desenha barras

# Eixo X: arange(len(dif)) + .5

# Eixo Y: dif

# Largura das barras: .5

# Cor: #ccbbaa

bar(arange(len(dif)) + .5, dif, .5, color='#ccbbaa')

# Salva a figura

savefig('graf.png')

Saída:

O pacote tem funções para gerar gráficos de barra, linha, dispersão, pizza e

polar, entre outros.

Exemplo usando matplotlib:

# -*- coding: latin1 -*-

import os

import matplotlib

from matplotlib.figure import Figure

from matplotlib.backends.backend_agg import FigureCanvasAgg

def pie(filename, labels, values):

"""

Gera um diagrama de Pizza e salva em arquivo.

"""

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!