Title: [Bug]: Corruption of 3D surface plot at log scale with negative or zero values (v3.11.0rc2) · Issue #31726 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Corruption of 3D surface plot at log scale with negative or zero values (v3.11.0rc2) · Issue #31726 · matplotlib/matplotlib
X Title: [Bug]: Corruption of 3D surface plot at log scale with negative or zero values (v3.11.0rc2) · Issue #31726 · matplotlib/matplotlib
Description: Bug summary Strange behavior of 3D surface plot axes in log scale if the data contains negative or zero values. With values >0 surface plot output is correct. ( Also tried with PyQt5 UI backend ) Code for reproduction import os, sys, re ...
Open Graph Description: Bug summary Strange behavior of 3D surface plot axes in log scale if the data contains negative or zero values. With values >0 surface plot output is correct. ( Also tried with PyQt5 UI backend ) C...
X Description: Bug summary Strange behavior of 3D surface plot axes in log scale if the data contains negative or zero values. With values >0 surface plot output is correct. ( Also tried with PyQt5 UI backend ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/31726
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Corruption of 3D surface plot at log scale with negative or zero values (v3.11.0rc2)","articleBody":"### Bug summary\n\nStrange behavior of 3D surface plot axes in log scale if the data contains negative or zero values. With values \u003e0 surface plot output is correct. ( Also tried with PyQt5 UI backend )\n\n\n\n\n\n### Code for reproduction\n\n```Python\nimport os, sys, re\nimport math as m\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom matplotlib.colors import LogNorm\n\n# path to test file with data\nfpath = r'D:\\Desktop\\MODES\\test NUMBER3 CL 0_03 -150 TO 120 STEP 5.TXT'\n\nfpath = os.path.normpath(fpath) \nfname = os.path.split(fpath)[1]\n\n# data search\npattern = r\"[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][-+]?\\d+)?\"\n\nheadlines = 0\nwith open(fpath, 'r', encoding='ansi') as (f):\n # head lines\n while not re.match(pattern, f.readline().split()[0]):\n headlines += 1\n \ndata = pd.read_table(fpath, sep='\\t', skiprows=headlines, \n names=['freq', 'temp', \"eps_real\", \"eps_imag\",\"sigma\"], \n encoding = \"ISO-8859-1\") \n \n# str to float\ntry:\n data.applymap(lambda x: float(x))\nexcept:\n # pandas ver. \u003e 2.1.0, map instead applymap !\n data.map(lambda x: float(x))\n \ndata.sort_values(by=[\"temp\", \"freq\"], ascending=[True, False], \n inplace=True)\n\n#----------------------------------------\n\nfig, axes = plt.subplots(2,3, figsize=(18, 12),subplot_kw={\"projection\": \"3d\"})\n\ny = data.temp.unique()\ny_len = len(y)\n\nfr = data.loc[data['freq'] == data['freq'][0]]\nx_len = (fr).index[1]\n\nx = (data['freq'].values)[0:x_len]\n\nz = data['eps_imag'].values\n\ncolormap = 'coolwarm' #, \nlog_norm = LogNorm(vmin=0.1, vmax=z.max())\n\ndef Plot_3D(ax):\n X, Y = np.meshgrid(x, y) \n Z = np.reshape(z, (y_len, x_len))\n ax.set_xscale('log')\n ax.set_yscale('log')\n ax.set_zscale('log')\n ax.set_xlabel(\"Freq\")\n ax.set_ylabel(\"Temp\")\n ax.set_zlabel(\"Eps\")\n ax.plot_surface(X, Y, Z, cmap= colormap, norm =log_norm)\n\naxes[0,0].remove()\n\naxes[0,1].set_title(\"X,Y,Z log scale\")\nPlot_3D(axes[0,1])\n\naxes[0,2].set_title(\"y \u003e= 0\")\ny = np.maximum(y, 0)\nPlot_3D(axes[0,2])\n\naxes[1,0].set_title(\"y and z \u003e= 0\")\nz = np.maximum(z, 0)\nPlot_3D(axes[1,0])\n\naxes[1,1].set_title(\"y \u003e= 1, z \u003e= 0\")\ny = np.maximum(y, 1)\nPlot_3D(axes[1,1])\n\naxes[1,2].set_title(\"y and z \u003e= 1\")\nz = np.maximum(z, 1)\nPlot_3D(axes[1,2])\n```\n\n### Actual outcome\n\n\n\u003cimg width=\"7598\" height=\"5040\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/9e7e5461-2832-40ce-a307-2107f568190d\" /\u003e\n\n### Expected outcome\n\nCorrect 3d surface plot even with negative of zero input values. (Probably with discarded negative data). And/Or warning about inappropriate data . \n\n### Additional information\n\nI created this test example to observe an issue.\n\nHi, I wrote a program for output experimental 3D dielectric spectra from text data (with a PyQt5 interface). To make the data more understandable, they should be displayed in log scale. Matplotlib v3.11.0rc2 just added this feature. I would like to thank everyone who contributes to matplotlib.\n\nThe input data file is a Eps values versus frequency and temperature. Temperature values in the test data (attached to report) range from -150 to 120°C. Eps values can be negative (although this is incorrect \"overshoot\", I used it to observe an issue).\n\nI noticed that, 3D surface plot axes are behaving strangely, in log scale if the data contains negative or zero values. \n\n\n\n[test NUMBER3 CL 0_03 -150 TO 120 STEP 5.TXT](https://github.com/user-attachments/files/28119242/test.NUMBER3.CL.0_03.-150.TO.120.STEP.5.TXT)\n\n### Operating system\n\nWindows 10 / 11\n\n### Matplotlib Version\n\n3.11.0rc2\n\n### Matplotlib Backend\n\nmodule://matplotlib_inline.backend_inline\n\n### Python version\n\n3.13 / 3.14.2\n\n### Jupyter version\n\n-\n\n### Installation\n\npip","author":{"url":"https://github.com/mrARGJ","@type":"Person","name":"mrARGJ"},"datePublished":"2026-05-21T20:51:13.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/31726/matplotlib/issues/31726"}
| 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:1987bf28-8bd3-dbb9-f5c1-deb9f26826bb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DB4A:2818E8:168BFC4:1E2CE35:6A52BC09 |
| html-safe-nonce | 0a02aa486a57ad91c883c64bb66265af1a4c57d4a84b3cf47ee2d6740b9486de |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQjRBOjI4MThFODoxNjhCRkM0OjFFMkNFMzU6NkE1MkJDMDkiLCJ2aXNpdG9yX2lkIjoiODgyMDIwMzMyOTcxNDA0MzkxNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | bc6d48ada5590433304ec5479a4e0e488ae520a18ac20330dc7c3fb3b1cf85e3 |
| hovercard-subject-tag | issue:4497827062 |
| 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/31726/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f0ba69c7391c4e8daabb710d414b7b9d05e2821eab2eb74455f176c45d83419f/matplotlib/matplotlib/issues/31726 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f0ba69c7391c4e8daabb710d414b7b9d05e2821eab2eb74455f176c45d83419f/matplotlib/matplotlib/issues/31726 |
| og:image:alt | Bug summary Strange behavior of 3D surface plot axes in log scale if the data contains negative or zero values. With values >0 surface plot output is correct. ( Also tried with PyQt5 UI backend ) C... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mrARGJ |
| 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