From 6c6a02dbd208ea180c1aa2d5cf7c51d5d36fa8ba Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Sun, 27 Oct 2024 20:46:22 -0500 Subject: comply with pylint --- utils/salary_visualization.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'utils') diff --git a/utils/salary_visualization.py b/utils/salary_visualization.py index 99b29fc..311e3c2 100644 --- a/utils/salary_visualization.py +++ b/utils/salary_visualization.py @@ -1,8 +1,10 @@ -%pip install plotly pandas +""" +A file that will visualize salary data from an incoming CSV. +""" +import locale import pandas as pd import plotly.graph_objs as go -import locale locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') @@ -10,6 +12,9 @@ df = pd.read_csv('~/git/cleberg.net/static/salary.csv') # Function to format salary as US currency def format_currency(value): + """ + Format values in USD currency format. + """ return f"${value:,.2f}" # Reverse the order of the DataFrame @@ -23,7 +28,7 @@ fig = go.Figure() # Adding each data point as a separate trace to display the text for index, row in df.iterrows(): - title_company = f"{row['Title']} ({row['Company']})" + TITLE_COMPANY = f"{row['Title']} ({row['Company']})" salary_formatted = format_currency(row['Salary']) if pd.notna(row['Percentage Increase']): text = f"{salary_formatted} ({row['Percentage Increase']:.2f}%)" @@ -34,27 +39,25 @@ for index, row in df.iterrows(): y=[row['Salary'], row['Salary']], text=[text], mode='lines+text', - name=title_company, # Combine title and company for legend + name=TITLE_COMPANY, textposition='top center' )) +# Update visual styles of the figure fig.update_layout( title="Salary Data Over Time (annualized)", xaxis_title="Time", yaxis_title="Salary", - font=dict( - family="monospace", - size=16 - ), - margin=dict(l=50, r=50, t=50, b=100), # Adjust bottom margin for legend space - legend=dict( - orientation="h", # Horizontal orientation - yanchor="top", # Anchor to the top of the legend box - y=-0.3, # Position below the graph - xanchor="center", # Center the legend horizontally - x=0.5 # Center the legend - ), - height=800 # Increase vertical size + font={"family": 'monospace', "size": 16}, + margin={"l": 50, "r": 50, "t": 50, "b": 100}, + legend={ + "orientation": 'h', + "yanchor": 'top', + "y": -0.3, + "xanchor": 'center', + "x": 0.5 + }, + height=800 ) fig.show() -- cgit v1.2.3-70-g09d2