Title: Matplotlib colorbar moves second x axis drawn with twiny · Issue #5904 · matplotlib/matplotlib · GitHub
Open Graph Title: Matplotlib colorbar moves second x axis drawn with twiny · Issue #5904 · matplotlib/matplotlib
X Title: Matplotlib colorbar moves second x axis drawn with twiny · Issue #5904 · matplotlib/matplotlib
Description: Bug report originated in SO post here: http://stackoverflow.com/q/34979781/1391441 I'm trying to add a second x axis to the top of a plot using twiny. If I make a simple scatter plot with no colorbar, the top x axis is correctly aligned ...
Open Graph Description: Bug report originated in SO post here: http://stackoverflow.com/q/34979781/1391441 I'm trying to add a second x axis to the top of a plot using twiny. If I make a simple scatter plot with no colorb...
X Description: Bug report originated in SO post here: http://stackoverflow.com/q/34979781/1391441 I'm trying to add a second x axis to the top of a plot using twiny. If I make a simple scatter plot with no co...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/5904
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Matplotlib colorbar moves second x axis drawn with twiny","articleBody":"Bug report originated in SO post here: http://stackoverflow.com/q/34979781/1391441\n\n---\n\nI'm trying to add a second x axis to the top of a plot using [twiny](http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.twiny).\n\nIf I make a simple scatter plot with no colorbar, the top x axis is correctly aligned with the bottom x axis (MWE is below):\n\n[](http://i.stack.imgur.com/NPT2H.png)\n\nIf I add a colorbar though, the top x axis is displaced:\n\n[](http://i.stack.imgur.com/5yf97.png)\n\n---\n\n**MWE**\n\n```\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.axes_grid1 import make_axes_locatable\nimport matplotlib.gridspec as gridspec\n\n\nX = np.array([0., 0.5, 1., 1.5, 2., 2.5, 3., 3.5, 4.])\nX2 = np.array([122, 85, 63, 50, 23, 12, 7, 5, 2])\nY = np.cos(X*20)\nZ = np.sin(X*20)\n\nfig = plt.figure()\ngs = gridspec.GridSpec(1, 2)\nax1 = plt.subplot(gs[1])\nax2 = ax1.twiny()\n\nax1.set_xlim(-0.2, max(X)+0.2)\nplt.tick_params(axis='both', which='major', labelsize=10)\nax1.minorticks_on()\nax1.grid(b=True, which='major', color='gray', linestyle='--', lw=0.3)\n\nSC = ax1.scatter(X, Y, c=Z)\nax1.set_xlabel(\"Original x-axis\")\n\nax2.set_xlim(ax1.get_xlim())\nax2.set_xticks(X)\nax2.set_xticklabels(X2)\nax2.set_xlabel(\"Second x-axis\")\n\n# Colorbar.\nthe_divider = make_axes_locatable(ax1)\ncolor_axis = the_divider.append_axes(\"right\", size=\"2%\", pad=0.1)\ncbar = plt.colorbar(SC, cax=color_axis)\ncbar.set_label('B', fontsize=10, labelpad=4, y=0.5)\ncbar.ax.tick_params(labelsize=10)\n\nplt.show()\n```\n","author":{"url":"https://github.com/Gabriel-p","@type":"Person","name":"Gabriel-p"},"datePublished":"2016-01-24T23:37:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/5904/matplotlib/issues/5904"}
| 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:997c6e02-cc56-6353-b1be-ca38ea8aa02e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9C1E:240794:75966:96715:6A52E9F5 |
| html-safe-nonce | 77581a2cc32c02588b39a211209afe99d45b15a9480d5995476f02d5884abedf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QzFFOjI0MDc5NDo3NTk2Njo5NjcxNTo2QTUyRTlGNSIsInZpc2l0b3JfaWQiOiI2NDA3MjAzOTM1ODkxOTQxODc3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3eee6ff8c9853aab6313a6972bd43d894933b3c8d3d7f3cae01b19783f1d3b23 |
| hovercard-subject-tag | issue:128433699 |
| 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/5904/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4e8356abeef25eaf67b6e0354366245d428f32b1cf6d3168de105c1ad90a7e1f/matplotlib/matplotlib/issues/5904 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4e8356abeef25eaf67b6e0354366245d428f32b1cf6d3168de105c1ad90a7e1f/matplotlib/matplotlib/issues/5904 |
| og:image:alt | Bug report originated in SO post here: http://stackoverflow.com/q/34979781/1391441 I'm trying to add a second x axis to the top of a plot using twiny. If I make a simple scatter plot with no colorb... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Gabriel-p |
| 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