GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||
GeezerVison is showing github.com — [Bug]: a scalar-only custom scale silently blanks all 3D data instead of drawing it · Issue #32129 · matplotlib/matplotlib Open DescriptionBug summaryA third-party scale whose
try: vmin, vmax = self.limit_range_for_scale(arr, arr, minpos=1e-300) except (TypeError, ValueError): result = np.zeros(arr.shape, dtype=bool)
The scalar form is not an unusual thing to write. It is what return (minpos if vmin <= 0 else vmin, minpos if vmax <= 0 else vmax)
Code for reproductionimport matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np from matplotlib.scale import ScaleBase, register_scale from matplotlib.transforms import IdentityTransform from matplotlib.ticker import AutoLocator, ScalarFormatter class ScalarOnlyScale(ScaleBase): name = "scalaronly" def get_transform(self): return IdentityTransform() def set_default_locators_and_formatters(self, axis): axis.set_major_locator(AutoLocator()) axis.set_major_formatter(ScalarFormatter()) def limit_range_for_scale(self, vmin, vmax, minpos): # The same shape as LogScale.limit_range_for_scale. return (minpos if vmin <= 0 else vmin, minpos if vmax <= 0 else vmax) register_scale(ScalarOnlyScale) xs = np.array([0., 1., 2., 3.]) ys = np.array([0., 1., 2., 3.]) zs = np.array([1., 2., 3., 4.]) # all finite, all positive fig = plt.figure() ax = fig.add_subplot(projection="3d") line, = ax.plot(xs, ys, zs) ax.scatter(xs, ys, zs) ax.set_zscale("scalaronly") fig.canvas.draw() print(np.asarray(line.get_data())) # all nan fig.savefig("blank.png") Actual outcomeThe line and the points are gone. Nothing is raised. Measured on the same figure with and without
Directly: >>> s = ScalarOnlyScale(None) >>> s.val_in_range(5.0) True >>> s.val_in_range(np.array([1., 2., 3.])) array([False, False, False]) The scalar answer is right and the array answer is the opposite of right. Expected outcomeThe data is drawn. Every value is finite and inside the scale's domain, and the scalar path agrees. 2D plots on the same scale are unaffected, because Additional information
The failure mode is what makes this worth reporting rather than the incompatibility itself. Falling back to "no value is in range" turns an unsupported call signature into deleted data. The safer direction is to fall back to the scalar semantics the implementation does support: except (TypeError, ValueError): result = np.array( [self.val_in_range(v) for v in np.atleast_1d(arr).ravel()] ).reshape(arr.shape) which returns Two smaller things noticed alongside:
I have not opened a PR for this one, since changing the fallback is a decision about Found while investigating #32127, which comes from the same change chain but is a different failure. Operating systemLinux (Debian 13) Matplotlib Version3.11.1 Matplotlib BackendAgg Python version3.14 Jupyter versionN/A Installationpip Activity
MetadataMetadataAssigneesTypeProjectsMilestoneRelationshipsDevelopmentIssue actions | |||||||||
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |