Skip to content

Commit

Permalink
Merge pull request #32 from mathause/fix/ex3_1
Browse files Browse the repository at this point in the history
Fix/ex3 1

closes #17 and #19
  • Loading branch information
mathause authored May 25, 2018
2 parents a60faa3 + 9df4c8a commit f51a7de
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 21 deletions.
72 changes: 51 additions & 21 deletions Part3/ex3_1_intro_scatter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"metadata": {},
"outputs": [],
"source": [
"import xarray as xr\n",
"import matplotlib.pyplot as plt\n",
"import xarray as xr\n",
"\n",
"%matplotlib inline"
]
Expand Down Expand Up @@ -83,7 +83,7 @@
"\n",
"To plot a map, we have to specify a `projection` for the axes. We start with the `PlateCarree` projection, which is a [equirectangular projection](https://en.wikipedia.org/wiki/Equirectangular_projection). This projection maps x to be the value of the longitude and y to be the value of the latitude.\n",
"\n",
"This creates a special kind of axes (a `<cartopy.mpl.geoaxes.GeoAxesSubplot>`) which is derived from the normal `axes`. As such it includes some special commands (which we'll get to know), one of them called `ax.coatlines()` which is an easy way to add the coastlines.\n",
"This creates a special kind of axes (a `<cartopy.mpl.geoaxes.GeoAxesSubplot>`) which is derived from the normal `axes`. As such it includes some special commands (which we'll get to know), one of them called `ax.coastlines()` which is an easy way to add the coastlines.\n",
"\n",
"Ok, let's get started:\n"
]
Expand Down Expand Up @@ -287,13 +287,17 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"hide_input": false
},
"source": [
"### Exercise\n",
"\n",
" * Color the points according to their temperature (TEMP)\n",
" * Color the points according to their temperature (`ATL.TEMP` etc.)\n",
" > You will need to remove the `color=` argument.\n",
" * restrict the range of the colormap to 0...25\n",
" * add a colorbar"
" * add a colorbar\n",
" > `colorbar` will require a `mappable`, use `h = ax.scatter`"
]
},
{
Expand Down Expand Up @@ -347,15 +351,46 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The colorbar is to big for the map! However, this is not straight forward to correct... You will learn how to do this later.\n",
"### Note\n",
"\n",
" > The colorbar is to big for the map! However, this is not straightforward to correct... You will learn how to do this later.\n",
"\n",
" > If the range of the colormap is not set to the same values for the three plots, it will be choosen according to the range of the data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ax = plt.axes(projection=ccrs.PlateCarree())\n",
"\n",
"ax.coastlines()\n",
"\n",
"opt = dict(s=15)\n",
"\n",
"h0 = ax.scatter(ATL.lon, ATL.lat, c=ATL.TEMP, **opt)\n",
"h1 = ax.scatter(IND.lon, IND.lat, c=IND.TEMP, **opt)\n",
"h2 = ax.scatter(PAC.lon, PAC.lat, c=PAC.TEMP, **opt)\n",
"\n",
"plt.colorbar(h0)\n",
"plt.colorbar(h1)\n",
"plt.colorbar(h2)\n",
"\n",
"ax.set_global()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Projections\n",
"\n",
"cartopy offers [20ish different projections](http://scitools.org.uk/cartopy/docs/v0.15/crs/projections.html). Have a look at them. Unfortunately some important projections are missing (e.g. Hammer and Aitoff).\n",
"\n",
"### Exercise\n",
" * redo the plot but select a projection from the website."
" * redo the plot but select a different projection from the website."
]
},
{
Expand Down Expand Up @@ -594,15 +629,14 @@
"\n",
"cartopy can make use of many online geographical data sources. See examples under [Web Services](http://scitools.org.uk/cartopy/docs/latest/gallery.html#web-services).\n",
"\n",
"The best thing about this is that you have access and easy ways to plot all the data available at [naturalearthdata.com]\n",
"http://www.naturalearthdata.com/. Naturalearth data provides high quality geo data for free.\n",
"The best thing about this is that you have access and easy ways to plot all the data available at [naturalearthdata.com](http://www.naturalearthdata.com/). Naturalearth data provides high quality geo data for free.\n",
"\n",
"See [naturalearthdata.com/features](http://www.naturalearthdata.com/features/) for all that is available.\n",
"\n",
"For example `ax.coastline()` displays the following data: [110m-coastline](http://www.naturalearthdata.com/downloads/110m-physical-vectors/110m-coastline/).\n",
"\n",
"Note:\n",
"> The data is downloaded and stored the first time you use it."
"> The data is downloaded and stored the first time you use it, so this might take a minute or so."
]
},
{
Expand Down Expand Up @@ -633,13 +667,14 @@
"# adding a slightly textured image of the globe\n",
"ax.stock_img();\n",
"\n",
"# ==========================================\n",
"# NaturalEarthData\n",
"\n",
"# some data is easily accessible\n",
"ax.add_feature(cfeature.BORDERS)\n",
"ax.add_feature(cfeature.LAKES, edgecolor='0.1')\n",
"\n",
"# for some data you need to know the name:\n",
"\n",
"# for some data you need to know the name (e.g. the States of the US and Canada):\n",
"states = cfeature.NaturalEarthFeature('cultural', 'admin_1_states_provinces_lakes', '50m')\n",
"ax.add_feature(states, edgecolor='0.2', facecolor='none', lw=0.5)"
]
Expand Down Expand Up @@ -742,7 +777,9 @@
"metadata": {},
"outputs": [],
"source": [
"ax = plt.axes(projection=ccrs.PlateCarree())\n",
"projection = ccrs.PlateCarree()\n",
"\n",
"ax = plt.axes(projection=projection)\n",
"\n",
"\n",
"ax.plot(ch.lon, ch.lat, transform=ccrs.PlateCarree())\n",
Expand Down Expand Up @@ -790,7 +827,7 @@
"Note:\n",
"> For a reason I don't know it is not possible to make an empty scatter plot. So I placed them at 0, 0, and then we need to set the extent explicitely.\n",
"\n",
"> `xarray` automatically sets labels when we plot it's data. Therefore we use `ch.lon.values` to get rid of the additional elements in the leged."
"> `xarray` automatically sets labels when we plot it's data. Therefore we use `ch.lon.values` to get rid of the additional elements in the legend."
]
},
{
Expand Down Expand Up @@ -823,13 +860,6 @@
"\n",
"ax.set_extent((5.49, 10.77, 45.7, 48.3), ccrs.PlateCarree())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
5 changes: 5 additions & 0 deletions WHATS_NEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* use `np.asarray` instead of `np.array`, because it does not copy the data (closes [GH2][i2])
* explain arguments of `plt.subplots` (closes [GH6][i6] and [GH7][i7])
* explain why np.newaxis is needed in ex1_2 (broadcasting) (closes [GH10][i10])
* ex3_2 fix typos and colormap range (closes [GH17][i17] and [GH19][i19])



### 1.0.0 (06.02.2018)
Expand All @@ -22,5 +24,8 @@
[i6]: https://github.com/C2SM/pyvis/issues/6
[i7]: https://github.com/C2SM/pyvis/issues/7
[i10]: https://github.com/C2SM/pyvis/issues/10
[i17]: https://github.com/C2SM/pyvis/issues/17
[i19]: https://github.com/C2SM/pyvis/issues/19



0 comments on commit f51a7de

Please sign in to comment.