Skip to content

Matplotlib #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions _toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ parts:
sections:
- file: core/matplotlib/matplotlib
- file: core/matplotlib/matplotlib-additional-topics-1
- file: core/matplotlib/additional-topics2
- file: core/cartopy
sections:
- file: core/cartopy/cartopy
Expand Down
767 changes: 767 additions & 0 deletions core/matplotlib/additional-topics2.ipynb

Large diffs are not rendered by default.

Binary file added core/matplotlib/images/c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/matplotlib/images/cyclic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/matplotlib/images/d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/matplotlib/images/diverging.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/matplotlib/images/hsv2gray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/matplotlib/images/m.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/matplotlib/images/misc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/matplotlib/images/ps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/matplotlib/images/qualitative.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/matplotlib/images/s1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/matplotlib/images/s2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/matplotlib/images/sequential.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added core/matplotlib/images/sequential2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 59 additions & 23 deletions core/matplotlib/matplotlib.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
"## Overview\n",
"We will cover the basics of plotting within Python, using the Matplotlib library, including a few different plots available within the library.\n",
"\n",
"1. Create a basic line plot.\n",
"1. Add labels and grid lines to the plot.\n",
"1. Plot multiple series of data.\n",
"1. Plot image, contour, and filled contour plots."
"1. Figure and axes\n",
"1. Basic line plots\n",
"1. Labels and grid lines\n",
"1. Customizing colors\n",
"1. Subplots\n",
"1. Scatterplots\n",
"1. Displaying Images\n",
"1. Contour and filled contour plots."
]
},
{
Expand Down Expand Up @@ -182,7 +186,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Line plots\n",
"## Basic Line Plots\n",
"\n",
"Let's create a `Figure` whose dimensions, if printed out on hardcopy, would be 10 inches wide and 6 inches long (assuming a landscape orientation). We then create an `Axes`, consisting of a single subplot, on the `Figure`. After that, we call `plot`, with `times` as the data along the x-axis (independent values) and `temps` as the data along the y-axis (the dependent values).\n",
"\n",
Expand All @@ -206,7 +210,14 @@
"ax = fig.add_subplot(1, 1, 1)\n",
"\n",
"# Plot times as x-variable and temperatures as y-variable\n",
"ax.plot(times, temps)"
"ax.plot(times, temps);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Labels and Grid Lines"
]
},
{
Expand Down Expand Up @@ -337,14 +348,14 @@
"ax.grid(True)\n",
"\n",
"# Add a legend to the upper left corner of the plot\n",
"ax.legend(loc='upper left')"
"ax.legend(loc='upper left');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Customizing colors"
"## Customizing colors"
]
},
{
Expand Down Expand Up @@ -382,14 +393,16 @@
"ax.grid(True)\n",
"\n",
"# Add a legend to the upper left corner of the plot\n",
"ax.legend(loc='upper left')"
"ax.legend(loc='upper left');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Working with multiple panels in a figure"
"## Subplots\n",
"\n",
"Working with multiple panels in a figure"
]
},
{
Expand Down Expand Up @@ -421,7 +434,7 @@
"metadata": {},
"source": [
"### Using add_subplot to create two different subplots within the figure\n",
"We can use the `.add_subplot()` method to add subplots to our figure! The subplot arguements are formatted as follows:\n",
"We can use the `.add_subplot()` method to add subplots to our figure! The subplot arguments are formatted as follows:\n",
"`(rows, columns, subplot_number)`\n",
"\n",
"For example, if we want a single row, with two columns, we use the following code block"
Expand All @@ -441,7 +454,28 @@
"\n",
"# Create a plot for dewpoint\n",
"ax2 = fig.add_subplot(1, 2, 2)\n",
"ax2.plot(times, dewpoint, color='tab:green')"
"ax2.plot(times, dewpoint, color='tab:green');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also use `plot.subplots()` with inputs `nrows` and `ncolumns` to initialize your subplot axes, `ax`. \n",
"\n",
"Index your axes, as in `ax[0].plot()` to decide which subplot you're plotting to."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(10, 6))\n",
"\n",
"ax[0].plot(times, temps, color='tab:red')\n",
"ax[1].plot(times, dewpoint, color='tab:green');"
]
},
{
Expand All @@ -468,7 +502,7 @@
"# Create a plot for dewpoint\n",
"ax2 = fig.add_subplot(1, 2, 2)\n",
"ax2.plot(times, dewpoint, color='tab:green')\n",
"ax2.set_title('Dewpoint')"
"ax2.set_title('Dewpoint');"
]
},
{
Expand Down Expand Up @@ -499,7 +533,7 @@
"ax2 = fig.add_subplot(1, 2, 2)\n",
"ax2.plot(times, dewpoint, color='tab:green')\n",
"ax2.set_title('Dewpoint')\n",
"ax2.set_xlim(110, 130)"
"ax2.set_xlim(110, 130);"
]
},
{
Expand Down Expand Up @@ -530,7 +564,7 @@
"# Create a plot for dewpoint\n",
"ax2 = fig.add_subplot(1, 2, 2, sharex=ax, sharey=ax)\n",
"ax2.plot(times, dewpoint, color='tab:green')\n",
"ax2.set_title('Dewpoint')"
"ax2.set_title('Dewpoint');"
]
},
{
Expand Down Expand Up @@ -621,7 +655,7 @@
"ax.set_xlabel('Temperature (surface)')\n",
"ax.set_ylabel('Temperature (1000 hPa)')\n",
"ax.set_title('Temperature Cross Plot')\n",
"ax.grid(True)"
"ax.grid(True);"
]
},
{
Expand Down Expand Up @@ -649,7 +683,7 @@
"ax.set_xlabel('Temperature (surface)')\n",
"ax.set_ylabel('Temperature (1000 hPa)')\n",
"ax.set_title('Temperature Cross Plot')\n",
"ax.grid(True)"
"ax.grid(True);"
]
},
{
Expand Down Expand Up @@ -679,14 +713,15 @@
"ax.set_xlabel('Temperature (surface)')\n",
"ax.set_ylabel('Temperature (1000 hPa)')\n",
"ax.set_title('Temperature Cross Plot')\n",
"ax.grid(True)"
"ax.grid(True);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## imshow\n",
"## Displaying Images\n",
"\n",
"`imshow` displays the values in an array as colored pixels, similar to a heat map.\n",
"\n",
"Here is some fake data to work with - let's use a bivariate normal distribution."
Expand Down Expand Up @@ -728,7 +763,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## contour/contourf\n",
"## Contour and Filled Contour Plots\n",
"\n",
"- `contour` creates contours around data.\n",
"- `contourf` creates filled contours around data."
]
Expand All @@ -747,7 +783,7 @@
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"ax.contour(X, Y, Z)"
"ax.contour(X, Y, Z);"
]
},
{
Expand All @@ -765,7 +801,7 @@
"source": [
"fig, ax = plt.subplots()\n",
"c = ax.contour(X, Y, Z, levels=np.arange(-2, 2, 0.25))\n",
"ax.clabel(c)"
"ax.clabel(c);"
]
},
{
Expand All @@ -782,7 +818,7 @@
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"c = ax.contourf(X, Y, Z)"
"c = ax.contourf(X, Y, Z);"
]
},
{
Expand Down