Title: Inconsistent behavior between Normalizers when input is Dataframe · Issue #16400 · matplotlib/matplotlib · GitHub
Open Graph Title: Inconsistent behavior between Normalizers when input is Dataframe · Issue #16400 · matplotlib/matplotlib
X Title: Inconsistent behavior between Normalizers when input is Dataframe · Issue #16400 · matplotlib/matplotlib
Description: Bug report Bug summary It seems matplotlib.colors.Normalize can work with pandas.Series inputs, whereas LogNorm can't. Code for reproduction import numpy as np import matplotlib.pyplot as plt from matplotlib.collections import LineCollec...
Open Graph Description: Bug report Bug summary It seems matplotlib.colors.Normalize can work with pandas.Series inputs, whereas LogNorm can't. Code for reproduction import numpy as np import matplotlib.pyplot as plt from ...
X Description: Bug report Bug summary It seems matplotlib.colors.Normalize can work with pandas.Series inputs, whereas LogNorm can't. Code for reproduction import numpy as np import matplotlib.pyplot as plt f...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/16400
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistent behavior between Normalizers when input is Dataframe","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\nIt seems matplotlib.colors.Normalize can work with pandas.Series inputs, whereas LogNorm can't.\r\n\r\n\u003c!--A short 1-2 sentences that succinctly describes the bug--\u003e\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```python\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\nfrom matplotlib.collections import LineCollection\r\nfrom matplotlib.colors import ListedColormap, BoundaryNorm, Normalize, LogNorm\r\nimport pandas as pd\r\n\r\nx = np.linspace(0, 3 * np.pi, 500)\r\ny = np.sin(x)\r\ndydx = np.linspace(0, 3 * np.pi, 500) +1 # first derivative\r\ndf= pd.DataFrame({'x':x,'y':y,'dydx':dydx})\r\npoints = np.array([df['x'], df['y']]).T.reshape(-1, 1, 2)\r\nsegments = np.concatenate([points[:-1], points[1:]], axis=1)\r\nfig, axs = plt.subplots()\r\n\r\n# Create a continuous norm to map from data points to colors\r\nnorm = LogNorm(df['dydx'].min(), df['dydx'].max())\r\nlc = LineCollection(segments, cmap='viridis', norm=norm)\r\n# Set the values used for colormapping\r\nlc.set_array(df['dydx'])\r\nlc.set_linewidth(2)\r\nline = axs.add_collection(lc)\r\nfig.colorbar(line, ax=axs)\r\naxs.set_xlim(x.min(), x.max())\r\naxs.set_ylim(-1.1, 1.1)\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\nTypeError: '\u003c=' not supported between instances of 'SingleBlockManager' and 'int'\r\n```\r\n\r\n**Expected outcome**\r\n\r\nNot sure about what's expected, but if I do `Normalize` instead of `LogNorm` it works, if I do `lc.set_array(df['dydx'].to_numpy())` instead of `lc.set_array(df['dydx'])` it also works. It's the combination of LogNorm and pd.Series is the problem.\r\n\r\n\u003c!--A description of the expected outcome from the code snippet--\u003e\r\n\u003c!--If this used to work in an earlier version of Matplotlib, please note the version it used to work on--\u003e\r\n\r\n**Matplotlib version**\r\n\u003c!--Please specify your platform and versions of the relevant libraries you are using:--\u003e\r\nversion 3.1.1\r\nmodule://ipykernel.pylab.backend_inline\r\n\r\n\u003c!--Please tell us how you installed matplotlib and python e.g., from source, pip, conda--\u003e\r\n\u003c!--If you installed from conda, please specify which channel you used if not the default--\u003e\r\n\r\n","author":{"url":"https://github.com/alicanb","@type":"Person","name":"alicanb"},"datePublished":"2020-02-03T20:22:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/16400/matplotlib/issues/16400"}
| 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:3a0573fc-1da2-6096-f582-0c1cd243a4a1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8388:1C38BA:8658A7:B383DE:6A517E58 |
| html-safe-nonce | e8e7bd29c5f83fc1159db9c5eadbbb51cc68202e07275581b912984a2312ad4b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Mzg4OjFDMzhCQTo4NjU4QTc6QjM4M0RFOjZBNTE3RTU4IiwidmlzaXRvcl9pZCI6IjMxOTQ3MjAxMTM5MDg2MTI2OTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8feae671f54e856c9edb2e3ba08e7785b3950678a2085818e089d0037108e283 |
| hovercard-subject-tag | issue:559312551 |
| 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/16400/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b96cc147d82cc3cdd231f163de93fb299923df377f268e19b7e1c48432af1a37/matplotlib/matplotlib/issues/16400 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b96cc147d82cc3cdd231f163de93fb299923df377f268e19b7e1c48432af1a37/matplotlib/matplotlib/issues/16400 |
| og:image:alt | Bug report Bug summary It seems matplotlib.colors.Normalize can work with pandas.Series inputs, whereas LogNorm can't. Code for reproduction import numpy as np import matplotlib.pyplot as plt from ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | alicanb |
| 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 | d01c62704ef24df49056c63892a149b775e1353d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width