Last active
September 5, 2018 20:55
-
-
Save fcunhaneto/c0253cf8152e19e8db254f7dc0dd48ae to your computer and use it in GitHub Desktop.
Criando um diagrama de barras para os totais de cada idade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import matplotlib.pyplot as plt | |
df = pd.read_csv('/home/francisco/Projects/Pycharm/' | |
'matplot-pandas-tutorial/files/questionario.csv') | |
""" | |
Criando um diagrama de barras para os totais de cada idade | |
""" | |
idade = df['Idade'] | |
idade_sum = idade.value_counts() | |
idade_sum = idade_sum.sort_index() | |
x = idade_sum.index | |
y = idade_sum | |
plt.figure(figsize=(8, 6)) | |
""" | |
sobre a função bar(*args, **kwargs) | |
Parameters: | |
x: As coordenadas x das barras | |
y: A altura (s) das barras | |
Mais em: | |
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.bar.html | |
""" | |
plt.bar(x, y) | |
plt.title('Distribuição de Idades') | |
plt.xlabel('Idade') | |
plt.ylabel('Alunos') | |
plt.xticks(x) # obriga a mostrar todos os números no eixo x | |
plt.savefig('imagens/idades-diagrama-barras.png') | |
plt.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment