Skip to content

Commit 86b0b73

Browse files
committed
More polishing, and exercises are separated
1 parent 31d4479 commit 86b0b73

10 files changed

+229
-184
lines changed

AnatomyOfMatplotlib-Part1-pyplot.ipynb

+13-38
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"name": "",
4-
"signature": "sha256:bb79f3fb1b583fa80ed2817cbc765825ca44470bce6a68afd866d1e59a9ab3c7"
4+
"signature": "sha256:c7159e6f4ecac56d72f7333ed9bb24bbfeb4c66fba3000a1b2cb3c382fd148fd"
55
},
66
"nbformat": 3,
77
"nbformat_minor": 0,
@@ -413,7 +413,7 @@
413413
"cell_type": "markdown",
414414
"metadata": {},
415415
"source": [
416-
"### Exercise\n",
416+
"### Exercise 1.1\n",
417417
"How would you make a plot with a y-axis such that it starts at 1000 at the bottom, and goes to 500 at the top?\n",
418418
"\n",
419419
"Hint: [`set_ylim`](http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.set_ylim)"
@@ -423,9 +423,7 @@
423423
"cell_type": "code",
424424
"collapsed": false,
425425
"input": [
426-
"fig, ax = plt.subplots(1, 1)\n",
427-
"ax.set_ylim( )\n",
428-
"plt.show()"
426+
"%load exercises/1.1-limits.py"
429427
],
430428
"language": "python",
431429
"metadata": {},
@@ -585,7 +583,6 @@
585583
"cell_type": "code",
586584
"collapsed": false,
587585
"input": [
588-
"# Without \"tight_layout\"\n",
589586
"def example_plot(ax):\n",
590587
" ax.plot([1, 2])\n",
591588
" ax.set_xlabel('x-label', fontsize=16)\n",
@@ -597,23 +594,7 @@
597594
"example_plot(ax2)\n",
598595
"example_plot(ax3)\n",
599596
"example_plot(ax4)\n",
600-
"plt.show()"
601-
],
602-
"language": "python",
603-
"metadata": {},
604-
"outputs": []
605-
},
606-
{
607-
"cell_type": "code",
608-
"collapsed": false,
609-
"input": [
610-
"# With \"tight_layout\"\n",
611-
"fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2)\n",
612-
"example_plot(ax1)\n",
613-
"example_plot(ax2)\n",
614-
"example_plot(ax3)\n",
615-
"example_plot(ax4)\n",
616-
"plt.tight_layout()\n",
597+
"#plt.tight_layout()\n",
617598
"plt.show()"
618599
],
619600
"language": "python",
@@ -632,7 +613,7 @@
632613
"metadata": {},
633614
"source": [
634615
"## GridSpec\n",
635-
"Under the hood, matplotlib utilizes [`GridSpec`](http://matplotlib.org/api/gridspec_api.html) to layout the subplots. While `plt.subplots()` is fine for simple cases, sometimes you will need more advanced subplot layouts. In such cases, you should use GridSpec directly. GridSpec is outside the scope of this tutorial, but it is handy to know that it exists. [Here](http://matplotlib.org/users/gridspec.html) is a guide on how to use it."
616+
"Under the hood, matplotlib utilizes [`GridSpec`](http://matplotlib.org/api/gridspec_api.html) to lay out the subplots. While `plt.subplots()` is fine for simple cases, sometimes you will need more advanced subplot layouts. In such cases, you should use GridSpec directly. GridSpec is outside the scope of this tutorial, but it is handy to know that it exists. [Here](http://matplotlib.org/users/gridspec.html) is a guide on how to use it."
636617
]
637618
},
638619
{
@@ -649,6 +630,7 @@
649630
"input": [
650631
"# going out of inline mode to demonstrate the zooming and panning\n",
651632
"%matplotlib\n",
633+
"\n",
652634
"fig, (ax1, ax2) = plt.subplots(1, 2, sharex=True, sharey=True)\n",
653635
"ax1.plot([1, 2, 3, 4], [1, 2, 3, 4])\n",
654636
"ax2.plot([3, 4, 5, 6], [6, 5, 4, 3])\n",
@@ -685,6 +667,9 @@
685667
"ax1.plot([1, 2, 3, 4], [1, 2, 3, 4])\n",
686668
"ax2 = ax1.twinx()\n",
687669
"ax2.scatter([1, 2, 3, 4], [60, 50, 40, 30])\n",
670+
"ax1.set_xlabel('X')\n",
671+
"ax1.set_ylabel('First scale')\n",
672+
"ax2.set_ylabel('Other scale')\n",
688673
"plt.show()"
689674
],
690675
"language": "python",
@@ -735,8 +720,8 @@
735720
"cell_type": "markdown",
736721
"metadata": {},
737722
"source": [
738-
"## Exercise\n",
739-
"Modify the above example to have outward spines and tick labels on both sides, with tickmarks *through* the spines.\n",
723+
"## Exercise 1.2\n",
724+
"Create a plot that have outward spines on the left and bottom with tick labels, and \"centered\" spines with no tick labels and tickmarks *through* the spines.\n",
740725
"\n",
741726
"Hints:\n",
742727
"[`tick_params()`](http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.tick_params)\n",
@@ -747,17 +732,7 @@
747732
"cell_type": "code",
748733
"collapsed": false,
749734
"input": [
750-
"fig, ax = plt.subplots(1, 1)\n",
751-
"ax.plot([1, 2, 3, 4], [10, 20, 25, 30])\n",
752-
"ax.spines['top'].set_visible(False)\n",
753-
"ax.xaxis.set_ticks_position('bottom') # no ticklines at the top\n",
754-
"ax.tick_params(axis='y', direction='inout', length=10,\n",
755-
" labelleft=True, labelright=True,\n",
756-
" right=True, left=True)\n",
757-
"ax.spines['bottom'].set_position(('outward', 10))\n",
758-
"ax.spines['right'].set_position(('outward', 10))\n",
759-
"ax.spines['left'].set_position(('outward', 10))\n",
760-
"plt.show()"
735+
"%load exercises/1.2-spines.py"
761736
],
762737
"language": "python",
763738
"metadata": {},
@@ -768,7 +743,7 @@
768743
"metadata": {},
769744
"source": [
770745
"# Colorbars\n",
771-
"While not required for plotting, colorbars are much like legends because they help to describe the data being displayed. While legends describe plots, i.e., plot(), scatter(), hist(), stem(), colorbars describe images. To be really specific and technical, they can be used for any \"ScalarMappable\", which will be discussed in the Artists section. Let us take a look at a very simple example of a colorbar for a simple 2D image."
746+
"Colorbars are much like legends because they help to describe the data being displayed. While legends describe plots, i.e., plot(), scatter(), hist(), stem(), colorbars describe images. To be really specific and technical, they can be used for any \"ScalarMappable\", which will be discussed in the `Artists` section. Let us take a look at a very simple example of a colorbar for a simple 2D image."
772747
]
773748
},
774749
{

0 commit comments

Comments
 (0)