René's URL Explorer Experiment


Title: plotting using secondary axis with mpl_toolkits.axes_grid1.parasite_axes.SubplotHost().twin() produces very weird outputs · Issue #7258 · matplotlib/matplotlib · GitHub

Open Graph Title: plotting using secondary axis with mpl_toolkits.axes_grid1.parasite_axes.SubplotHost().twin() produces very weird outputs · Issue #7258 · matplotlib/matplotlib

X Title: plotting using secondary axis with mpl_toolkits.axes_grid1.parasite_axes.SubplotHost().twin() produces very weird outputs · Issue #7258 · matplotlib/matplotlib

Description: For several plots I'd like to have a secondary x axis that is a non-affine transformation of the original axis. Following a very old discussion on nabble I recognized that it is only possible, if I define my own matplotlib.transforms.Tra...

Open Graph Description: For several plots I'd like to have a secondary x axis that is a non-affine transformation of the original axis. Following a very old discussion on nabble I recognized that it is only possible, if I...

X Description: For several plots I'd like to have a secondary x axis that is a non-affine transformation of the original axis. Following a very old discussion on nabble I recognized that it is only possible, ...

Opengraph URL: https://github.com/matplotlib/matplotlib/issues/7258

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"plotting using secondary axis with mpl_toolkits.axes_grid1.parasite_axes.SubplotHost().twin() produces very weird outputs","articleBody":"For several plots I'd like to have a secondary x axis that is a non-affine transformation of the original axis. Following a very old discussion on [nabble](http://matplotlib.1069221.n5.nabble.com/Dual-x-axes-with-transformation-td10865.html) I recognized that it is only possible, if I define my own matplotlib.transforms.Transform() class or I have to set tick locations manually according to a discussion on [stackoverflow](http://stackoverflow.com/questions/10514315/how-to-add-a-second-x-axis-in-matplotlib). I managed to make the code from the nabble link work, but I had to rename the class method transform() to transform_non_affine(). Otherwise it would not work.\nSo I now have the following code, which seemed to work fine for the first few tests.\n\n```\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.transforms as mtransforms\nfrom mpl_toolkits.axes_grid1.parasite_axes import SubplotHost\n\n\ndef transformed_x_axis(ax, transformation):\n\n    class MyTransform(mtransforms.Transform):\n        input_dims = 1\n        output_dims = 1\n        is_separable = False\n        has_inverse = False\n\n        def transform_non_affine(self, x):\n            return transformation(x)\n\n        def inverted(self):\n            return MyInvertedTransform()\n\n    class MyInvertedTransform(MyTransform):\n        def inverted(self):\n            return MyTransform()\n\n    aux_trans = mtransforms.BlendedGenericTransform(\n            MyTransform(), mtransforms.IdentityTransform())\n\n    ax2 = ax.twin(aux_trans)\n    ax2.set_viewlim_mode(\"transform\")\n    ax2.axis[\"right\"].toggle(ticklabels=False)\n    return ax2\n```\n\nFor convenience I defined a function 'transformed_x_axis()' that just accepts an original matplotlib.axes.Axes object and a transformation formula.\n(Actually, I think that my use case is pretty common and matplotlib should provide such kind of function that I tried to use, here.)\n\nUsing it with\n\n```\nfig = plt.figure()\nax = SubplotHost(fig, 1,1,1)\nfig.add_subplot(ax)\n\nax2 = transformed_x_axis(ax, lambda x: 1. / x)\n\nx = np.linspace(1., 2., 200)\nax.plot(x, np.sin(x))\nplt.show()\n```\n\nproduces exactly what I want -- a plot with a secondary transformed x axis:\n![01](https://cloud.githubusercontent.com/assets/7665678/19308706/53662004-9081-11e6-89dd-9b9adbc9e7bf.png)\n\nUnfortunately, for other transformations or for other data limits I see all kinds of weirdest things happening.\n\nFor other data ranges, e.g. `x = np.linspace(1., 5., 200)`, the ticker has problems and draws ticklabels on top of each other:\n![02](https://cloud.githubusercontent.com/assets/7665678/19308895/3dc33eac-9082-11e6-86e1-f35549a89cbe.png)\n\nIf the axis approaches the critical point 0.0 of my transformation, the ticks don'e even fill the axis but only a tiny part of it:\n![03](https://cloud.githubusercontent.com/assets/7665678/19309003/b6549276-9082-11e6-8a16-9fb948e96998.png)\n\nI guess that this is a result of the linear scale of the ticklabels. It seems the ticks for the axis are chosen by value and not by position in axes coordinates, which I find kind of wrong.\n\nOther transformations also produce weird things, e.g.\n\n```\nfig = plt.figure()\nax = SubplotHost(fig, 1,1,1)\nfig.add_subplot(ax)\n\nax2 = transformed_x_axis(ax, lambda x: np.exp(x))\n\nx = np.linspace(1., 5., 200)\nax.plot(x, np.sin(x))\nplt.show()\n```\n\ngives me a RuntimeError in an IPython Notebook and in a terminal it produces a secondary axis that contains nothing but the value 0.\n![04](https://cloud.githubusercontent.com/assets/7665678/19309474/408e4462-9085-11e6-942a-424feb9bc618.png)\n\nFor other data limits,\n\n```\nax2 = transformed_x_axis(ax, lambda x: np.exp(x))\nx = np.linspace(1., 2., 200)\nax.plot(x, np.sin(x))\n```\n\nI get a MemoryError in the notebook. When done in the terminal, I see no secondary x axis.\n\nThe strangest things occur for simple linear transformations:\n\n```\nfig = plt.figure()\nax = SubplotHost(fig, 1,1,1)\nfig.add_subplot(ax)\n\nax2 = transformed_x_axis(ax, lambda x: 2. * x)\n\nx = np.linspace(1., 2., 200)\nax.plot(x, np.sin(x))\nplt.show()\n```\n\nHere, in the terminal, I see, again, no secondary axis. But in the notebook, I think one can see that something goes dramatically wrong:\n![05](https://cloud.githubusercontent.com/assets/7665678/19309566/f6e4dbea-9085-11e6-8ea3-b3bbc45d93b7.png)\n\nI think, it is the ticker that does those weird things when it faces transformed axes.\n\nAnyway, the behavior is inconsistent, unexpected and very weird.\n\nCheers, Gerhard\n\n---\n\nPython 2.7.12, matplotlib 1.5.1 on Windows 64 bit\neverything installed via Anaconda\n","author":{"url":"https://github.com/griai","@type":"Person","name":"griai"},"datePublished":"2016-10-12T12:17:41.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/7258/matplotlib/issues/7258"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:a673059a-2c3c-55af-3480-859f16679610
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8A7C:2A1FE2:A2EA8E:DB4B31:6A53140E
html-safe-nonceeae335c556f1b284946fcaf4e84040ecbec7229d581785d210d89eceea598c27
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTdDOjJBMUZFMjpBMkVBOEU6REI0QjMxOjZBNTMxNDBFIiwidmlzaXRvcl9pZCI6IjE1MzY5NzgzODM5NDIxMjg2NTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacc022bd87b4d179da4f22b0843f52bc240e4f7216209d6340572ef6134a4d16d8
hovercard-subject-tagissue:182510537
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/7258/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d086212254fb7fb8902bd7ab38bbebabec7cdded0511c60efc8c6588be2e12b4/matplotlib/matplotlib/issues/7258
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d086212254fb7fb8902bd7ab38bbebabec7cdded0511c60efc8c6588be2e12b4/matplotlib/matplotlib/issues/7258
og:image:altFor several plots I'd like to have a secondary x axis that is a non-affine transformation of the original axis. Following a very old discussion on nabble I recognized that it is only possible, if I...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamegriai
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
go-importgithub.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git
octolytics-dimension-user_id215947
octolytics-dimension-user_loginmatplotlib
octolytics-dimension-repository_id1385122
octolytics-dimension-repository_nwomatplotlib/matplotlib
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1385122
octolytics-dimension-repository_network_root_nwomatplotlib/matplotlib
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release07a982c1d40157c619b364352b704c3ce66bb332
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/matplotlib/matplotlib/issues/7258#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F7258
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F7258
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=matplotlib%2Fmatplotlib
Reloadhttps://github.com/matplotlib/matplotlib/issues/7258
Reloadhttps://github.com/matplotlib/matplotlib/issues/7258
Reloadhttps://github.com/matplotlib/matplotlib/issues/7258
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/7258
matplotlib https://github.com/matplotlib
matplotlibhttps://github.com/matplotlib/matplotlib
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/7258
Notifications https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Fork 8.4k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Star 23k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Code https://github.com/matplotlib/matplotlib
Issues 1.1k https://github.com/matplotlib/matplotlib/issues
Pull requests 408 https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality 0 https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
Code https://github.com/matplotlib/matplotlib
Issues https://github.com/matplotlib/matplotlib/issues
Pull requests https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
plotting using secondary axis with mpl_toolkits.axes_grid1.parasite_axes.SubplotHost().twin() produces very weird outputshttps://github.com/matplotlib/matplotlib/issues/7258#top
https://github.com/griai
griaihttps://github.com/griai
on Oct 12, 2016https://github.com/matplotlib/matplotlib/issues/7258#issue-182510537
nabblehttp://matplotlib.1069221.n5.nabble.com/Dual-x-axes-with-transformation-td10865.html
stackoverflowhttp://stackoverflow.com/questions/10514315/how-to-add-a-second-x-axis-in-matplotlib
https://cloud.githubusercontent.com/assets/7665678/19308706/53662004-9081-11e6-89dd-9b9adbc9e7bf.png
https://cloud.githubusercontent.com/assets/7665678/19308895/3dc33eac-9082-11e6-86e1-f35549a89cbe.png
https://cloud.githubusercontent.com/assets/7665678/19309003/b6549276-9082-11e6-8a16-9fb948e96998.png
https://cloud.githubusercontent.com/assets/7665678/19309474/408e4462-9085-11e6-942a-424feb9bc618.png
https://cloud.githubusercontent.com/assets/7665678/19309566/f6e4dbea-9085-11e6-8ea3-b3bbc45d93b7.png
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.