Skip to content

Commit

Permalink
Update: some plots with change in blogpost
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliph committed Mar 6, 2019
1 parent c9eb7b4 commit e51fe84
Show file tree
Hide file tree
Showing 4 changed files with 390 additions and 368 deletions.
43 changes: 31 additions & 12 deletions analysis/2018/0. Imports and functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -60,10 +60,15 @@
"import sys\n",
"from pathlib import Path\n",
"sys.path.append(str(Path('.').absolute().parent))\n",
"\n",
"from include.likertScalePlot import likert_scale\n",
"from include.textCleaning import plot_wordcloud as wordcloud\n",
"from include.textCleaning import wrap_clean_text"
"try:\n",
" from include.likertScalePlot import likert_scale\n",
" from include.textCleaning import plot_wordcloud as wordcloud\n",
" from include.textCleaning import wrap_clean_text\n",
"except ModuleNotFoundError:\n",
" sys.path.append(\"../..\")\n",
" from include.likertScalePlot import likert_scale\n",
" from include.textCleaning import plot_wordcloud as wordcloud\n",
" from include.textCleaning import wrap_clean_text"
]
},
{
Expand Down Expand Up @@ -760,11 +765,11 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"def radar_plotting(df, title='', subplot=False, percentage=True, fixed_y=False):\n",
"def radar_plotting(df, title='', subplot=False, percentage=True, fixed_y=False, color=None):\n",
" \"\"\"\n",
" Plotting a radar based on the df.\n",
" The df need to have the group in the index\n",
Expand All @@ -780,6 +785,7 @@
" plot(): of the data\n",
" \"\"\"\n",
" def _draw_plot(df, label, fixed_y, ax=None, color=None):\n",
"\n",
" # number of variable\n",
" categories = list(df)\n",
" N = len(categories)\n",
Expand Down Expand Up @@ -808,15 +814,23 @@
" plt.ylim(0, 100)\n",
" else:\n",
" plt.ylim(0, int(df.max().max())+5)\n",
" ax.tick_params(axis='x', colors='grey')\n",
" ax.spines['polar'].set_visible(False) \n",
" #ax.tick_params(axis='y', colors='grey')\n",
" #ax.yaxis.grid(False,color='grey',linestyle='-')\n",
" #plt.ylim(0,100)\n",
" # ------- PART 2: Add plots\n",
" # Plot each individual = each line of the data\n",
" for i in range(len(df)):\n",
" values=df.iloc[i,:].values.flatten().tolist()\n",
" values += values[:1]\n",
" if color:\n",
" ax.plot(angles, values, color=color, linewidth=1, linestyle='solid', label=df.index[i])\n",
" ax.fill(angles, values,color=color, alpha=1/(len(df)+2))\n",
" if isinstance(color, list):\n",
" color_ = color[i]\n",
" else:\n",
" color_ = color\n",
" ax.plot(angles, values, c=color_, linewidth=1, linestyle='solid', label=df.index[i])\n",
" ax.fill(angles, values, c=color_, alpha=1/(len(df)+2))\n",
" else:\n",
" ax.plot(angles, values, linewidth=1, linestyle='solid', label=df.index[i])\n",
" ax.fill(angles, values, alpha=1/(len(df)+2))\n",
Expand All @@ -829,18 +843,23 @@
" else:\n",
" position_title = 1.1\n",
" \n",
" if color:\n",
" if color and not isinstance(color, list):\n",
" plt.title(label, size=14, color=color, y=position_title)\n",
" else:\n",
" plt.title(label, size=14, y=position_title)\n",
" plt.title(label, size=14, color='grey', y=position_title)\n",
" return ax\n",
" \n",
" # Initialise the spider plot\n",
" plt.figure()\n",
" # Create a color palette:\n",
" if subplot is False:\n",
" #fig, ax = plt.subplots(1, nbr_plots, sharey=True, polar=True)\n",
" plot = _draw_plot(df=df, label=title, fixed_y=fixed_y)\n",
" if color:\n",
" color_ = [matplotlib.colors.to_rgba(x, alpha=None) for x in color]\n",
" #color_ = [matplotlib.colors.to_rgb(x) for x in color]\n",
" \n",
" plot = _draw_plot(df=df, label=title, fixed_y=fixed_y, color=color_)\n",
" \n",
" else:\n",
" nbr_plots = len(df.index)\n",
" my_palette = plt.cm.get_cmap(\"Set2\", len(df.index))\n",
Expand Down
103 changes: 53 additions & 50 deletions analysis/2018/1. Overview and sampling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@
"outputs": [],
"source": [
"# Loading dataset\n",
"df = pd.read_csv('./data/clean_merged.csv')"
"try:\n",
" df = pd.read_csv('./data/clean_merged.csv')\n",
"except FileNotFoundError:\n",
" df = pd.read_csv('./../data/clean_merged.csv')"
]
},
{
Expand Down Expand Up @@ -271,83 +274,83 @@
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Belgium</th>\n",
" <th>Denmark</th>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Brazil</th>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Denmark</th>\n",
" <th>Belgium</th>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Botswana</th>\n",
" <th>Sweden</th>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Switzerland</th>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sweden</th>\n",
" <th>Ireland</th>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Ireland</th>\n",
" <th>Botswana</th>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Malawi</th>\n",
" <th>Turkey</th>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Japan</th>\n",
" <th>Benin</th>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Russian Federation</th>\n",
" <th>Poland</th>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Greece</th>\n",
" <th>Malawi</th>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Portugal</th>\n",
" <th>Nigeria</th>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>India</th>\n",
" <th>Greece</th>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Benin</th>\n",
" <th>Japan</th>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Turkey</th>\n",
" <th>Mauritius</th>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Saudi Arabia</th>\n",
" <th>Ethiopia</th>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Poland</th>\n",
" <th>Russian Federation</th>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Nigeria</th>\n",
" <th>India</th>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Ethiopia</th>\n",
" <th>Portugal</th>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Mauritius</th>\n",
" <th>Saudi Arabia</th>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
Expand All @@ -368,26 +371,26 @@
"France 5\n",
"Spain 4\n",
"Italy 4\n",
"Belgium 3\n",
"Brazil 3\n",
"Denmark 3\n",
"Botswana 2\n",
"Switzerland 2\n",
"Brazil 3\n",
"Belgium 3\n",
"Sweden 2\n",
"Switzerland 2\n",
"Ireland 2\n",
"Malawi 1\n",
"Japan 1\n",
"Russian Federation 1\n",
"Greece 1\n",
"Portugal 1\n",
"India 1\n",
"Benin 1\n",
"Botswana 2\n",
"Turkey 1\n",
"Saudi Arabia 1\n",
"Benin 1\n",
"Poland 1\n",
"Malawi 1\n",
"Nigeria 1\n",
"Greece 1\n",
"Japan 1\n",
"Mauritius 1\n",
"Ethiopia 1\n",
"Mauritius 1"
"Russian Federation 1\n",
"India 1\n",
"Portugal 1\n",
"Saudi Arabia 1"
]
},
"execution_count": 7,
Expand Down Expand Up @@ -739,7 +742,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 17,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -773,48 +776,48 @@
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">2017</th>\n",
" <th>No</th>\n",
" <td>14</td>\n",
" <td>27</td>\n",
" <td>149</td>\n",
" <td>NaN</td>\n",
" <td>13</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Yes</th>\n",
" <td>814</td>\n",
" <td>176</td>\n",
" <td>828.0</td>\n",
" <td>828</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">2018</th>\n",
" <th>No</th>\n",
" <td>39</td>\n",
" <td>40</td>\n",
" <td>787</td>\n",
" <td>NaN</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Yes</th>\n",
" <td>945</td>\n",
" <td>166</td>\n",
" <td>984.0</td>\n",
" <td>984</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Write software Lead a team of software developers \\\n",
"2017 No 14 149 \n",
"2017 No 27 149 \n",
" Yes 814 176 \n",
"2018 No 39 787 \n",
"2018 No 40 787 \n",
" Yes 945 166 \n",
"\n",
" At least one of the two \n",
"2017 No NaN \n",
" Yes 828.0 \n",
"2018 No NaN \n",
" Yes 984.0 "
"2017 No 13 \n",
" Yes 828 \n",
"2018 No 1 \n",
" Yes 984 "
]
},
"execution_count": 27,
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -830,7 +833,7 @@
"soft_any = df.groupby(['Year'])['any_rse'].value_counts().to_frame()\n",
"# Create one df\n",
"result = pd.concat([soft_dev, soft_lead, soft_any], axis=1, sort=False)\n",
"\n",
"1\n",
"# Rename columns\n",
"result.columns = ['Write software', 'Lead a team of software developers', 'At least one of the two']\n",
"result"
Expand All @@ -845,7 +848,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -864,7 +867,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 20,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -907,7 +910,7 @@
"0 828 984"
]
},
"execution_count": 29,
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
Expand Down
Loading

0 comments on commit e51fe84

Please sign in to comment.