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 @@
3.vscode 3.vscode
4public 4public
5readme.html 5readme.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"""
2 4
5import locale
3import pandas as pd 6import pandas as pd
4import plotly.graph_objs as go 7import plotly.graph_objs as go
5import locale
6 8
7locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') 9locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
8 10
@@ -10,6 +12,9 @@ df = pd.read_csv('~/git/cleberg.net/static/salary.csv')
10 12
11# Function to format salary as US currency 13# Function to format salary as US currency
12def format_currency(value): 14def format_currency(value):
15 """
16 Format values in USD currency format.
17 """
13 return f"${value:,.2f}" 18 return f"${value:,.2f}"
14 19
15# Reverse the order of the DataFrame 20# Reverse the order of the DataFrame
@@ -23,7 +28,7 @@ fig = go.Figure()
23 28
24# Adding each data point as a separate trace to display the text 29# Adding each data point as a separate trace to display the text
25for index, row in df.iterrows(): 30for index, row in df.iterrows():
26 title_company = f"{row['Title']} ({row['Company']})" 31 TITLE_COMPANY = f"{row['Title']} ({row['Company']})"
27 salary_formatted = format_currency(row['Salary']) 32 salary_formatted = format_currency(row['Salary'])
28 if pd.notna(row['Percentage Increase']): 33 if pd.notna(row['Percentage Increase']):
29 text = f"{salary_formatted} ({row['Percentage Increase']:.2f}%)" 34 text = f"{salary_formatted} ({row['Percentage Increase']:.2f}%)"
@@ -34,27 +39,25 @@ for index, row in df.iterrows():
34 y=[row['Salary'], row['Salary']], 39 y=[row['Salary'], row['Salary']],
35 text=[text], 40 text=[text],
36 mode='lines+text', 41 mode='lines+text',
37 name=title_company, # Combine title and company for legend 42 name=TITLE_COMPANY,
38 textposition='top center' 43 textposition='top center'
39 )) 44 ))
40 45
46# Update visual styles of the figure
41fig.update_layout( 47fig.update_layout(
42 title="Salary Data Over Time (annualized)", 48 title="Salary Data Over Time (annualized)",
43 xaxis_title="Time", 49 xaxis_title="Time",
44 yaxis_title="Salary", 50 yaxis_title="Salary",
45 font=dict( 51 font={"family": 'monospace', "size": 16},
46 family="monospace", 52 margin={"l": 50, "r": 50, "t": 50, "b": 100},
47 size=16 53 legend={
48 ), 54 "orientation": 'h',
49 margin=dict(l=50, r=50, t=50, b=100), # Adjust bottom margin for legend space 55 "yanchor": 'top',
50 legend=dict( 56 "y": -0.3,
51 orientation="h", # Horizontal orientation 57 "xanchor": 'center',
52 yanchor="top", # Anchor to the top of the legend box 58 "x": 0.5
53 y=-0.3, # Position below the graph 59 },
54 xanchor="center", # Center the legend horizontally 60 height=800
55 x=0.5 # Center the legend
56 ),
57 height=800 # Increase vertical size
58) 61)
59 62
60fig.show() 63fig.show()