{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyscisci.all as pyscisci\n",
    "\n",
    "import os\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pylab as plt\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "path2mag = '/home/ajgates/MAG'\n",
    "path2wos = '/home/ajgates/WOS'\n",
    "path2dblp = '/home/ajgates/DBLP'\n",
    "path2aps = '/home/ajgates/APS/APS2019'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a1a2fe323fbc43c680e34bef5a8e595a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(HTML(value='Loading Publications'), FloatProgress(value=0.0, max=1.0), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Year</th>\n",
       "      <th>NumPubs</th>\n",
       "      <th>NumJournals</th>\n",
       "      <th>NumAuthors</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1893</td>\n",
       "      <td>20</td>\n",
       "      <td>1</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1894</td>\n",
       "      <td>36</td>\n",
       "      <td>1</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1895</td>\n",
       "      <td>36</td>\n",
       "      <td>1</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1896</td>\n",
       "      <td>36</td>\n",
       "      <td>1</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1897</td>\n",
       "      <td>54</td>\n",
       "      <td>1</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>122</th>\n",
       "      <td>2015</td>\n",
       "      <td>18016</td>\n",
       "      <td>11</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>123</th>\n",
       "      <td>2016</td>\n",
       "      <td>18916</td>\n",
       "      <td>12</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <td>2017</td>\n",
       "      <td>19531</td>\n",
       "      <td>13</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>125</th>\n",
       "      <td>2018</td>\n",
       "      <td>19977</td>\n",
       "      <td>13</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>126</th>\n",
       "      <td>2019</td>\n",
       "      <td>20328</td>\n",
       "      <td>14</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>127 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     Year  NumPubs  NumJournals NumAuthors\n",
       "0    1893       20            1       None\n",
       "1    1894       36            1       None\n",
       "2    1895       36            1       None\n",
       "3    1896       36            1       None\n",
       "4    1897       54            1       None\n",
       "..    ...      ...          ...        ...\n",
       "122  2015    18016           11       None\n",
       "123  2016    18916           12       None\n",
       "124  2017    19531           13       None\n",
       "125  2018    19977           13       None\n",
       "126  2019    20328           14       None\n",
       "\n",
       "[127 rows x 4 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "myaps = pyscisci.APS(path2aps)\n",
    "apspubs = myaps.load_publications(columns=['PublicationId', 'Year', 'JournalId'])\n",
    "\n",
    "npubs_aps = apspubs.groupby('Year')['PublicationId'].nunique().to_frame().reset_index()\n",
    "njournals_aps = apspubs.groupby('Year')['JournalId'].nunique().to_frame().reset_index()\n",
    "aps_values = npubs_aps.merge(njournals_aps, on='Year', how='left')\n",
    "aps_values['AuthorId'] = None\n",
    "aps_values = aps_values.rename(columns={'PublicationId':'NumPubs', 'JournalId':'NumJournals', 'AuthorId':'NumAuthors'})\n",
    "aps_values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "387ce872539447c5879741bf86a1810c",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(HTML(value='Loading Publications'), FloatProgress(value=0.0, max=6.0), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Year</th>\n",
       "      <th>NumPubs</th>\n",
       "      <th>NumJournals</th>\n",
       "      <th>NumAuthors</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1918</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1936</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1937</td>\n",
       "      <td>15</td>\n",
       "      <td>1</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1938</td>\n",
       "      <td>11</td>\n",
       "      <td>2</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>2017</td>\n",
       "      <td>325290</td>\n",
       "      <td>1447</td>\n",
       "      <td>558911.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>2018</td>\n",
       "      <td>355119</td>\n",
       "      <td>1422</td>\n",
       "      <td>613877.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>2019</td>\n",
       "      <td>383863</td>\n",
       "      <td>1379</td>\n",
       "      <td>674824.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>2020</td>\n",
       "      <td>107064</td>\n",
       "      <td>1105</td>\n",
       "      <td>269986.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>2021</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>14.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>88 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    Year  NumPubs  NumJournals  NumAuthors\n",
       "0      0        3            1         NaN\n",
       "1   1918        1            1         1.0\n",
       "2   1936       12            1         8.0\n",
       "3   1937       15            1        12.0\n",
       "4   1938       11            2        10.0\n",
       "..   ...      ...          ...         ...\n",
       "83  2017   325290         1447    558911.0\n",
       "84  2018   355119         1422    613877.0\n",
       "85  2019   383863         1379    674824.0\n",
       "86  2020   107064         1105    269986.0\n",
       "87  2021        6            1        14.0\n",
       "\n",
       "[88 rows x 4 columns]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydblp = pyscisci.DBLP(path2dblp)\n",
    "dblppubs = mydblp.load_publications(columns=['PublicationId', 'Year', 'JournalId'])\n",
    "pub2year = {pid:y for pid, y in dblppubs[['PublicationId', 'Year']].values}\n",
    "\n",
    "npubs_dblp = dblppubs.groupby('Year')['PublicationId'].nunique().to_frame().reset_index()\n",
    "njournals_dblp = dblppubs.groupby('Year')['JournalId'].nunique().to_frame().reset_index()\n",
    "\n",
    "\n",
    "dblpauthors = mydblp.load_publicationauthor(columns=['PublicationId', 'AuthorId'],\n",
    "                                                      duplicate_subset=['PublicationId', 'AuthorId'])\n",
    "#pub2year = mydblp.pub2year\n",
    "dblpauthors['Year'] = [pub2year.get(pid, None) for pid in dblpauthors['PublicationId'].values]\n",
    "dblpauthors.dropna(inplace=True)\n",
    "\n",
    "nauthors_dblp = dblpauthors.groupby('Year')['AuthorId'].nunique().to_frame().reset_index()\n",
    "\n",
    "dblp_values = npubs_dblp.merge(njournals_dblp, how='left', on='Year')\n",
    "dblp_values = dblp_values.merge(nauthors_dblp, how='left', on='Year')\n",
    "dblp_values = dblp_values.rename(columns={'PublicationId':'NumPubs', 'JournalId':'NumJournals', 'AuthorId':'NumAuthors'})\n",
    "dblp_values\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "619afe504e594222be0a1e79e889b6ae",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(HTML(value='Loading Publications'), FloatProgress(value=0.0, max=47.0), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "mymag = pyscisci.MAG(path2mag)\n",
    "magpubs = mymag.load_publications(columns=['PublicationId', 'Year', 'JournalId'])\n",
    "pub2year = {pid:y for pid, y in magpubs[['PublicationId', 'Year']].values}\n",
    "\n",
    "npubs_mag = magpubs.groupby('Year')['PublicationId'].nunique()\n",
    "njournals_mag = magpubs.groupby('Year')['JournalId'].nunique()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1463d4924cc04272bebce39859ba8bca",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(HTML(value='Loading Publication Author Affiliation'), FloatProgress(value=0.0, max=63.0), HTML(…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "magauthors = mymag.load_publicationauthoraffiliation(columns=['PublicationId', 'AuthorId'],\n",
    "                                                      duplicate_subset=['PublicationId', 'AuthorId'])\n",
    "#pub2year = mydblp.pub2year\n",
    "magauthors['Year'] = [pub2year.get(pid, None) for pid in magauthors['PublicationId'].values]\n",
    "magauthors.dropna(inplace=True)\n",
    "\n",
    "nauthors_mag = magauthors.groupby('Year')['AuthorId'].nunique()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Year</th>\n",
       "      <th>NumPubs</th>\n",
       "      <th>NumJournals</th>\n",
       "      <th>NumAuthors</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1800.0</td>\n",
       "      <td>4325</td>\n",
       "      <td>40</td>\n",
       "      <td>5082</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1801.0</td>\n",
       "      <td>1710</td>\n",
       "      <td>5</td>\n",
       "      <td>1550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1802.0</td>\n",
       "      <td>1425</td>\n",
       "      <td>6</td>\n",
       "      <td>1465</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1803.0</td>\n",
       "      <td>1350</td>\n",
       "      <td>5</td>\n",
       "      <td>1380</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1804.0</td>\n",
       "      <td>1315</td>\n",
       "      <td>6</td>\n",
       "      <td>1291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>217</th>\n",
       "      <td>2017.0</td>\n",
       "      <td>10648228</td>\n",
       "      <td>32460</td>\n",
       "      <td>17547373</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>218</th>\n",
       "      <td>2018.0</td>\n",
       "      <td>10747058</td>\n",
       "      <td>30952</td>\n",
       "      <td>17710519</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>219</th>\n",
       "      <td>2019.0</td>\n",
       "      <td>9852890</td>\n",
       "      <td>29306</td>\n",
       "      <td>17512276</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>220</th>\n",
       "      <td>2020.0</td>\n",
       "      <td>1537674</td>\n",
       "      <td>20163</td>\n",
       "      <td>4157285</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>221</th>\n",
       "      <td>2021.0</td>\n",
       "      <td>138</td>\n",
       "      <td>0</td>\n",
       "      <td>191</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>222 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       Year   NumPubs  NumJournals  NumAuthors\n",
       "0    1800.0      4325           40        5082\n",
       "1    1801.0      1710            5        1550\n",
       "2    1802.0      1425            6        1465\n",
       "3    1803.0      1350            5        1380\n",
       "4    1804.0      1315            6        1291\n",
       "..      ...       ...          ...         ...\n",
       "217  2017.0  10648228        32460    17547373\n",
       "218  2018.0  10747058        30952    17710519\n",
       "219  2019.0   9852890        29306    17512276\n",
       "220  2020.0   1537674        20163     4157285\n",
       "221  2021.0       138            0         191\n",
       "\n",
       "[222 rows x 4 columns]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mag_values = npubs_mag.to_frame().reset_index().merge(njournals_mag.to_frame().reset_index(), how='left', on='Year')\n",
    "mag_values = mag_values.merge(nauthors_mag.to_frame().reset_index(), how='left', on='Year')\n",
    "mag_values = mag_values.rename(columns={'PublicationId':'NumPubs', 'JournalId':'NumJournals', 'AuthorId':'NumAuthors'})\n",
    "mag_values\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Year</th>\n",
       "      <th>NumPubs</th>\n",
       "      <th>NumJournals</th>\n",
       "      <th>NumAuthors</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1900</td>\n",
       "      <td>14084</td>\n",
       "      <td>121</td>\n",
       "      <td>1284.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1901</td>\n",
       "      <td>15504</td>\n",
       "      <td>132</td>\n",
       "      <td>1451.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1902</td>\n",
       "      <td>15732</td>\n",
       "      <td>128</td>\n",
       "      <td>1617.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1903</td>\n",
       "      <td>14115</td>\n",
       "      <td>130</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1904</td>\n",
       "      <td>16569</td>\n",
       "      <td>140</td>\n",
       "      <td>2086.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>113</th>\n",
       "      <td>2013</td>\n",
       "      <td>1451882</td>\n",
       "      <td>11429</td>\n",
       "      <td>733289.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114</th>\n",
       "      <td>2014</td>\n",
       "      <td>1495926</td>\n",
       "      <td>11515</td>\n",
       "      <td>604670.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>2015</td>\n",
       "      <td>1533249</td>\n",
       "      <td>12076</td>\n",
       "      <td>601227.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>2016</td>\n",
       "      <td>1499412</td>\n",
       "      <td>11707</td>\n",
       "      <td>92730.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>117</th>\n",
       "      <td>2017</td>\n",
       "      <td>145</td>\n",
       "      <td>5</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>118 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     Year  NumPubs  NumJournals  NumAuthors\n",
       "0    1900    14084          121      1284.0\n",
       "1    1901    15504          132      1451.0\n",
       "2    1902    15732          128      1617.0\n",
       "3    1903    14115          130      1852.0\n",
       "4    1904    16569          140      2086.0\n",
       "..    ...      ...          ...         ...\n",
       "113  2013  1451882        11429    733289.0\n",
       "114  2014  1495926        11515    604670.0\n",
       "115  2015  1533249        12076    601227.0\n",
       "116  2016  1499412        11707     92730.0\n",
       "117  2017      145            5         NaN\n",
       "\n",
       "[118 rows x 4 columns]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "if False:\n",
    "    mywos = pyscisci.WOS(path2wos)\n",
    "    magpubs = mywos.load_publications(columns=['PublicationId', 'Year', 'JournalId'])\n",
    "    pub2year = {pid:y for pid, y in magpubs[['PublicationId', 'Year']].values}\n",
    "\n",
    "    npubs_wos = magpubs.groupby('Year')['PublicationId'].nunique()\n",
    "    njournals_wos = magpubs.groupby('Year')['JournalId'].nunique()\n",
    "    \n",
    "    wosauthors = mywos.load_publicationauthoraffiliation(columns=['PublicationId', 'AuthorId'],\n",
    "                                                      duplicate_subset=['PublicationId', 'AuthorId'])\n",
    "\n",
    "    wosauthors['Year'] = [pub2year.get(pid, None) for pid in wosauthors['PublicationId'].values]\n",
    "    wosauthors.dropna(inplace=True)\n",
    "\n",
    "    nauthors_wos = wosauthors.groupby('Year')['AuthorId'].nunique()\n",
    "\n",
    "wos_values = pd.read_hdf('/Users/ajgates/Documents/WOSyearlysize.hdf')\n",
    "wos_values = wos_values.rename(columns={'PubYear':'Year'})\n",
    "wos_values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 80748 characters]\n",
      "text/plain": [
       "<Figure size 432x864 with 3 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "dblp_color = '#7A82AB'\n",
    "aps_color = '#DBAD6A'\n",
    "mag_color = '#12664F'\n",
    "wos_color = '#2DC2BD'\n",
    "sns.set_style('whitegrid')\n",
    "dflabels = ['APS', 'DBLP', 'MAG', 'WOS']\n",
    "dfcolors = [aps_color, dblp_color, mag_color, wos_color]\n",
    "dfs = [aps_values, dblp_values, mag_values, wos_values]\n",
    "\n",
    "vmax = 2017\n",
    "\n",
    "fig, ax = plt.subplots(3, 1, figsize=(6, 12))\n",
    "\n",
    "for idf in range(4):\n",
    "    idy = np.logical_and(dfs[idf]['Year'].values > 1000, dfs[idf]['Year'].values < vmax)\n",
    "    for iax,v in enumerate(['NumPubs', 'NumJournals', 'NumAuthors']):\n",
    "        ax[iax].plot(dfs[idf]['Year'].values[idy], dfs[idf][v].values[idy], lw=3, \n",
    "               color=dfcolors[idf], label=dflabels[idf])\n",
    "    #ax[1].plot(njournals_dblp.index.values[years], njournals_dblp.values[years], lw=2, color=dblp_color)\n",
    "    #ax[2].plot(nauthors_dblp.index.values[years], nauthors_dblp.values[years], lw=2, color=dblp_color)\n",
    "\n",
    "ax[0].set_ylabel('Number of publications')\n",
    "ax[1].set_ylabel('Number of journals')\n",
    "ax[2].set_ylabel('Number of authors')\n",
    "\n",
    "ax[0].text(x=1805, y=10**7, s='A)', fontsize=20, va = 'top')\n",
    "ax[1].text(x=1805, y=0.3*10**5, s='B)', fontsize=20, va = 'top')\n",
    "ax[2].text(x=1805, y=10**7, s='C)', fontsize=20, va = 'top')\n",
    "\n",
    "handles, labels = ax[0].get_legend_handles_labels()\n",
    "ax[0].legend(handles, labels, loc='lower left')\n",
    "\n",
    "for iax in range(3):\n",
    "    ax[iax].set_yscale('log')\n",
    "    \n",
    "    ax[iax].set_xlim([1800, 2020])\n",
    "\n",
    "for iax in [0,2]:\n",
    "    ax[iax].set_yticks([10**0, 10**2, 10**4, 10**6])\n",
    "\n",
    "plt.savefig('DatabaseGrowth.pdf')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
