Title: Specifying a Marker as a Tuple seems broken in 3.2 · Issue #16811 · matplotlib/matplotlib · GitHub
Open Graph Title: Specifying a Marker as a Tuple seems broken in 3.2 · Issue #16811 · matplotlib/matplotlib
X Title: Specifying a Marker as a Tuple seems broken in 3.2 · Issue #16811 · matplotlib/matplotlib
Description: Bug report Bug summary In matplotlib 3.2 setting a line marker=(3, 2, 0.0) (which should be an asterisk style marker with 3 sides and 0 degrees of rotation) causes an error. AttributeError: 'IdentityTransform' object has no attribute 'sc...
Open Graph Description: Bug report Bug summary In matplotlib 3.2 setting a line marker=(3, 2, 0.0) (which should be an asterisk style marker with 3 sides and 0 degrees of rotation) causes an error. AttributeError: 'Identi...
X Description: Bug report Bug summary In matplotlib 3.2 setting a line marker=(3, 2, 0.0) (which should be an asterisk style marker with 3 sides and 0 degrees of rotation) causes an error. AttributeError: 'Id...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/16811
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Specifying a Marker as a Tuple seems broken in 3.2","articleBody":"\u003c!--To help us understand and resolve your issue, please fill out the form to the best of your ability.--\u003e\r\n\u003c!--You can feel free to delete the sections that do not apply.--\u003e\r\n\r\n### Bug report\r\n\r\n**Bug summary**\r\n\r\nIn matplotlib 3.2 setting a line `marker=(3, 2, 0.0)` (which should be an asterisk style marker with 3 sides and 0 degrees of rotation) causes an error.\r\n\r\n```\r\nAttributeError: 'IdentityTransform' object has no attribute 'scale'\r\n```\r\n\r\nIn version 3.1.2, this error does not occur. It looks like \r\n\r\n\u003c!--A short 1-2 sentences that succinctly describes the bug--\u003e\r\n\r\n**Code for reproduction**\r\n\r\n\u003c!--A minimum code snippet required to reproduce the bug.\r\nPlease make sure to minimize the number of dependencies required, and provide\r\nany necessary plotted data.\r\nAvoid using threads, as Matplotlib is (explicitly) not thread-safe.--\u003e\r\n\r\n```python\r\ndef main():\r\n import matplotlib.pyplot as plt\r\n fig = plt.figure()\r\n fig.add_axes()\r\n ax = fig.gca()\r\n ax.plot([0, 1, 2], [0, 1, 2], marker=(3, 2, 0.0))\r\n fig.savefig('foo.png')\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n```\r\n\r\nThis results in the error: \r\n\r\n```\r\nTraceback (most recent call last):\r\n File \"/home/joncrall/code/kwplot/dev/mwe_markerstye.py\", line 15, in \u003cmodule\u003e\r\n main()\r\n File \"/home/joncrall/code/kwplot/dev/mwe_markerstye.py\", line 7, in main\r\n fig.savefig('foo.png')\r\n File \"/home/joncrall/.local/conda/envs/py38/lib/python3.8/site-packages/matplotlib/figure.py\", line 2203, in savefig\r\n self.canvas.print_figure(fname, **kwargs)\r\n File \"/home/joncrall/.local/conda/envs/py38/lib/python3.8/site-packages/matplotlib/backends/backend_qt5agg.py\", line 94, in print_figure\r\n super().print_figure(*args, **kwargs)\r\n File \"/home/joncrall/.local/conda/envs/py38/lib/python3.8/site-packages/matplotlib/backend_bases.py\", line 2086, in print_figure\r\n result = print_method(\r\n File \"/home/joncrall/.local/conda/envs/py38/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py\", line 514, in print_png\r\n FigureCanvasAgg.draw(self)\r\n File \"/home/joncrall/.local/conda/envs/py38/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py\", line 393, in draw\r\n self.figure.draw(self.renderer)\r\n File \"/home/joncrall/.local/conda/envs/py38/lib/python3.8/site-packages/matplotlib/artist.py\", line 38, in draw_wrapper\r\n return draw(artist, renderer, *args, **kwargs)\r\n File \"/home/joncrall/.local/conda/envs/py38/lib/python3.8/site-packages/matplotlib/figure.py\", line 1735, in draw\r\n mimage._draw_list_compositing_images(\r\n File \"/home/joncrall/.local/conda/envs/py38/lib/python3.8/site-packages/matplotlib/image.py\", line 137, in _draw_list_compositing_images\r\n a.draw(renderer)\r\n File \"/home/joncrall/.local/conda/envs/py38/lib/python3.8/site-packages/matplotlib/artist.py\", line 38, in draw_wrapper\r\n return draw(artist, renderer, *args, **kwargs)\r\n File \"/home/joncrall/.local/conda/envs/py38/lib/python3.8/site-packages/matplotlib/axes/_base.py\", line 2630, in draw\r\n mimage._draw_list_compositing_images(renderer, self, artists)\r\n File \"/home/joncrall/.local/conda/envs/py38/lib/python3.8/site-packages/matplotlib/image.py\", line 137, in _draw_list_compositing_images\r\n a.draw(renderer)\r\n File \"/home/joncrall/.local/conda/envs/py38/lib/python3.8/site-packages/matplotlib/artist.py\", line 38, in draw_wrapper\r\n return draw(artist, renderer, *args, **kwargs)\r\n File \"/home/joncrall/.local/conda/envs/py38/lib/python3.8/site-packages/matplotlib/lines.py\", line 866, in draw\r\n marker_trans = marker_trans.scale(w)\r\nAttributeError: 'IdentityTransform' object has no attribute 'scale'\r\n```\r\n\r\nWhile the 3.1.2 version results in a nice plot: \r\n\r\n\r\n\r\n\r\n**Matplotlib version**\r\n * Operating system: Linux\r\n * Matplotlib version: 3.2 (via pip)\r\n * Matplotlib backend: tried agg and pyqt5\r\n * Python version: 3.7 and 3.8\r\n\r\nI've identified a possible solution. The main difference seems to be in the `_set_tuple_marker` function. In 3.1.2 it was:\r\n\r\n```python\r\n def _set_tuple_marker(self):\r\n marker = self._marker\r\n if isinstance(marker[0], Number):\r\n if len(marker) == 2:\r\n numsides, rotation = marker[0], 0.0\r\n elif len(marker) == 3:\r\n numsides, rotation = marker[0], marker[2]\r\n symstyle = marker[1]\r\n if symstyle == 0:\r\n self._path = Path.unit_regular_polygon(numsides)\r\n self._joinstyle = 'miter'\r\n elif symstyle == 1:\r\n self._path = Path.unit_regular_star(numsides)\r\n self._joinstyle = 'bevel'\r\n elif symstyle == 2:\r\n self._path = Path.unit_regular_asterisk(numsides)\r\n self._filled = False\r\n self._joinstyle = 'bevel'\r\n elif symstyle == 3:\r\n cbook.warn_deprecated(\r\n \"3.0\", message=\"Setting a circle marker using `(..., 3)` \"\r\n \"is deprecated since Matplotlib 3.0, and support for it \"\r\n \"will be removed in 3.2. Directly pass 'o' instead.\")\r\n self._path = Path.unit_circle()\r\n self._transform = Affine2D().scale(0.5).rotate_deg(rotation)\r\n else:\r\n cbook.warn_deprecated(\r\n \"3.0\", message=\"Passing vertices as `(verts, 0)` is \"\r\n \"deprecated since Matplotlib 3.0, and support for it will be \"\r\n \"removed in 3.2. Directly pass `verts` instead.\")\r\n verts = np.asarray(marker[0])\r\n path = Path(verts)\r\n self._set_custom_marker(path)\r\n```\r\n\r\nand in 3.2 it was cleaned up to: \r\n\r\n\r\n```python\r\n def _set_tuple_marker(self):\r\n marker = self._marker\r\n print('marker = {!r}'.format(marker))\r\n if len(marker) == 2:\r\n numsides, rotation = marker[0], 0.0\r\n elif len(marker) == 3:\r\n numsides, rotation = marker[0], marker[2]\r\n symstyle = marker[1]\r\n if symstyle == 0:\r\n self._path = Path.unit_regular_polygon(numsides)\r\n self._joinstyle = 'miter'\r\n elif symstyle == 1:\r\n self._path = Path.unit_regular_star(numsides)\r\n self._joinstyle = 'bevel'\r\n elif symstyle == 2:\r\n self._path = Path.unit_regular_asterisk(numsides)\r\n self._filled = False\r\n self._joinstyle = 'bevel'\r\n else:\r\n raise ValueError(f\"Unexpected tuple marker: {marker}\")\r\n```\r\n\r\nHowever, notice that in the second version `self._transform` is never set. Also note that in the 3.2 version the rotation param is never used. I expect that the `self._transform = Affine2D().scale(0.5).rotate_deg(rotation)` line was supposed to be ported, but never was. Adding it back in seems to fix the issue. \r\n\r\nI noticed it when looking in the lines.py draw method. I saw most markers had an AffineTransform, but the ones I made using the tuple method of initialization has IdentityTransforms. \r\n\r\n","author":{"url":"https://github.com/Erotemic","@type":"Person","name":"Erotemic"},"datePublished":"2020-03-17T22:47:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/16811/matplotlib/issues/16811"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:aa26700e-70cf-8ff1-f947-174bd24960e7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 81DC:2336BC:4AD95F:65A24D:6A5278C1 |
| html-safe-nonce | a89bddc7ba72f9e003fb1c5e87e53f368cf29dab69e946bc46f34bc4dbfb8e7d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MURDOjIzMzZCQzo0QUQ5NUY6NjVBMjREOjZBNTI3OEMxIiwidmlzaXRvcl9pZCI6IjgxNTUzNTEzNzMwNjk4NDI2MjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8b20498d53dcb9d0e7b5c2669e7794fb589a2ce6234b0bdc991dd93187f852e8 |
| hovercard-subject-tag | issue:583345090 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/16811/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0128197d01451dcdd08257565909979ad2bb87bff5d3fcfd596a91477e84e2fe/matplotlib/matplotlib/issues/16811 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0128197d01451dcdd08257565909979ad2bb87bff5d3fcfd596a91477e84e2fe/matplotlib/matplotlib/issues/16811 |
| og:image:alt | Bug report Bug summary In matplotlib 3.2 setting a line marker=(3, 2, 0.0) (which should be an asterisk style marker with 3 sides and 0 degrees of rotation) causes an error. AttributeError: 'Identi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Erotemic |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width