Spaces:
Runtime error
Runtime error
Commit
·
58b074e
1
Parent(s):
e6f4341
add the get_commits_per_region function
Browse files- utils/plot.py +44 -2
utils/plot.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
| 1 |
__copyright__ = "Copyright (C) 2023 Ali Mustapha"
|
| 2 |
__license__ = "GPL-3.0-or-later"
|
| 3 |
|
| 4 |
-
import
|
|
|
|
| 5 |
from plotly.subplots import make_subplots
|
|
|
|
| 6 |
|
| 7 |
def get_commits_per_gender(gender_counts):
|
| 8 |
gender_counts=gender_counts[gender_counts["Predicted_Gender"]!="Unknown"]
|
|
@@ -38,4 +40,44 @@ def get_gender_percentage(df):
|
|
| 38 |
counts = df['Predicted_Gender'].value_counts()
|
| 39 |
colors = ["blue", "pink", "gray"]
|
| 40 |
Gender_Percentage_plot = go.Figure(data=[go.Pie(labels=df['Predicted_Gender'].unique(), values=counts, marker=dict(colors=colors))])
|
| 41 |
-
return Gender_Percentage_plot
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
__copyright__ = "Copyright (C) 2023 Ali Mustapha"
|
| 2 |
__license__ = "GPL-3.0-or-later"
|
| 3 |
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import plotly.express as px
|
| 6 |
from plotly.subplots import make_subplots
|
| 7 |
+
import plotly.graph_objects as go
|
| 8 |
|
| 9 |
def get_commits_per_gender(gender_counts):
|
| 10 |
gender_counts=gender_counts[gender_counts["Predicted_Gender"]!="Unknown"]
|
|
|
|
| 40 |
counts = df['Predicted_Gender'].value_counts()
|
| 41 |
colors = ["blue", "pink", "gray"]
|
| 42 |
Gender_Percentage_plot = go.Figure(data=[go.Pie(labels=df['Predicted_Gender'].unique(), values=counts, marker=dict(colors=colors))])
|
| 43 |
+
return Gender_Percentage_plot
|
| 44 |
+
|
| 45 |
+
def get_commits_per_region(df,url):
|
| 46 |
+
Country_to_region=pd.read_csv("utils/CodeToRegion.csv")
|
| 47 |
+
Country_to_region=Country_to_region.rename(columns={"sub-region":"sub-region-prediction"})
|
| 48 |
+
|
| 49 |
+
# Group by Year and sub-region-prediction, then count unique sub-regions
|
| 50 |
+
sub_region_counts = df.groupby(['Year', "sub-region-prediction"])["sub-region-prediction"].count().reset_index(name='Count')
|
| 51 |
+
# Merge the sub_region_counts DataFrame with the Country_to_region DataFrame
|
| 52 |
+
merged_df = sub_region_counts.merge(Country_to_region, on="sub-region-prediction", how="left")
|
| 53 |
+
color_max=df["sub-region-prediction"].value_counts().max()
|
| 54 |
+
# Create a choropleth map using plotly.express
|
| 55 |
+
fig = go.Figure(data=px.choropleth(
|
| 56 |
+
merged_df,
|
| 57 |
+
locations="code3",
|
| 58 |
+
color="Count",
|
| 59 |
+
hover_name="sub-region-prediction",
|
| 60 |
+
# color_continuous_scale=px.colors.qualitative.Set3, # Choose your color scale
|
| 61 |
+
color_continuous_scale="Greens",
|
| 62 |
+
animation_frame="Year",
|
| 63 |
+
title="Counts by Sub-Region"
|
| 64 |
+
))
|
| 65 |
+
|
| 66 |
+
fig.update_layout(
|
| 67 |
+
title_text='Commits Counts by Sub-Region for '+url
|
| 68 |
+
geo=dict(
|
| 69 |
+
showframe=False,
|
| 70 |
+
showcoastlines=False,
|
| 71 |
+
projection_type='equirectangular'
|
| 72 |
+
),
|
| 73 |
+
annotations = [dict(
|
| 74 |
+
x=0.55,
|
| 75 |
+
y=0.1,
|
| 76 |
+
xref='paper',
|
| 77 |
+
yref='paper',
|
| 78 |
+
text='Source: <a href="https://huggingface.co/spaces/AliMustapha/Geo-GenderStudy">\
|
| 79 |
+
Geo-GenderStudy</a>',
|
| 80 |
+
showarrow = False
|
| 81 |
+
)]
|
| 82 |
+
)
|
| 83 |
+
return fig
|