Commit 9007704c4b

9007704c4b298a00b971e2ab80fdc404d8570edc

parent: 7b6cf3f194

Unsigned

cmc <hello@cleberg.net> · 2024-10-28 01:46 UTC

comply with pylint

Layout: unified · split

.gitignore +1
@@ -3,3 +3,4 @@
33.vscode
44public
55readme.html
6venv
utils/salary_visualization.py +20 −17
@@ -1,8 +1,10 @@
1%pip install plotly pandas
1"""
2A file that will visualize salary data from an incoming CSV.
3"""
24
5import locale
36import pandas as pd
47import plotly.graph_objs as go
5import locale
68
79locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
810
@@ -10,6 +12,9 @@ df = pd.read_csv('~/git/cleberg.net/static/salary.csv')
1012
1113# Function to format salary as US currency
1214def format_currency(value):
15 """
16 Format values in USD currency format.
17 """
1318 return f"${value:,.2f}"
1419
1520# Reverse the order of the DataFrame
@@ -23,7 +28,7 @@ fig = go.Figure()
2328
2429# Adding each data point as a separate trace to display the text
2530for index, row in df.iterrows():
26 title_company = f"{row['Title']} ({row['Company']})"
31 TITLE_COMPANY = f"{row['Title']} ({row['Company']})"
2732 salary_formatted = format_currency(row['Salary'])
2833 if pd.notna(row['Percentage Increase']):
2934 text = f"{salary_formatted} ({row['Percentage Increase']:.2f}%)"
@@ -34,27 +39,25 @@ for index, row in df.iterrows():
3439 y=[row['Salary'], row['Salary']],
3540 text=[text],
3641 mode='lines+text',
37 name=title_company, # Combine title and company for legend
42 name=TITLE_COMPANY,
3843 textposition='top center'
3944 ))
4045
46# Update visual styles of the figure
4147fig.update_layout(
4248 title="Salary Data Over Time (annualized)",
4349 xaxis_title="Time",
4450 yaxis_title="Salary",
45 font=dict(
46 family="monospace",
47 size=16
48 ),
49 margin=dict(l=50, r=50, t=50, b=100), # Adjust bottom margin for legend space
50 legend=dict(
51 orientation="h", # Horizontal orientation
52 yanchor="top", # Anchor to the top of the legend box
53 y=-0.3, # Position below the graph
54 xanchor="center", # Center the legend horizontally
55 x=0.5 # Center the legend
56 ),
57 height=800 # Increase vertical size
51 font={"family": 'monospace', "size": 16},
52 margin={"l": 50, "r": 50, "t": 50, "b": 100},
53 legend={
54 "orientation": 'h',
55 "yanchor": 'top',
56 "y": -0.3,
57 "xanchor": 'center',
58 "x": 0.5
59 },
60 height=800
5861)
5962
6063fig.show()