Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
fellipaocastro committed May 19, 2024
1 parent 7041966 commit e01679d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
21 changes: 12 additions & 9 deletions carreira/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime
import math
from os import path

import matplotlib.pyplot as plt
Expand All @@ -14,16 +15,13 @@ def format_date(date: str) -> datetime:

def format_y_axis(y_param: int, _pos: int) -> str:
y_axis = ''

anos = y_param / 365

if anos >= 1:
ano_str = 'anos' if anos >= 2 else 'ano'

y_axis = f'{anos:.1f} {ano_str}'.replace('.', ',')
elif y_param > 0:
meses = int(np.mod(y_param, 365) / 30)

y_axis = f'{meses} meses'

return y_axis
Expand All @@ -39,9 +37,12 @@ def main() -> None:
carreira['entrada'] = carreira['entrada'].apply(format_date)
carreira['saida'] = carreira['saida'].apply(format_date)
carreira['dias'] = (carreira['saida'] - carreira['entrada']).dt.days + 1

carreira['inicio'] = carreira['entrada'].dt.strftime('%m/%Y')

first_entry = carreira['entrada'].min()
last_exit = carreira['saida'].max()
total_years = math.ceil((last_exit - first_entry).days / 365)

bgcolor = '#fbf0d9'

fig, ax = plt.subplots(figsize=(10, 5))
Expand All @@ -50,22 +51,24 @@ def main() -> None:

formatter = ticker.FuncFormatter(format_y_axis)
ax.yaxis.set_major_formatter(formatter)
ax.tick_params(axis='x', labelsize=10)
ax.tick_params(axis='y', labelsize=10)

sns.barplot(data=carreira, x='inicio', y='dias', hue='esfera', palette=sns.color_palette(['#a61c00', '#1c4587']),
ax=ax)

plt.title('Carreira', fontsize=14)
plt.xlabel('Início', fontsize=12)
plt.ylabel('Tempo', fontsize=12)
plt.legend(fontsize=11)
plt.title(f'{total_years} anos de carreira', fontsize=14, weight='bold')
plt.xlabel('início', fontsize=13)
plt.ylabel('tempo', fontsize=13)
plt.legend(fontsize=12)

for container in ax.containers:
for rect in container:
height = rect.get_height()
x_pos = rect.get_x() + rect.get_width() / 2
y_pos = height + 20
text = carreira.iloc[container.index(rect)]['instituicao']
ax.annotate(text, xy=(x_pos, y_pos), ha='center', fontsize=11)
ax.annotate(text, xy=(x_pos, y_pos), ha='center', fontsize=12)

plt.savefig(path.join(script_dir, 'carreira.png'))
plt.show()
Expand Down
26 changes: 14 additions & 12 deletions carreira/carreira.ipynb

Large diffs are not rendered by default.

Binary file modified carreira/carreira.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e01679d

Please sign in to comment.