René's URL Explorer Experiment


Title: [ENH]: Support for custom/special ticks without complex workarounds · Issue #22262 · matplotlib/matplotlib · GitHub

Open Graph Title: [ENH]: Support for custom/special ticks without complex workarounds · Issue #22262 · matplotlib/matplotlib

X Title: [ENH]: Support for custom/special ticks without complex workarounds · Issue #22262 · matplotlib/matplotlib

Description: Problem There is no direct, user-friendly method to add custom/special ticks. Existing methods can lead to surprising results and I have found little official guidance in the documentation that would account for this. From what I have se...

Open Graph Description: Problem There is no direct, user-friendly method to add custom/special ticks. Existing methods can lead to surprising results and I have found little official guidance in the documentation that wou...

X Description: Problem There is no direct, user-friendly method to add custom/special ticks. Existing methods can lead to surprising results and I have found little official guidance in the documentation that wou...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[ENH]: Support for custom/special ticks without complex workarounds","articleBody":"### Problem\r\n\r\nThere is no direct, user-friendly method to add custom/special ticks. Existing methods can lead to surprising results and I have found little official guidance in the documentation that would account for this.\r\n\r\nFrom what I have seen in the examples gallery and on the Internet, most solutions rely on `Axes.set_xticks` or `Axes.set_yticks`. These methods can fail silently (and very frustratingly) when attempting to work with e.g. a semilog plot.\r\n\r\nExample of what would be expected behaviour with user set ticks (using ordinary `plot`):\r\n```python\r\nimport numpy as np\r\nimport matplotlib as mpl\r\nimport matplotlib.pyplot as plt\r\n\r\n\r\n# Constants\r\nL = 6\r\nD = 1\r\ngamma = 1\r\nm_0 = 1\r\nDelta_m = 0.05\r\nq = gamma / D\r\nr = np.sqrt(q)\r\nSamples = 601\r\n\r\n# Functions that should work with numbers and ndarrays just as well\r\ndef dervLin(xs):\r\n    return xs * 0 -m_0 / L # Trick to make this ndarray-compatible (`xs * 0 +` forces array broadcasting, but doesn't change the value)\r\n\r\ndef dervExp(xs):\r\n    return -m_0 * r * np.exp(-r * xs)\r\n\r\ndef dervPow(xs):\r\n    return -12 * D / gamma / (xs + np.sqrt((6 * D / gamma) / m_0))**3\r\n\r\n\r\nxs = np.linspace(0, L, Samples)\r\nys1 = Delta_m / np.abs(dervLin(xs))\r\nys2 = Delta_m / np.abs(dervExp(xs))\r\nys3 = Delta_m / np.abs(dervPow(xs))\r\n\r\n\r\nfig, ax = plt.subplots(1, 1)\r\nax.set_xlim(0, L)\r\nax.plot(xs, ys1, xs, ys2, xs, ys3)\r\nax.hlines([ys1[-1], ys2[-1], ys3[-1]], 0, L, linewidth=0.5, linestyle=\"dashed\", color=\"grey\")\r\nax.set_yticks([ys1[-1], ys2[-1], ys3[-1]])\r\n```\r\n\r\noutputs\r\n![issue_plot_1](https://user-images.githubusercontent.com/6322902/150011042-a0c941c9-01cc-48c2-a331-16b54868f889.png)\r\n\r\nNow, trying the same with `Axes.semilogy` instead of `Axes.plot`:\r\n```python\r\nimport numpy as np\r\nimport matplotlib as mpl\r\nimport matplotlib.pyplot as plt\r\n\r\n\r\n# Constants\r\nL = 6\r\nD = 1\r\ngamma = 1\r\nm_0 = 1\r\nDelta_m = 0.05\r\nq = gamma / D\r\nr = np.sqrt(q)\r\nSamples = 601\r\n\r\n# Functions that should work with numbers and ndarrays just as well\r\ndef dervLin(xs):\r\n    return xs * 0 -m_0 / L # Trick to make this ndarray-compatible (`xs * 0 +` forces array broadcasting, but doesn't change the value)\r\n\r\ndef dervExp(xs):\r\n    return -m_0 * r * np.exp(-r * xs)\r\n\r\ndef dervPow(xs):\r\n    return -12 * D / gamma / (xs + np.sqrt((6 * D / gamma) / m_0))**3\r\n\r\n\r\nxs = np.linspace(0, L, Samples)\r\nys1 = Delta_m / np.abs(dervLin(xs))\r\nys2 = Delta_m / np.abs(dervExp(xs))\r\nys3 = Delta_m / np.abs(dervPow(xs))\r\n\r\n\r\nfig, ax = plt.subplots(1, 1)\r\nax.set_xlim(0, L)\r\nax.semilogy(xs, ys1, xs, ys2, xs, ys3)\r\nax.hlines([ys1[-1], ys2[-1], ys3[-1]], 0, L, linewidth=0.5, linestyle=\"dashed\", color=\"grey\")\r\nax.set_yticks([ys1[-1], ys2[-1], ys3[-1]])\r\n```\r\n\r\nsilently fails to produce labelled ticks:\r\n![issue_plot_2](https://user-images.githubusercontent.com/6322902/150011993-0427b124-958f-43fe-a4b8-5e67e7cc092c.png)\r\n\r\nI have deduced that the problem lies with `LogFormatterSciNotation`, which doesn't produce a tick label when presented with user-provided values.\r\n```python\r\nfmt = ax.yaxis.get_major_formatter()\r\n\u003e\u003e\u003e fmt\r\n\u003cmatplotlib.ticker.LogFormatterSciNotation at 0x1d7a95a1940\u003e\r\n\u003e\u003e\u003e fmt(0.3)\r\n''\r\n\u003e\u003e\u003e fmt(10)\r\n'$\\\\mathdefault{10^{1}}$'\r\n```\r\n\r\nMy workaround includes subclassing and substituting the formatter:\r\n```python\r\nclass SpecialLogFmt(mpl.ticker.LogFormatterSciNotation):\r\n    def __call__(self, x, pos):\r\n        s = super().__call__(x, pos)\r\n        \r\n        if len(s) == 0:\r\n            s = \"%.2f\" % x\r\n        return s\r\n\r\nsfmt = SpecialLogFmt()\r\nax.yaxis.set_major_formatter(sfmt)\r\n```\r\n\r\nGiven these complications that necessitate a not completely trivial workaround, I believe it would be helpful to introduce explicit support for user-provided special ticks (in parallel to automatically-generated ticks). Other software e.g. OriginLab/OriginPro offers such a feature out of the box.\r\n\r\n### Proposed solution\r\n\r\nAt the very least, amend documentation of `Axes.set_xticks`/`Axes.set_yticks` to state that the results also depend on the `Formatter` of the axis, which may ignore the ticks which were added manually. [Current documentation](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_yticks.html) claiming that `If not set, the labels show the data value.` is misleading when this isn't mentioned.\r\n\r\nAdd a gallery example that shows how to use special ticks, with more emphasis on such edge cases as can occur with e.g. log plots.\r\n\r\nIf possible, create new API methods that would explicitly support manually-added special ticks, so that the user does not have to worry about making the axis formatter work with the custom ticks. This API could be connected with the `hlines`/`vlines` method to give horizontal/vertical lines ending in a special tick, which may be very helpful in some contexts.","author":{"url":"https://github.com/yaaun","@type":"Person","name":"yaaun"},"datePublished":"2022-01-18T20:55:40.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/22262/matplotlib/issues/22262"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:413dc0e7-c3f6-485f-866a-98e995bc6b90
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9BA6:1F8C21:A95089:E3E79C:6A52968E
html-safe-nonce934cd7e92934085832bf50b24e79722d396332cf39baa3ae9417c4ae873274f9
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QkE2OjFGOEMyMTpBOTUwODk6RTNFNzlDOjZBNTI5NjhFIiwidmlzaXRvcl9pZCI6IjgzODQyMjMzNjQxNjA1OTE1MDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmaca69b10766f695a7f87215c6692ca1b36bb1bc058af9812e44d6dc4368cb557b6
hovercard-subject-tagissue:1107353812
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/22262/issue_layout
twitter:imagehttps://opengraph.githubassets.com/bf3810a82cf9daad651cbf8d0513082608112ac62136c9ed4193437b2a0f622c/matplotlib/matplotlib/issues/22262
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/bf3810a82cf9daad651cbf8d0513082608112ac62136c9ed4193437b2a0f622c/matplotlib/matplotlib/issues/22262
og:image:altProblem There is no direct, user-friendly method to add custom/special ticks. Existing methods can lead to surprising results and I have found little official guidance in the documentation that wou...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameyaaun
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/22262#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F22262
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%2F22262
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/22262
Reloadhttps://github.com/matplotlib/matplotlib/issues/22262
Reloadhttps://github.com/matplotlib/matplotlib/issues/22262
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/22262
matplotlib https://github.com/matplotlib
matplotlibhttps://github.com/matplotlib/matplotlib
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/22262
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
[ENH]: Support for custom/special ticks without complex workaroundshttps://github.com/matplotlib/matplotlib/issues/22262#top
Documentationhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22Documentation%22
New featurehttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22New%20feature%22
topic: ticks axis labelshttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22topic%3A%20ticks%20axis%20labels%22
v3.6.0https://github.com/matplotlib/matplotlib/milestone/65
https://github.com/yaaun
yaaunhttps://github.com/yaaun
on Jan 18, 2022https://github.com/matplotlib/matplotlib/issues/22262#issue-1107353812
https://user-images.githubusercontent.com/6322902/150011042-a0c941c9-01cc-48c2-a331-16b54868f889.png
https://user-images.githubusercontent.com/6322902/150011993-0427b124-958f-43fe-a4b8-5e67e7cc092c.png
Current documentationhttps://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_yticks.html
Documentationhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22Documentation%22
New featurehttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22New%20feature%22
topic: ticks axis labelshttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22topic%3A%20ticks%20axis%20labels%22
v3.6.0https://github.com/matplotlib/matplotlib/milestone/65
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.