Title: [Bug]: Secondary axis does not support Transform as functions · Issue #25691 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Secondary axis does not support Transform as functions · Issue #25691 · matplotlib/matplotlib
X Title: [Bug]: Secondary axis does not support Transform as functions · Issue #25691 · matplotlib/matplotlib
Description: Bug summary The documentation for secondary_[xy]axis claims to accept a Transform for the functions parameter. However, the checks in set_functions do not accept Transform: matplotlib/lib/matplotlib/axes/_secondary_axes.py Lines 147 to 1...
Open Graph Description: Bug summary The documentation for secondary_[xy]axis claims to accept a Transform for the functions parameter. However, the checks in set_functions do not accept Transform: matplotlib/lib/matplotli...
X Description: Bug summary The documentation for secondary_[xy]axis claims to accept a Transform for the functions parameter. However, the checks in set_functions do not accept Transform: matplotlib/lib/matplotli...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/25691
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Secondary axis does not support Transform as functions","articleBody":"### Bug summary\n\nThe [documentation for `secondary_[xy]axis`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.secondary_xaxis.html#matplotlib.axes.Axes.secondary_xaxis) claims to accept a `Transform` for the `functions` parameter.\r\n\r\nHowever, the checks in `set_functions` do not accept `Transform`:\r\nhttps://github.com/matplotlib/matplotlib/blob/3f4d4c10d40c1c60e9572b5e4702a463e2a06747/lib/matplotlib/axes/_secondary_axes.py#L147-L158\r\n\r\nand any usage of the internal attribute seems to assume a tuple of callables:\r\nhttps://github.com/matplotlib/matplotlib/blob/3f4d4c10d40c1c60e9572b5e4702a463e2a06747/lib/matplotlib/axes/_secondary_axes.py#L193-L194\r\nhttps://github.com/matplotlib/matplotlib/blob/3f4d4c10d40c1c60e9572b5e4702a463e2a06747/lib/matplotlib/axes/_secondary_axes.py#L216\r\n\r\nBoth this documentation and the checks have been in the code since it was added in #11859.\n\n### Code for reproduction\n\n```python\nimport matplotlib.pyplot as plt\r\nfrom matplotlib.transforms import IdentityTransform\r\n\r\nfig, ax = plt.subplots()\r\nsecax = ax.secondary_xaxis('top', functions=IdentityTransform)\r\n# OR:\r\nsecax = ax.secondary_xaxis('top', functions=IdentityTransform())\r\n# OR:\r\nsecax = ax.secondary_xaxis('top', functions=(IdentityTransform, IdentityTransform))\r\n# OR:\r\nsecax = ax.secondary_xaxis('top', functions=(IdentityTransform(), IdentityTransform()))\n```\n\n\n### Actual outcome\n\nWith a single transform (class or object), _or_ a tuple of transform objects, it fails in the setter:\r\n```pytb\r\nTraceback (most recent call last):\r\n File \"galleries/examples/subplots_axes_and_figures/secondary_axis.py\", line 40, in \u003cmodule\u003e\r\n secax = ax.secondary_xaxis('top', functions=IdentityTransform)\r\n File \"lib/matplotlib/axes/_axes.py\", line 586, in secondary_xaxis\r\n secondary_ax = SecondaryAxis(self, 'x', location, functions,\r\n File \"lib/matplotlib/axes/_secondary_axes.py\", line 42, in __init__\r\n self.set_functions(functions)\r\n File \"lib/matplotlib/axes/_secondary_axes.py\", line 155, in set_functions\r\n raise ValueError('functions argument of secondary axes '\r\nValueError: functions argument of secondary axes must be a two-tuple of callable functions with the first function being the transform and the second being the inverse\r\n```\r\nWith a tuple of transform classes, the setter allows it, but it fails when drawing:\r\n```\r\nTraceback (most recent call last):\r\n File \"lib/matplotlib/backends/backend_qt.py\", line 461, in _draw_idle\r\n self.draw()\r\n File \"lib/matplotlib/backends/backend_agg.py\", line 401, in draw\r\n self.figure.draw(self.renderer)\r\n File \"lib/matplotlib/artist.py\", line 95, in draw_wrapper\r\n result = draw(artist, renderer, *args, **kwargs)\r\n File \"lib/matplotlib/artist.py\", line 72, in draw_wrapper\r\n return draw(artist, renderer)\r\n File \"lib/matplotlib/figure.py\", line 3115, in draw\r\n artists = self._get_draw_artists(renderer)\r\n File \"lib/matplotlib/figure.py\", line 225, in _get_draw_artists\r\n child.apply_aspect(\r\n File \"lib/matplotlib/axes/_secondary_axes.py\", line 120, in apply_aspect\r\n self._set_lims()\r\n File \"lib/matplotlib/axes/_secondary_axes.py\", line 216, in _set_lims\r\n lims = self._functions[0](np.array(lims))\r\n File \"lib/matplotlib/transforms.py\", line 1759, in __init__\r\n super().__init__(*args, **kwargs)\r\n File \"lib/matplotlib/transforms.py\", line 125, in __init__\r\n self._shorthand_name = shorthand_name or ''\r\nValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()\r\n```\n\n### Expected outcome\n\nAt least one of the options works, or it should not be documented as accepted.\n\n### Additional information\n\nI noticed this oddity in the types while reviewing #25224, but not sure what we intend here.\n\n### Operating system\n\n_No response_\n\n### Matplotlib Version\n\n3f4d4c10d40c1c60e9572b5e4702a463e2a06747\n\n### Matplotlib Backend\n\n_No response_\n\n### Python version\n\n_No response_\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\ngit checkout","author":{"url":"https://github.com/QuLogic","@type":"Person","name":"QuLogic"},"datePublished":"2023-04-15T06:07:32.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/25691/matplotlib/issues/25691"}
| 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:eb9ab522-b127-721f-d3cb-3be4b3efd754 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B29C:814DC:4E094E:6751C0:6A52FF38 |
| html-safe-nonce | da5edcb7562730201fbac649e6fad16f71269c7c1bf100374ef795fa0eecd2cc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMjlDOjgxNERDOjRFMDk0RTo2NzUxQzA6NkE1MkZGMzgiLCJ2aXNpdG9yX2lkIjoiNDk5ODU4MDE0MDI3MzQ5OTk2MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2f6f7c970e6bf84b0df9d45e7266959a3695aedbad15fb40dd998d44813bb3a5 |
| hovercard-subject-tag | issue:1669178265 |
| 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/25691/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2e5363783de26ac75b86dba35654c75385722d079eb94394c4352bd155b60491/matplotlib/matplotlib/issues/25691 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2e5363783de26ac75b86dba35654c75385722d079eb94394c4352bd155b60491/matplotlib/matplotlib/issues/25691 |
| og:image:alt | Bug summary The documentation for secondary_[xy]axis claims to accept a Transform for the functions parameter. However, the checks in set_functions do not accept Transform: matplotlib/lib/matplotli... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | QuLogic |
| 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