{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# visualize by World 🌎 locations for each bird🦜\n\nThis is inpired by **The easiest way to plot data from Pandas on a world map**\n\nhttps://towardsdatascience.com/the-easiest-way-to-plot-data-from-pandas-on-a-world-map-1a62962a27f3","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"code","source":"!pip install -q GeoPandas\n!ls -l /kaggle/input/birdclef-2022\n\nPATH_DATASET = \"/kaggle/input/birdclef-2022\"","metadata":{"execution":{"iopub.status.busy":"2022-02-16T21:29:57.351472Z","iopub.execute_input":"2022-02-16T21:29:57.352557Z","iopub.status.idle":"2022-02-16T21:29:58.171658Z","shell.execute_reply.started":"2022-02-16T21:29:57.352512Z","shell.execute_reply":"2022-02-16T21:29:58.170519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport pandas as pd\n\ntrain_meta = pd.read_csv(os.path.join(PATH_DATASET, \"train_metadata.csv\"))\ndisplay(train_meta.head(3))","metadata":{"execution":{"iopub.status.busy":"2022-02-16T21:29:59.137703Z","iopub.execute_input":"2022-02-16T21:29:59.138030Z","iopub.status.idle":"2022-02-16T21:29:59.296977Z","shell.execute_reply.started":"2022-02-16T21:29:59.137996Z","shell.execute_reply":"2022-02-16T21:29:59.295568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport matplotlib.pyplot as plt\nimport geopandas as gpd\n\n# initialize an axis\nfig, ax = plt.subplots(figsize=(24,18))\n# plot map on axis\ncountries = gpd.read_file(gpd.datasets.get_path(\"naturalearth_lowres\"))\ncountries.plot(color=\"lightgrey\", ax=ax)\n\n# plot points\ncmap = plt.cm.get_cmap('jet')\nbirds = len(train_meta[\"primary_label\"].unique())\nfor i, (bird, dfg) in enumerate(train_meta.groupby(\"primary_label\")):\n    dfg.longitude = np.around(dfg.longitude, 1)\n    dfg.latitude = np.around(dfg.latitude, 1)\n    dfgg = dfg.groupby([\"longitude\", \"latitude\"]).size().reset_index(name=\"counts\")\n    dfgg.plot(x=\"longitude\", y=\"latitude\", kind=\"scatter\", c=cmap(float(i) / birds), s=dfgg[\"counts\"] * 5, ax=ax, label=bird, alpha=0.5)\n\nax.legend(loc='upper center', bbox_to_anchor=(0.5, 1.25), ncol=15, fancybox=True, shadow=True)\n\n# get axes limits\nx_lo, x_up = ax.get_xlim()\ny_lo, y_up = ax.get_ylim()\n# add minor ticks with a specified sapcing (deg)\ndeg = 5\n# add grid\nax.set_xticks(np.arange(np.ceil(x_lo), np.ceil(x_up), deg), minor=True)\nax.set_yticks(np.arange(np.ceil(y_lo), np.ceil(y_up), deg), minor=True)\nax.grid(b=True, which=\"minor\", alpha=0.25)","metadata":{"execution":{"iopub.status.busy":"2022-02-16T22:05:11.243357Z","iopub.execute_input":"2022-02-16T22:05:11.243663Z","iopub.status.idle":"2022-02-16T22:05:26.377566Z","shell.execute_reply.started":"2022-02-16T22:05:11.243625Z","shell.execute_reply":"2022-02-16T22:05:26.376558Z"},"trusted":true},"execution_count":null,"outputs":[]}]}