Skip to content

Commit bed2f02

Browse files
committed
Move anatomy of a figure image to circumvent GitHub issues
1 parent bf029bc commit bed2f02

File tree

3 files changed

+44
-44
lines changed

3 files changed

+44
-44
lines changed

notebooks/1-getting_started_with_matplotlib.ipynb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@
15961596
],
15971597
"source": [
15981598
"stackoverflow_monthly.matplotlib.plot(\n",
1599-
" figsize=(8, 2), xlabel='creation date', ylabel='total questions', \n",
1599+
" figsize=(8, 2), xlabel='creation date', ylabel='total questions',\n",
16001600
" title='Matplotlib Questions per Month\\n(since the creation of Stack Overflow)'\n",
16011601
")"
16021602
]
@@ -1729,7 +1729,7 @@
17291729
"The `Figure` object is the container for all components of our visualization. It contains one or more `Axes` objects, which can be thought of as the (sub)plots, as well as other [*Artists*](https://matplotlib.org/stable/tutorials/intermediate/artists.html), which draw on the plot canvas (x-axis, y-axis, legend, lines, etc.). The following image from the Matplotlib documentation illustrates the different components of a figure:\n",
17301730
"\n",
17311731
"<div style=\"text-align: center;\">\n",
1732-
" <img width=\"40%\" src=\"https://raw.githubusercontent.com/stefmolin/python-data-viz-workshop/main/media/figure_anatomy.svg\" alt=\"Matplotlib figure anatomy\" style=\"min-width: 400px\">\n",
1732+
" <img width=\"40%\" src=\"../slides/media/figure_anatomy.svg\" alt=\"Matplotlib figure anatomy\" style=\"min-width: 400px\">\n",
17331733
" <div><small><em><a href=\"https://matplotlib.org/stable/tutorials/introductory/quick_start.html#parts-of-a-figure\">Source</a></em></small></div>\n",
17341734
"</div>"
17351735
]
@@ -5705,7 +5705,7 @@
57055705
],
57065706
"source": [
57075707
"ax = stackoverflow_monthly.matplotlib.plot(\n",
5708-
" figsize=(8, 2), xlabel='creation date', ylabel='total questions', \n",
5708+
" figsize=(8, 2), xlabel='creation date', ylabel='total questions',\n",
57095709
" title='Matplotlib Questions per Month\\n(since the creation of Stack Overflow)'\n",
57105710
")\n",
57115711
"ax.set_ylim(0, None) # this can also be done with pandas\n",
@@ -21035,7 +21035,7 @@
2103521035
"fig, ax = plt.subplots(figsize=(8, 2))\n",
2103621036
"ax.plot(avgs.index, avgs.matplotlib)\n",
2103721037
"ax.fill_between(\n",
21038-
" avgs.index, avgs.matplotlib - 2 * stds.matplotlib, \n",
21038+
" avgs.index, avgs.matplotlib - 2 * stds.matplotlib,\n",
2103921039
" avgs.matplotlib + 2 * stds.matplotlib, alpha=0.25\n",
2104021040
")"
2104121041
]
@@ -33816,7 +33816,7 @@
3381633816
"fig, ax = plt.subplots(figsize=(8, 2))\n",
3381733817
"ax.plot(avgs.index, avgs.matplotlib)\n",
3381833818
"ax.fill_between(\n",
33819-
" avgs.index, avgs.matplotlib - 2 * stds.matplotlib, \n",
33819+
" avgs.index, avgs.matplotlib - 2 * stds.matplotlib,\n",
3382033820
" avgs.matplotlib + 2 * stds.matplotlib, alpha=0.25\n",
3382133821
")\n",
3382233822
"\n",
@@ -34590,7 +34590,7 @@
3459034590
"fig, ax = plt.subplots(figsize=(9, 3))\n",
3459134591
"ax.plot(\n",
3459234592
" stackoverflow_monthly.index,\n",
34593-
" stackoverflow_monthly.matplotlib, \n",
34593+
" stackoverflow_monthly.matplotlib,\n",
3459434594
" 'ok', label=None, alpha=0.5\n",
3459534595
")"
3459634596
]
@@ -35395,7 +35395,7 @@
3539535395
"source": [
3539635396
"fig, ax = plt.subplots(figsize=(9, 3))\n",
3539735397
"ax.plot(\n",
35398-
" x_axis_dates, stackoverflow_monthly.matplotlib, \n",
35398+
" x_axis_dates, stackoverflow_monthly.matplotlib,\n",
3539935399
" 'ok', label=None, alpha=0.5\n",
3540035400
")"
3540135401
]
@@ -44476,7 +44476,7 @@
4447644476
"source": [
4447744477
"fig, ax = plt.subplots(figsize=(12, 3))\n",
4447844478
"ax.stackplot(\n",
44479-
" mdates.date2num(top_libraries_monthly.index), top_libraries_monthly.to_numpy().T, \n",
44479+
" mdates.date2num(top_libraries_monthly.index), top_libraries_monthly.to_numpy().T,\n",
4448044480
" labels=top_libraries_monthly.columns\n",
4448144481
")\n",
4448244482
"ax.set(xlabel='', ylabel='tagged questions', title='Stack Overflow Questions per Month')\n",
@@ -44509,7 +44509,7 @@
4450944509
" fig, ax = plt.subplots(figsize=(12, 3))\n",
4451044510
" ax.stackplot(\n",
4451144511
" mdates.date2num(data.index),\n",
44512-
" data.to_numpy().T, \n",
44512+
" data.to_numpy().T,\n",
4451344513
" labels=data.columns\n",
4451444514
" )\n",
4451544515
" ax.set(\n",
@@ -47195,7 +47195,7 @@
4719547195
" fig, ax = plt.subplots(figsize=(12, 3))\n",
4719647196
" ax.stackplot(\n",
4719747197
" mdates.date2num(data.index),\n",
47198-
" data.to_numpy().T, \n",
47198+
" data.to_numpy().T,\n",
4719947199
" labels=data.columns\n",
4720047200
" )\n",
4720147201
" ax.set(\n",
@@ -49833,7 +49833,7 @@
4983349833
"import datetime as dt\n",
4983449834
"\n",
4983549835
"ax = area_plot(top_libraries_monthly)\n",
49836-
" \n",
49836+
"\n",
4983749837
"# mark when seaborn was created\n",
4983849838
"seaborn_released = dt.date(2013, 10, 28)\n",
4983949839
"ax.axvline(seaborn_released, ymax=0.6, color='gray', linestyle='dashed')\n",
@@ -55159,8 +55159,8 @@
5515955159
")\n",
5516055160
"middle = (seaborn_released - first_seaborn_qs) / 2 + first_seaborn_qs\n",
5516155161
"ax.annotate(\n",
55162-
" 'posts retroactively\\ntagged \"seaborn\"', \n",
55163-
" xy=(mdates.date2num(middle), 3500), \n",
55162+
" 'posts retroactively\\ntagged \"seaborn\"',\n",
55163+
" xy=(mdates.date2num(middle), 3500),\n",
5516455164
" va='top', ha='center'\n",
5516555165
")"
5516655166
]
@@ -55210,7 +55210,7 @@
5521055210
" fig, ax = plt.subplots(figsize=(12, 3))\n",
5521155211
" ax.stackplot(\n",
5521255212
" mdates.date2num(data.index),\n",
55213-
" data.to_numpy().T, \n",
55213+
" data.to_numpy().T,\n",
5521455214
" labels=data.columns\n",
5521555215
" )\n",
5521655216
" ax.set(\n",
@@ -63637,7 +63637,7 @@
6363763637
"\n",
6363863638
"total_qs = top_libraries_monthly.sum()\n",
6363963639
"inset_ax.barh(\n",
63640-
" total_qs.index, total_qs.to_numpy(), \n",
63640+
" total_qs.index, total_qs.to_numpy(),\n",
6364163641
" color=[colors[label] for label in total_qs.index]\n",
6364263642
")\n",
6364363643
"inset_ax.yaxis.set_inverted(True)\n",
@@ -68368,7 +68368,7 @@
6836868368
" co_occurring_library = data[library]\n",
6836968369
" ax.barh(libraries, co_occurring_library, label=library, left=last)\n",
6837068370
" last += co_occurring_library\n",
68371-
" \n",
68371+
"\n",
6837268372
" ax.yaxis.set_inverted(True)\n",
6837368373
" return despine(ax)"
6837468374
]
@@ -73752,7 +73752,7 @@
7375273752
" co_occurring_library = data[library]\n",
7375373753
" ax.barh(libraries, co_occurring_library, label=library, left=last)\n",
7375473754
" last += co_occurring_library\n",
73755-
" \n",
73755+
"\n",
7375673756
" ax.yaxis.set_inverted(True)\n",
7375773757
" ax.legend(bbox_to_anchor=(1.35, 0.5), loc='center right', framealpha=0.5)\n",
7375873758
" ax.set(xlabel='percentage of questions with co-occurrences', xlim=(0, 1))\n",
@@ -76160,11 +76160,11 @@
7616076160
" for i, library in enumerate(libraries):\n",
7616176161
" co_occurring_library = data[library]\n",
7616276162
" ax.barh(\n",
76163-
" libraries, co_occurring_library, \n",
76163+
" libraries, co_occurring_library,\n",
7616476164
" label=library, left=last, color=cmap(i)\n",
7616576165
" )\n",
7616676166
" last += co_occurring_library\n",
76167-
" \n",
76167+
"\n",
7616876168
" ax.yaxis.set_inverted(True)\n",
7616976169
" ax.legend(bbox_to_anchor=(1.35, 0.5), loc='center right', framealpha=0.5)\n",
7617076170
" ax.set(xlabel='percentage of questions with co-occurrences', xlim=(0, 1))\n",
@@ -78628,7 +78628,7 @@
7862878628
],
7862978629
"source": [
7863078630
"subway = pd.read_csv(\n",
78631-
" '../data/NYC_subway_daily.csv', parse_dates=['Datetime'], \n",
78631+
" '../data/NYC_subway_daily.csv', parse_dates=['Datetime'],\n",
7863278632
" index_col=['Borough', 'Datetime']\n",
7863378633
")\n",
7863478634
"subway_daily = subway.unstack(0)\n",
@@ -84537,7 +84537,7 @@
8453784537
"\n",
8453884538
" axes[0].set_ylabel('Frequency')\n",
8453984539
" fig.suptitle('Histogram of Daily Subway Entries in Manhattan')\n",
84540-
" \n",
84540+
"\n",
8454184541
" return fig, axes"
8454284542
]
8454384543
},

slides/1-getting_started_with_matplotlib.ipynb

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@
16201620
],
16211621
"source": [
16221622
"stackoverflow_monthly.matplotlib.plot(\n",
1623-
" figsize=(8, 2), xlabel='creation date', ylabel='total questions', \n",
1623+
" figsize=(8, 2), xlabel='creation date', ylabel='total questions',\n",
16241624
" title='Matplotlib Questions per Month\\n(since the creation of Stack Overflow)'\n",
16251625
")"
16261626
]
@@ -1774,7 +1774,7 @@
17741774
"The `Figure` object is the container for all components of our visualization. It contains one or more `Axes` objects, which can be thought of as the (sub)plots, as well as other [*Artists*](https://matplotlib.org/stable/tutorials/intermediate/artists.html), which draw on the plot canvas (x-axis, y-axis, legend, lines, etc.). The following image from the Matplotlib documentation illustrates the different components of a figure:\n",
17751775
"\n",
17761776
"<div style=\"text-align: center;\">\n",
1777-
" <img width=\"40%\" src=\"https://raw.githubusercontent.com/stefmolin/python-data-viz-workshop/main/media/figure_anatomy.svg\" alt=\"Matplotlib figure anatomy\" style=\"min-width: 400px\">\n",
1777+
" <img width=\"40%\" src=\"media/figure_anatomy.svg\" alt=\"Matplotlib figure anatomy\" style=\"min-width: 400px\">\n",
17781778
" <div><small><em><a href=\"https://matplotlib.org/stable/tutorials/introductory/quick_start.html#parts-of-a-figure\">Source</a></em></small></div>\n",
17791779
"</div>"
17801780
]
@@ -5750,7 +5750,7 @@
57505750
],
57515751
"source": [
57525752
"ax = stackoverflow_monthly.matplotlib.plot(\n",
5753-
" figsize=(8, 2), xlabel='creation date', ylabel='total questions', \n",
5753+
" figsize=(8, 2), xlabel='creation date', ylabel='total questions',\n",
57545754
" title='Matplotlib Questions per Month\\n(since the creation of Stack Overflow)'\n",
57555755
")\n",
57565756
"ax.set_ylim(0, None) # this can also be done with pandas\n",
@@ -21101,7 +21101,7 @@
2110121101
"fig, ax = plt.subplots(figsize=(8, 2))\n",
2110221102
"ax.plot(avgs.index, avgs.matplotlib)\n",
2110321103
"ax.fill_between(\n",
21104-
" avgs.index, avgs.matplotlib - 2 * stds.matplotlib, \n",
21104+
" avgs.index, avgs.matplotlib - 2 * stds.matplotlib,\n",
2110521105
" avgs.matplotlib + 2 * stds.matplotlib, alpha=0.25\n",
2110621106
")"
2110721107
]
@@ -33882,7 +33882,7 @@
3388233882
"fig, ax = plt.subplots(figsize=(8, 2))\n",
3388333883
"ax.plot(avgs.index, avgs.matplotlib)\n",
3388433884
"ax.fill_between(\n",
33885-
" avgs.index, avgs.matplotlib - 2 * stds.matplotlib, \n",
33885+
" avgs.index, avgs.matplotlib - 2 * stds.matplotlib,\n",
3388633886
" avgs.matplotlib + 2 * stds.matplotlib, alpha=0.25\n",
3388733887
")\n",
3388833888
"\n",
@@ -34658,7 +34658,7 @@
3465834658
"fig, ax = plt.subplots(figsize=(9, 3))\n",
3465934659
"ax.plot(\n",
3466034660
" stackoverflow_monthly.index,\n",
34661-
" stackoverflow_monthly.matplotlib, \n",
34661+
" stackoverflow_monthly.matplotlib,\n",
3466234662
" 'ok', label=None, alpha=0.5\n",
3466334663
")"
3466434664
]
@@ -35463,7 +35463,7 @@
3546335463
"source": [
3546435464
"fig, ax = plt.subplots(figsize=(9, 3))\n",
3546535465
"ax.plot(\n",
35466-
" x_axis_dates, stackoverflow_monthly.matplotlib, \n",
35466+
" x_axis_dates, stackoverflow_monthly.matplotlib,\n",
3546735467
" 'ok', label=None, alpha=0.5\n",
3546835468
")"
3546935469
]
@@ -40384,7 +40384,7 @@
4038440384
" ax.xaxis.set_major_formatter(mdates.DateFormatter('%b\\n%Y'))\n",
4038540385
"\n",
4038640386
" ax.fill_between(\n",
40387-
" la_tavg.index, la_tavg, nyc_tavg, where=nyc_tavg > la_tavg, \n",
40387+
" la_tavg.index, la_tavg, nyc_tavg, where=nyc_tavg > la_tavg,\n",
4038840388
" hatch='///', facecolor='gray', alpha=0.5, label='NYC hotter than LA'\n",
4038940389
" )\n",
4039040390
" ax.legend(ncols=3, loc='lower center')\n",
@@ -47037,7 +47037,7 @@
4703747037
"source": [
4703847038
"fig, ax = plt.subplots(figsize=(12, 3))\n",
4703947039
"ax.stackplot(\n",
47040-
" mdates.date2num(top_libraries_monthly.index), top_libraries_monthly.to_numpy().T, \n",
47040+
" mdates.date2num(top_libraries_monthly.index), top_libraries_monthly.to_numpy().T,\n",
4704147041
" labels=top_libraries_monthly.columns\n",
4704247042
")\n",
4704347043
"ax.set(xlabel='', ylabel='tagged questions', title='Stack Overflow Questions per Month')\n",
@@ -47070,7 +47070,7 @@
4707047070
" fig, ax = plt.subplots(figsize=(12, 3))\n",
4707147071
" ax.stackplot(\n",
4707247072
" mdates.date2num(data.index),\n",
47073-
" data.to_numpy().T, \n",
47073+
" data.to_numpy().T,\n",
4707447074
" labels=data.columns\n",
4707547075
" )\n",
4707647076
" ax.set(\n",
@@ -49756,7 +49756,7 @@
4975649756
" fig, ax = plt.subplots(figsize=(12, 3))\n",
4975749757
" ax.stackplot(\n",
4975849758
" mdates.date2num(data.index),\n",
49759-
" data.to_numpy().T, \n",
49759+
" data.to_numpy().T,\n",
4976049760
" labels=data.columns\n",
4976149761
" )\n",
4976249762
" ax.set(\n",
@@ -52394,7 +52394,7 @@
5239452394
"import datetime as dt\n",
5239552395
"\n",
5239652396
"ax = area_plot(top_libraries_monthly)\n",
52397-
" \n",
52397+
"\n",
5239852398
"# mark when seaborn was created\n",
5239952399
"seaborn_released = dt.date(2013, 10, 28)\n",
5240052400
"ax.axvline(seaborn_released, ymax=0.6, color='gray', linestyle='dashed')\n",
@@ -57720,8 +57720,8 @@
5772057720
")\n",
5772157721
"middle = (seaborn_released - first_seaborn_qs) / 2 + first_seaborn_qs\n",
5772257722
"ax.annotate(\n",
57723-
" 'posts retroactively\\ntagged \"seaborn\"', \n",
57724-
" xy=(mdates.date2num(middle), 3500), \n",
57723+
" 'posts retroactively\\ntagged \"seaborn\"',\n",
57724+
" xy=(mdates.date2num(middle), 3500),\n",
5772557725
" va='top', ha='center'\n",
5772657726
")"
5772757727
]
@@ -57773,7 +57773,7 @@
5777357773
" fig, ax = plt.subplots(figsize=(12, 3))\n",
5777457774
" ax.stackplot(\n",
5777557775
" mdates.date2num(data.index),\n",
57776-
" data.to_numpy().T, \n",
57776+
" data.to_numpy().T,\n",
5777757777
" labels=data.columns\n",
5777857778
" )\n",
5777957779
" ax.set(\n",
@@ -66200,7 +66200,7 @@
6620066200
"\n",
6620166201
"total_qs = top_libraries_monthly.sum()\n",
6620266202
"inset_ax.barh(\n",
66203-
" total_qs.index, total_qs.to_numpy(), \n",
66203+
" total_qs.index, total_qs.to_numpy(),\n",
6620466204
" color=[colors[label] for label in total_qs.index]\n",
6620566205
")\n",
6620666206
"inset_ax.yaxis.set_inverted(True)\n",
@@ -72555,7 +72555,7 @@
7255572555
" co_occurring_library = data[library]\n",
7255672556
" ax.barh(libraries, co_occurring_library, label=library, left=last)\n",
7255772557
" last += co_occurring_library\n",
72558-
" \n",
72558+
"\n",
7255972559
" ax.yaxis.set_inverted(True)\n",
7256072560
" return despine(ax)"
7256172561
]
@@ -77939,7 +77939,7 @@
7793977939
" co_occurring_library = data[library]\n",
7794077940
" ax.barh(libraries, co_occurring_library, label=library, left=last)\n",
7794177941
" last += co_occurring_library\n",
77942-
" \n",
77942+
"\n",
7794377943
" ax.yaxis.set_inverted(True)\n",
7794477944
" ax.legend(bbox_to_anchor=(1.35, 0.5), loc='center right', framealpha=0.5)\n",
7794577945
" ax.set(xlabel='percentage of questions with co-occurrences', xlim=(0, 1))\n",
@@ -80347,11 +80347,11 @@
8034780347
" for i, library in enumerate(libraries):\n",
8034880348
" co_occurring_library = data[library]\n",
8034980349
" ax.barh(\n",
80350-
" libraries, co_occurring_library, \n",
80350+
" libraries, co_occurring_library,\n",
8035180351
" label=library, left=last, color=cmap(i)\n",
8035280352
" )\n",
8035380353
" last += co_occurring_library\n",
80354-
" \n",
80354+
"\n",
8035580355
" ax.yaxis.set_inverted(True)\n",
8035680356
" ax.legend(bbox_to_anchor=(1.35, 0.5), loc='center right', framealpha=0.5)\n",
8035780357
" ax.set(xlabel='percentage of questions with co-occurrences', xlim=(0, 1))\n",
@@ -82836,7 +82836,7 @@
8283682836
" )\n",
8283782837
" last += prcp\n",
8283882838
"\n",
82839-
" ax.set_xlabel('2020 total precipitation (inches)') \n",
82839+
" ax.set_xlabel('2020 total precipitation (inches)')\n",
8284082840
" ax.set_title('Total Precipitation per City in 2020', y=1.1)\n",
8284182841
" ax.axvline(total_prcp['Seattle'], linestyle='--', color='gray')\n",
8284282842
" ax.legend(bbox_to_anchor=(0.5, 1.15), loc='upper center', ncols=4, frameon=False)\n",
@@ -84824,7 +84824,7 @@
8482484824
],
8482584825
"source": [
8482684826
"subway = pd.read_csv(\n",
84827-
" '../data/NYC_subway_daily.csv', parse_dates=['Datetime'], \n",
84827+
" '../data/NYC_subway_daily.csv', parse_dates=['Datetime'],\n",
8482884828
" index_col=['Borough', 'Datetime']\n",
8482984829
")\n",
8483084830
"subway_daily = subway.unstack(0)\n",
@@ -90733,7 +90733,7 @@
9073390733
"\n",
9073490734
" axes[0].set_ylabel('Frequency')\n",
9073590735
" fig.suptitle('Histogram of Daily Subway Entries in Manhattan')\n",
90736-
" \n",
90736+
"\n",
9073790737
" return fig, axes"
9073890738
]
9073990739
},

0 commit comments

Comments
 (0)