Title: [Bug]: clabel manual argument does not accept units · Issue #27525 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: clabel manual argument does not accept units · Issue #27525 · matplotlib/matplotlib
X Title: [Bug]: clabel manual argument does not accept units · Issue #27525 · matplotlib/matplotlib
Description: Bug summary As found in #27490, while contour does appear to allow units, if you pass manual label locations to the manual argument of `clabel, it will fail. Code for reproduction import datetime import numpy as np import matplotlib.pypl...
Open Graph Description: Bug summary As found in #27490, while contour does appear to allow units, if you pass manual label locations to the manual argument of `clabel, it will fail. Code for reproduction import datetime i...
X Description: Bug summary As found in #27490, while contour does appear to allow units, if you pass manual label locations to the manual argument of `clabel, it will fail. Code for reproduction import datetime i...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/27525
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: clabel manual argument does not accept units","articleBody":"### Bug summary\r\n\r\nAs found in #27490, while `contour` does appear to allow units, if you pass manual label locations to the `manual` argument of `clabel, it will fail.\r\n\r\n### Code for reproduction\r\n\r\n```python\r\nimport datetime\r\n\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\n\r\n\r\n# Sample data for contour plot\r\ndates = [datetime.datetime(2023, 10, 1) + datetime.timedelta(days=i) for i in range(10)]\r\nx_start, x_end, x_step = -10.0, 5.0, 0.5\r\ny_start, y_end, y_step = 0, 10, 1\r\n\r\nx = np.arange(x_start, x_end, x_step)\r\ny = np.arange(y_start, y_end, y_step)\r\n\r\n# In this case, Y axis has dates\r\nX, Y = np.meshgrid(x, dates)\r\n\r\nrows = len(X)\r\ncols = len(X[0])\r\n\r\nz1D = np.arange(rows * cols)\r\nZ = z1D.reshape((rows, cols))\r\n\r\nfig, ax = plt.subplots()\r\nCS = ax.contour(X, Y, Z)\r\n\r\nax.clabel(CS, CS.levels, inline=True, fmt=dict(zip(CS.levels, dates)),\r\n manual=[(x, y) for x, y in zip(x, dates)])\r\n```\r\n\r\n\r\n### Actual outcome\r\n```python\r\nTraceback (most recent call last):\r\n File \"/home/elliott/code/matplotlib/clabel.py\", line 27, in \u003cmodule\u003e\r\n ax.clabel(CS, CS.levels, inline=True, fmt=dict(zip(CS.levels, dates)),\r\n File \"/home/elliott/code/matplotlib/lib/matplotlib/axes/_axes.py\", line 6581, in clabel\r\n return CS.clabel(levels, **kwargs)\r\n File \"/home/elliott/code/matplotlib/lib/matplotlib/contour.py\", line 195, in clabel\r\n self.add_label_near(x, y, inline, inline_spacing)\r\n File \"/home/elliott/code/matplotlib/lib/matplotlib/contour.py\", line 553, in add_label_near\r\n x, y = transform.transform((x, y))\r\n File \"/home/elliott/code/matplotlib/lib/matplotlib/transforms.py\", line 1508, in transform\r\n res = self.transform_affine(self.transform_non_affine(values))\r\n File \"/home/elliott/code/matplotlib/lib/matplotlib/_api/deprecation.py\", line 297, in wrapper\r\n return func(*args, **kwargs)\r\n File \"/home/elliott/code/matplotlib/lib/matplotlib/transforms.py\", line 2422, in transform_affine\r\n return self.get_affine().transform(values)\r\n File \"/home/elliott/code/matplotlib/lib/matplotlib/transforms.py\", line 1797, in transform\r\n return self.transform_affine(values)\r\n File \"/home/elliott/code/matplotlib/lib/matplotlib/_api/deprecation.py\", line 297, in wrapper\r\n return func(*args, **kwargs)\r\n File \"/home/elliott/code/matplotlib/lib/matplotlib/transforms.py\", line 1868, in transform_affine\r\n return affine_transform(values, mtx)\r\nTypeError: Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'safe'\r\n```\r\n### Expected outcome\r\n\r\nLabels are added at spots corresponding to those given in `manual`.\r\n\r\n### Additional information\r\n\r\n_No response_\r\n\r\n### Operating system\r\n\r\n_No response_\r\n\r\n### Matplotlib Version\r\n\r\n589d3fbe13f0067a21804ab3f55ffeb07a839b90\r\n\r\n### Matplotlib Backend\r\n\r\n_No response_\r\n\r\n### Python version\r\n\r\n_No response_\r\n\r\n### Jupyter version\r\n\r\n_No response_\r\n\r\n### Installation\r\n\r\ngit checkout","author":{"url":"https://github.com/QuLogic","@type":"Person","name":"QuLogic"},"datePublished":"2023-12-16T00:14:46.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/27525/matplotlib/issues/27525"}
| 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:8ba8d343-d4d0-8dfd-a40e-9fd6c684b4e6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C6AE:1D5468:1A7A43A:230B74A:6A51D451 |
| html-safe-nonce | a74b4dfa09e6feb4654a5f5f63e197d46a4e0e2e359680a95b6a3a98ac673aee |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNkFFOjFENTQ2ODoxQTdBNDNBOjIzMEI3NEE6NkE1MUQ0NTEiLCJ2aXNpdG9yX2lkIjoiNTQxOTczNTg3MTU4NTg5OTYwMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9e8e5fd6f5fdc2558aeccee073491208d80b64ea89349e39d8d3a76b0114193c |
| hovercard-subject-tag | issue:2044513518 |
| 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/27525/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e34a80c92f448212f948def90929cfdf94a0642d6f59e1fb288b56b9e2346bc6/matplotlib/matplotlib/issues/27525 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e34a80c92f448212f948def90929cfdf94a0642d6f59e1fb288b56b9e2346bc6/matplotlib/matplotlib/issues/27525 |
| og:image:alt | Bug summary As found in #27490, while contour does appear to allow units, if you pass manual label locations to the manual argument of `clabel, it will fail. Code for reproduction import datetime i... |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width