{"action":"created","issue":{"url":"https://api.github.com/repos/rasbt/mlxtend/issues/183","repository_url":"https://api.github.com/repos/rasbt/mlxtend","labels_url":"https://api.github.com/repos/rasbt/mlxtend/issues/183/labels{/name}","comments_url":"https://api.github.com/repos/rasbt/mlxtend/issues/183/comments","events_url":"https://api.github.com/repos/rasbt/mlxtend/issues/183/events","html_url":"https://github.com/rasbt/mlxtend/issues/183","id":226851489,"number":183,"title":"plot_decision_regions AttributeError with subplot axes","user":{"login":"groundflyer","id":10357503,"avatar_url":"https://avatars2.githubusercontent.com/u/10357503?v=3","gravatar_id":"","url":"https://api.github.com/users/groundflyer","html_url":"https://github.com/groundflyer","followers_url":"https://api.github.com/users/groundflyer/followers","following_url":"https://api.github.com/users/groundflyer/following{/other_user}","gists_url":"https://api.github.com/users/groundflyer/gists{/gist_id}","starred_url":"https://api.github.com/users/groundflyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/groundflyer/subscriptions","organizations_url":"https://api.github.com/users/groundflyer/orgs","repos_url":"https://api.github.com/users/groundflyer/repos","events_url":"https://api.github.com/users/groundflyer/events{/privacy}","received_events_url":"https://api.github.com/users/groundflyer/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-05-07T11:27:34Z","updated_at":"2017-05-07T12:58:30Z","closed_at":"2017-05-07T12:58:30Z","body":"Such a snippet generates the error:\r\n```python\r\nfig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 5))\r\nplot_decision_regions(X, y, clf, ax1)\r\n```\r\nOutput:\r\n```python\r\nAttributeError                            Traceback (most recent call last)\r\n<ipython-input-8-0c4b110ce7ad> in <module>()\r\n      1 fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 5))\r\n----> 2 plot_decision_regions(X, y, clf, ax1)\r\n\r\n/home/toster/.local/lib64/python3.4/site-packages/mlxtend/plotting/decision_regions.py in plot_decision_regions(X, y, clf, ax, X_highlight, res, legend, hide_spines, markers, colors)\r\n    155                             borderaxespad=0.9)\r\n    156 \r\n--> 157         ax.add_artist(legend)\r\n    158 \r\n    159     if plot_testdata:\r\n\r\n/usr/lib64/python3.4/site-packages/matplotlib/axes/_base.py in add_artist(self, a)\r\n   1647         Returns the artist.\r\n   1648         \"\"\"\r\n-> 1649         a.axes = self\r\n   1650         self.artists.append(a)\r\n   1651         self._set_artist_props(a)\r\n\r\nAttributeError: 'NoneType' object has no attribute 'axes'\r\n```\r\nApparently, it's caused by `plt.legend()` which returns `None` when axes is set."},"comment":{"url":"https://api.github.com/repos/rasbt/mlxtend/issues/comments/299704819","html_url":"https://github.com/rasbt/mlxtend/issues/183#issuecomment-299704819","issue_url":"https://api.github.com/repos/rasbt/mlxtend/issues/183","id":299704819,"user":{"login":"rasbt","id":5618407,"avatar_url":"https://avatars0.githubusercontent.com/u/5618407?v=3","gravatar_id":"","url":"https://api.github.com/users/rasbt","html_url":"https://github.com/rasbt","followers_url":"https://api.github.com/users/rasbt/followers","following_url":"https://api.github.com/users/rasbt/following{/other_user}","gists_url":"https://api.github.com/users/rasbt/gists{/gist_id}","starred_url":"https://api.github.com/users/rasbt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rasbt/subscriptions","organizations_url":"https://api.github.com/users/rasbt/orgs","repos_url":"https://api.github.com/users/rasbt/repos","events_url":"https://api.github.com/users/rasbt/events{/privacy}","received_events_url":"https://api.github.com/users/rasbt/received_events","type":"User","site_admin":false},"created_at":"2017-05-07T12:58:30Z","updated_at":"2017-05-07T12:58:30Z","body":"Should work now (as of #184 , can be installed via `pip install git+git://github.com/rasbt/mlxtend.git`). Here's an example:\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nfrom mlxtend.plotting import plot_decision_regions\r\n\r\nfrom sklearn.linear_model import LogisticRegression\r\nfrom sklearn.naive_bayes import GaussianNB \r\nfrom sklearn import datasets\r\nimport numpy as np\r\n\r\n# Loading some example data\r\niris = datasets.load_iris()\r\nX = iris.data[:, 2]\r\nX = X[:, None]\r\ny = iris.target\r\n\r\n# Initializing and fitting classifiers\r\nclf1 = LogisticRegression(random_state=1)\r\nclf2 = GaussianNB()\r\nclf1.fit(X, y)\r\nclf2.fit(X, y)\r\n\r\nfig, axes = plt.subplots(1, 2, figsize=(10, 3))\r\n\r\nfig = plot_decision_regions(X=X, y=y, clf=clf1, ax=axes[0], legend=2)\r\nfig = plot_decision_regions(X=X, y=y, clf=clf2, ax=axes[1], legend=1)\r\n    \r\nplt.show()\r\n```\r\n\r\n![unknown](https://cloud.githubusercontent.com/assets/5618407/25781135/50eb361e-3303-11e7-886e-9d6df9920e8b.png)\r\n"}}
{"actor":{"display_login":"rasbt"}}