Title: Aspect ratio for not so common scales · Issue #13819 · matplotlib/matplotlib · GitHub
Open Graph Title: Aspect ratio for not so common scales · Issue #13819 · matplotlib/matplotlib
X Title: Aspect ratio for not so common scales · Issue #13819 · matplotlib/matplotlib
Description: Bug report Bug summary Bringing up this stackoverflow question on the issue tracker. Setting an equal aspect for symlog scales results in an UnboundLocalError. This should never happen, independent on how meaningful the notion of "aspect...
Open Graph Description: Bug report Bug summary Bringing up this stackoverflow question on the issue tracker. Setting an equal aspect for symlog scales results in an UnboundLocalError. This should never happen, independent...
X Description: Bug report Bug summary Bringing up this stackoverflow question on the issue tracker. Setting an equal aspect for symlog scales results in an UnboundLocalError. This should never happen, independent...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/13819
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Aspect ratio for not so common scales","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\nBringing up [this stackoverflow question](https://stackoverflow.com/questions/55438189/matplotlib-symlog-plot-with-non-auto-aspect-ratio) on the issue tracker.\r\n\r\nSetting an equal aspect for symlog scales results in an `UnboundLocalError`. This should never happen, independent on how meaningful the notion of \"aspect\" would be such case.\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```\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\ndt = 0.01\r\nx = np.arange(-50.0, 50.0, dt)\r\ny = np.arange(0, 100.0, dt)\r\n\r\nfig = plt.figure()\r\nax = fig.add_subplot(111,aspect='equal')\r\n\r\nplt.plot(x, np.sin(x / 3.0))\r\nplt.xscale('symlog')\r\nplt.yscale('symlog', linthreshy=0.015)\r\nplt.grid(True)\r\nplt.ylabel('symlog both')\r\n\r\nplt.show()\r\n```\r\n\r\n**Actual outcome**\r\n\r\n\u003c!--The output produced by the above code, which may be a screenshot, console output, etc.--\u003e\r\n\r\n```\r\nUnboundLocalError: local variable 'aspect_scale_mode' referenced before assignment\r\n```\r\n\r\n**Expected outcome**\r\n\r\nEither of the following:\r\n\r\n* An error telling that symlog does not support equal aspect.\r\n* A warning of the above and a fallback to `aspect=\"auto\".\r\n* A meaningful plot, in case someone has an idea of what \"aspect\" could mean in the case of two symlog scales.\r\n\r\n**Analysis**\r\n\r\nThe problem comes from https://github.com/matplotlib/matplotlib/blob/699f35e4d8d424393a7038428abc573d591bd6db/lib/matplotlib/axes/_base.py#L1469-L1485\r\n\r\nwhere there are a lot of cases for which the variable `aspect_scale_mode` isn't defined. I.e. each case that ends up in the `pass` section.\r\nWhen later accessing `aspect_scale_mode` in \r\nhttps://github.com/matplotlib/matplotlib/blob/699f35e4d8d424393a7038428abc573d591bd6db/lib/matplotlib/axes/_base.py#L1502-L1505\r\n\r\nthe above error is raised. \r\n\r\nThis brings up a more general question: Wouldn't the axis and its `Scale` actually need to be asked about their data limits? Something like (in pseudo code)\r\n\r\n box_aspect = A * (tranformed(self.yaxis.bounds[1]) - tranformed(self.yaxis.bounds[1]))/\r\n (tranformed(self.xaxis.bounds[0]) - tranformed(self.xaxis.bounds[0]))\r\n\r\nsuch that other / custom scales can have an aspect defined?\r\n\r\nRelated issue: https://github.com/matplotlib/matplotlib/issues/8878\r\n\r\n**Matplotlib version**\r\n\r\n * Matplotlib version: master\r\n","author":{"url":"https://github.com/ImportanceOfBeingErnest","@type":"Person","name":"ImportanceOfBeingErnest"},"datePublished":"2019-03-31T15:43:19.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/13819/matplotlib/issues/13819"}
| 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:551b1958-a738-2ed8-33be-f92762169016 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DB10:262D17:7DC460:A7B64A:6A53F72F |
| html-safe-nonce | 7ddf33496f45bb5d5543acbf78578605dbd5460640711906246eb8c62b693cdc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQjEwOjI2MkQxNzo3REM0NjA6QTdCNjRBOjZBNTNGNzJGIiwidmlzaXRvcl9pZCI6IjQ4MTcwNDQzODgyMDYzNDM5ODMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0bf2f6c47cda00fe7c4fe2ecf430f6d3c1c2f902e3b35bc8935c2ad030047462 |
| hovercard-subject-tag | issue:427410418 |
| 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/13819/issue_layout |
| twitter:image | https://opengraph.githubassets.com/15c07bf0acb0b72361486330bd95e7a818f6de4ffc33468b2a7b5218dbbac431/matplotlib/matplotlib/issues/13819 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/15c07bf0acb0b72361486330bd95e7a818f6de4ffc33468b2a7b5218dbbac431/matplotlib/matplotlib/issues/13819 |
| og:image:alt | Bug report Bug summary Bringing up this stackoverflow question on the issue tracker. Setting an equal aspect for symlog scales results in an UnboundLocalError. This should never happen, independent... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ImportanceOfBeingErnest |
| 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