Skip to content

Commit f5c7ca5

Browse files
committed
[08] make plot compatible with new matplotlib version
plt.hist() not working with plt.annotate() using arrow dicts with newest matplotlib version
1 parent 3ab0070 commit f5c7ca5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

notebooks/08-common-problems.ipynb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@
7979
" if ax is None:\n",
8080
" fig, ax = plt.subplots()\n",
8181
" for n, _traj in enumerate(data):\n",
82-
" ax.hist(_traj, bins=30, alpha=.33, density=True, color='C{}'.format(n));\n",
83-
" ylims = ax.get_ylim()\n",
82+
" h, e = np.histogram(_traj, bins=30, density=True)\n",
83+
" ax.fill_between(e[1:], h, step='pre', alpha=.33, color='C{}'.format(n))\n",
84+
" \n",
85+
" ylims = (0, ax.get_ylim()[1])\n",
8486
" xlims = ax.get_xlim()\n",
8587
" for n, _traj in enumerate(data):\n",
8688
" ax.plot(\n",
@@ -98,6 +100,7 @@
98100
" ax.text(0.86 * xlims[1], 0.5 * ylims[1], '$x(time)$', ha='left', va='center', rotation=90)\n",
99101
" ax.set_xlabel('TICA coordinate')\n",
100102
" ax.set_ylabel('histogram counts & trajectory time')\n",
103+
" ax.set_ylim(0, ax.get_ylim()[1]) # fill_between resets lower ylim < 0\n",
101104
" ax.legend(loc=2)"
102105
]
103106
},
@@ -905,7 +908,7 @@
905908
"name": "python",
906909
"nbconvert_exporter": "python",
907910
"pygments_lexer": "ipython3",
908-
"version": "3.6.5"
911+
"version": "3.6.6"
909912
},
910913
"toc": {
911914
"base_numbering": 1,

0 commit comments

Comments
 (0)