| 1 | { |
| 2 | "task_id": "matplotlib__matplotlib-22835", |
| 3 | "setup_info": { |
| 4 | "repo_path": "/media/media0/yuntong/SWE-bench/testbed/matplotlib__matplotlib/setup_matplotlib__matplotlib__3.5", |
| 5 | "env_name": "setup_matplotlib__matplotlib__3.5", |
| 6 | "pre_install": [], |
| 7 | "install": "python -m pip install -e .", |
| 8 | "test_cmd": "pytest --no-header -rA --tb=no -p no:cacheprovider lib/matplotlib/tests/test_artist.py" |
| 9 | }, |
| 10 | "task_info": { |
| 11 | "instance_id": "matplotlib__matplotlib-22835", |
| 12 | "base_commit": "c33557d120eefe3148ebfcf2e758ff2357966000", |
| 13 | "hints_text": "I think the correct fix is to specifically check for BoundaryNorm there and implement special logic to determine the positions of the neighboring intervals (on the BoundaryNorm) for that case.\nI tried returning the passed in `value` instead of the exception at https://github.com/matplotlib/matplotlib/blob/b2bb7be4ba343fcec6b1dbbffd7106e6af240221/lib/matplotlib/colors.py#L1829\r\n\r\n```python\r\nreturn value\r\n```\r\nand it seems to work. At least the error is gone and the values displayed in the plot (bottom right) when hovering with the mouse seem also right. But the numbers are rounded to only 1 digit in sci notation. So 19, 20 or 21 become 2.e+01.\r\nHope this helps.\r\n\nMaybe a more constructive suggestion for a change in https://github.com/matplotlib/matplotlib/blob/b2bb7be4ba343fcec6b1dbbffd7106e6af240221/lib/matplotlib/artist.py#L1280 that tries to fix the error:\r\n```python\r\nends = self.norm(np.array([self.norm.vmin, self.norm.vmax]))\r\nif np.isfinite(normed) and np.allclose(ends, 0.5, rtol=0.0, atol=0.5):\r\n```\r\nThis way, because `BoundaryNorm` doesn't map to 0...1 range but to the indices of the colors, the call to `BoundaryNorm.inverse()` is skipped and the default value for `g_sig_digits=3` is used.\r\nBut I'm not sure if there can be a case where `BoundaryNorm` actually maps its endpoints to 0...1, in which case all breaks down.\nhey, I just ran into this while plotting data... (interactivity doesn't stop but it plots a lot of issues) any updates?\n@raphaelquast no, this still needs someone to work on it.\r\n\r\nLabeled as a good first issue as there in no API design here (just returning an empty string is better than the current state).\nI can give a PR, that is based on my [last comment](https://github.com/matplotlib/matplotlib/issues/21915#issuecomment-992454625) a try. But my concerns/questions from then are still valid.\nAs this is all internal code, I think we should just do an `isinstance(norm, BoundaryNorm)` check and then act accordingly. There is already a bunch of instances of this in the colorbar code as precedence. \nAfter thinking about my suggestion again, I now understand why you prefer an `isinstace` check.\r\n(In my initial suggestion one would have to check if `ends` maps to (0,1) and if `normed` is in [0, 1] for the correct way to implement my idea. But these conditions are taylored to catch `BoundaryNorm` anyway, so why not do it directly.)\r\n\r\nHowever, I suggest using a try block after https://github.com/matplotlib/matplotlib/blob/c33557d120eefe3148ebfcf2e758ff2357966000/lib/matplotlib/artist.py#L1305\r\n```python\r\n# Midpoints of neighboring color intervals.\r\ntry:\r\n neighbors = self.norm.inverse(\r\n (int(normed * n) + np.array([0, 1])) / n)\r\nexcept ValueError:\r\n # non-invertible ScalarMappable\r\n```\r\nbecause `BoundaryNorm` raises a `ValueError` anyway and I assume this to be the case for all non-invertible `ScalarMappables`.\r\n(And the issue is the exception raised from `inverse`).\r\n\r\nThe question is:\r\nWhat to put in the `except`? So what is \"acting accordingly\" in this case?\r\nIf `BoundaryNorm` isn't invertible, how can we reliably get the data values of the midpoints of neighboring colors?\r\n\r\nI think it should be enough to get the boundaries themselves, instead of the midpoints (though both is possible) with something like:\r\n```python\r\ncur_idx = np.argmin(np.abs(self.norm.boundaries - data))\r\ncur_bound = self.norm.boundaries[cur_idx]\r\nneigh_idx = cur_idx + 1 if data > cur_bound else cur_idx - 1\r\nneighbors = self.norm.boundaries[\r\n np.array([cur_idx, neigh_idx])\r\n]\r\n```\r\nProblems with this code are:\r\n- `boundaries` property is specific to `BoundaryNorm`, isn't it? So we gained nothing by using `try .. except`\r\n- more checks are needed to cover all cases for `clip` and `extend` options of `BoundaryNorm` such that `neigh_idx` is always in bounds\r\n- for very coarse boundaries compared to data (ie: `boundaries = [0,1,2,3,4,5]; data = random(n)*5) the displayed values are always rounded to one significant digit. While in principle, this is expected (I believe), it results in inconsistency. In my example 0.111111 would be given as 0.1 and 0.001 as 0.001 and 1.234 would be just 1.\n> boundaries property is specific to BoundaryNorm, isn't it? So we gained nothing by using try .. except\r\n\r\nThis is one argument in favor of doing the `isinstance` check because then you can assert we _have_ a BoundaryNorm and can trust that you can access its state etc. One on hand, duck typeing is in general a Good Thing in Python and we should err on the side of being forgiving on input, but sometimes the complexity of it is more trouble than it is worth if you really only have 1 case that you are trying catch! \r\n\r\n> I assume this to be the case for all non-invertible ScalarMappables.\r\n\r\nHowever we only (at this point) are talking about a way to recover in the case of BoundaryNorm. Let everything else continue to fail and we will deal with those issues if/when they get reported.\nI think the correct fix is to specifically check for BoundaryNorm there and implement special logic to determine the positions of the neighboring intervals (on the BoundaryNorm) for that case.\nI tried returning the passed in `value` instead of the exception at https://github.com/matplotlib/matplotlib/blob/b2bb7be4ba343fcec6b1dbbffd7106e6af240221/lib/matplotlib/colors.py#L1829\r\n\r\n```python\r\nreturn value\r\n```\r\nand it seems to work. At least the error is gone and the values displayed in the plot (bottom right) when hovering with the mouse seem also right. But the numbers are rounded to only 1 digit in sci notation. So 19, 20 or 21 become 2.e+01.\r\nHope this helps.\r\n\nMaybe a more constructive suggestion for a change in https://github.com/matplotlib/matplotlib/blob/b2bb7be4ba343fcec6b1dbbffd7106e6af240221/lib/matplotlib/artist.py#L1280 that tries to fix the error:\r\n```python\r\nends = self.norm(np.array([self.norm.vmin, self.norm.vmax]))\r\nif np.isfinite(normed) and np.allclose(ends, 0.5, rtol=0.0, atol=0.5):\r\n```\r\nThis way, because `BoundaryNorm` doesn't map to 0...1 range but to the indices of the colors, the call to `BoundaryNorm.inverse()` is skipped and the default value for `g_sig_digits=3` is used.\r\nBut I'm not sure if there can be a case where `BoundaryNorm` actually maps its endpoints to 0...1, in which case all breaks down.\nhey, I just ran into this while plotting data... (interactivity doesn't stop but it plots a lot of issues) any updates?\n@raphaelquast no, this still needs someone to work on it.\r\n\r\nLabeled as a good first issue as there in no API design here (just returning an empty string is better than the current state).\nI can give a PR, that is based on my [last comment](https://github.com/matplotlib/matplotlib/issues/21915#issuecomment-992454625) a try. But my concerns/questions from then are still valid.\nAs this is all internal code, I think we should just do an `isinstance(norm, BoundaryNorm)` check and then act accordingly. There is already a bunch of instances of this in the colorbar code as precedence. \nAfter thinking about my suggestion again, I now understand why you prefer an `isinstace` check.\r\n(In my initial suggestion one would have to check if `ends` maps to (0,1) and if `normed` is in [0, 1] for the correct way to implement my idea. But these conditions are taylored to catch `BoundaryNorm` anyway, so why not do it directly.)\r\n\r\nHowever, I suggest using a try block after https://github.com/matplotlib/matplotlib/blob/c33557d120eefe3148ebfcf2e758ff2357966000/lib/matplotlib/artist.py#L1305\r\n```python\r\n# Midpoints of neighboring color intervals.\r\ntry:\r\n neighbors = self.norm.inverse(\r\n (int(normed * n) + np.array([0, 1])) / n)\r\nexcept ValueError:\r\n # non-invertible ScalarMappable\r\n```\r\nbecause `BoundaryNorm` raises a `ValueError` anyway and I assume this to be the case for all non-invertible `ScalarMappables`.\r\n(And the issue is the exception raised from `inverse`).\r\n\r\nThe question is:\r\nWhat to put in the `except`? So what is \"acting accordingly\" in this case?\r\nIf `BoundaryNorm` isn't invertible, how can we reliably get the data values of the midpoints of neighboring colors?\r\n\r\nI think it should be enough to get the boundaries themselves, instead of the midpoints (though both is possible) with something like:\r\n```python\r\ncur_idx = np.argmin(np.abs(self.norm.boundaries - data))\r\ncur_bound = self.norm.boundaries[cur_idx]\r\nneigh_idx = cur_idx + 1 if data > cur_bound else cur_idx - 1\r\nneighbors = self.norm.boundaries[\r\n np.array([cur_idx, neigh_idx])\r\n]\r\n```\r\nProblems with this code are:\r\n- `boundaries` property is specific to `BoundaryNorm`, isn't it? So we gained nothing by using `try .. except`\r\n- more checks are needed to cover all cases for `clip` and `extend` options of `BoundaryNorm` such that `neigh_idx` is always in bounds\r\n- for very coarse boundaries compared to data (ie: `boundaries = [0,1,2,3,4,5]; data = random(n)*5) the displayed values are always rounded to one significant digit. While in principle, this is expected (I believe), it results in inconsistency. In my example 0.111111 would be given as 0.1 and 0.001 as 0.001 and 1.234 would be just 1.\n> boundaries property is specific to BoundaryNorm, isn't it? So we gained nothing by using try .. except\r\n\r\nThis is one argument in favor of doing the `isinstance` check because then you can assert we _have_ a BoundaryNorm and can trust that you can access its state etc. One on hand, duck typeing is in general a Good Thing in Python and we should err on the side of being forgiving on input, but sometimes the complexity of it is more trouble than it is worth if you really only have 1 case that you are trying catch! \r\n\r\n> I assume this to be the case for all non-invertible ScalarMappables.\r\n\r\nHowever we only (at this point) are talking about a way to recover in the case of BoundaryNorm. Let everything else continue to fail and we will deal with those issues if/when they get reported.", |
| 14 | "created_at": "2022-04-12T23:13:58Z", |
| 15 | "test_patch": "diff --git a/lib/matplotlib/tests/test_artist.py b/lib/matplotlib/tests/test_artist.py\n--- a/lib/matplotlib/tests/test_artist.py\n+++ b/lib/matplotlib/tests/test_artist.py\n@@ -5,6 +5,8 @@\n \n import pytest\n \n+from matplotlib import cm\n+import matplotlib.colors as mcolors\n import matplotlib.pyplot as plt\n import matplotlib.patches as mpatches\n import matplotlib.lines as mlines\n@@ -372,3 +374,164 @@ class MyArtist4(MyArtist3):\n pass\n \n assert MyArtist4.set is MyArtist3.set\n+\n+\n+def test_format_cursor_data_BoundaryNorm():\n+ \"\"\"Test if cursor data is correct when using BoundaryNorm.\"\"\"\n+ X = np.empty((3, 3))\n+ X[0, 0] = 0.9\n+ X[0, 1] = 0.99\n+ X[0, 2] = 0.999\n+ X[1, 0] = -1\n+ X[1, 1] = 0\n+ X[1, 2] = 1\n+ X[2, 0] = 0.09\n+ X[2, 1] = 0.009\n+ X[2, 2] = 0.0009\n+\n+ # map range -1..1 to 0..256 in 0.1 steps\n+ fig, ax = plt.subplots()\n+ fig.suptitle(\"-1..1 to 0..256 in 0.1\")\n+ norm = mcolors.BoundaryNorm(np.linspace(-1, 1, 20), 256)\n+ img = ax.imshow(X, cmap='RdBu_r', norm=norm)\n+\n+ labels_list = [\n+ \"[0.9]\",\n+ \"[1.]\",\n+ \"[1.]\",\n+ \"[-1.0]\",\n+ \"[0.0]\",\n+ \"[1.0]\",\n+ \"[0.09]\",\n+ \"[0.009]\",\n+ \"[0.0009]\",\n+ ]\n+ for v, label in zip(X.flat, labels_list):\n+ # label = \"[{:-#.{}g}]\".format(v, cbook._g_sig_digits(v, 0.1))\n+ assert img.format_cursor_data(v) == label\n+\n+ plt.close()\n+\n+ # map range -1..1 to 0..256 in 0.01 steps\n+ fig, ax = plt.subplots()\n+ fig.suptitle(\"-1..1 to 0..256 in 0.01\")\n+ cmap = cm.get_cmap('RdBu_r', 200)\n+ norm = mcolors.BoundaryNorm(np.linspace(-1, 1, 200), 200)\n+ img = ax.imshow(X, cmap=cmap, norm=norm)\n+\n+ labels_list = [\n+ \"[0.90]\",\n+ \"[0.99]\",\n+ \"[1.0]\",\n+ \"[-1.00]\",\n+ \"[0.00]\",\n+ \"[1.00]\",\n+ \"[0.09]\",\n+ \"[0.009]\",\n+ \"[0.0009]\",\n+ ]\n+ for v, label in zip(X.flat, labels_list):\n+ # label = \"[{:-#.{}g}]\".format(v, cbook._g_sig_digits(v, 0.01))\n+ assert img.format_cursor_data(v) == label\n+\n+ plt.close()\n+\n+ # map range -1..1 to 0..256 in 0.01 steps\n+ fig, ax = plt.subplots()\n+ fig.suptitle(\"-1..1 to 0..256 in 0.001\")\n+ cmap = cm.get_cmap('RdBu_r', 2000)\n+ norm = mcolors.BoundaryNorm(np.linspace(-1, 1, 2000), 2000)\n+ img = ax.imshow(X, cmap=cmap, norm=norm)\n+\n+ labels_list = [\n+ \"[0.900]\",\n+ \"[0.990]\",\n+ \"[0.999]\",\n+ \"[-1.000]\",\n+ \"[0.000]\",\n+ \"[1.000]\",\n+ \"[0.090]\",\n+ \"[0.009]\",\n+ \"[0.0009]\",\n+ ]\n+ for v, label in zip(X.flat, labels_list):\n+ # label = \"[{:-#.{}g}]\".format(v, cbook._g_sig_digits(v, 0.001))\n+ assert img.format_cursor_data(v) == label\n+\n+ plt.close()\n+\n+ # different testing data set with\n+ # out of bounds values for 0..1 range\n+ X = np.empty((7, 1))\n+ X[0] = -1.0\n+ X[1] = 0.0\n+ X[2] = 0.1\n+ X[3] = 0.5\n+ X[4] = 0.9\n+ X[5] = 1.0\n+ X[6] = 2.0\n+\n+ labels_list = [\n+ \"[-1.0]\",\n+ \"[0.0]\",\n+ \"[0.1]\",\n+ \"[0.5]\",\n+ \"[0.9]\",\n+ \"[1.0]\",\n+ \"[2.0]\",\n+ ]\n+\n+ fig, ax = plt.subplots()\n+ fig.suptitle(\"noclip, neither\")\n+ norm = mcolors.BoundaryNorm(\n+ np.linspace(0, 1, 4, endpoint=True), 256, clip=False, extend='neither')\n+ img = ax.imshow(X, cmap='RdBu_r', norm=norm)\n+ for v, label in zip(X.flat, labels_list):\n+ # label = \"[{:-#.{}g}]\".format(v, cbook._g_sig_digits(v, 0.33))\n+ assert img.format_cursor_data(v) == label\n+\n+ plt.close()\n+\n+ fig, ax = plt.subplots()\n+ fig.suptitle(\"noclip, min\")\n+ norm = mcolors.BoundaryNorm(\n+ np.linspace(0, 1, 4, endpoint=True), 256, clip=False, extend='min')\n+ img = ax.imshow(X, cmap='RdBu_r', norm=norm)\n+ for v, label in zip(X.flat, labels_list):\n+ # label = \"[{:-#.{}g}]\".format(v, cbook._g_sig_digits(v, 0.33))\n+ assert img.format_cursor_data(v) == label\n+\n+ plt.close()\n+\n+ fig, ax = plt.subplots()\n+ fig.suptitle(\"noclip, max\")\n+ norm = mcolors.BoundaryNorm(\n+ np.linspace(0, 1, 4, endpoint=True), 256, clip=False, extend='max')\n+ img = ax.imshow(X, cmap='RdBu_r', norm=norm)\n+ for v, label in zip(X.flat, labels_list):\n+ # label = \"[{:-#.{}g}]\".format(v, cbook._g_sig_digits(v, 0.33))\n+ assert img.format_cursor_data(v) == label\n+\n+ plt.close()\n+\n+ fig, ax = plt.subplots()\n+ fig.suptitle(\"noclip, both\")\n+ norm = mcolors.BoundaryNorm(\n+ np.linspace(0, 1, 4, endpoint=True), 256, clip=False, extend='both')\n+ img = ax.imshow(X, cmap='RdBu_r', norm=norm)\n+ for v, label in zip(X.flat, labels_list):\n+ # label = \"[{:-#.{}g}]\".format(v, cbook._g_sig_digits(v, 0.33))\n+ assert img.format_cursor_data(v) == label\n+\n+ plt.close()\n+\n+ fig, ax = plt.subplots()\n+ fig.suptitle(\"clip, neither\")\n+ norm = mcolors.BoundaryNorm(\n+ np.linspace(0, 1, 4, endpoint=True), 256, clip=True, extend='neither')\n+ img = ax.imshow(X, cmap='RdBu_r', norm=norm)\n+ for v, label in zip(X.flat, labels_list):\n+ # label = \"[{:-#.{}g}]\".format(v, cbook._g_sig_digits(v, 0.33))\n+ assert img.format_cursor_data(v) == label\n+\n+ plt.close()\n", |
| 16 | "repo": "matplotlib/matplotlib", |
| 17 | "problem_statement": "[Bug]: scalar mappable format_cursor_data crashes on BoundarNorm\n### Bug summary\r\n\r\nIn 3.5.0 if you do:\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\nimport matplotlib as mpl\r\n\r\nfig, ax = plt.subplots()\r\nnorm = mpl.colors.BoundaryNorm(np.linspace(-4, 4, 5), 256)\r\nX = np.random.randn(10, 10)\r\npc = ax.imshow(X, cmap='RdBu_r', norm=norm)\r\n```\r\n\r\nand mouse over the image, it crashes with\r\n\r\n```\r\nFile \"/Users/jklymak/matplotlib/lib/matplotlib/artist.py\", line 1282, in format_cursor_data\r\n neighbors = self.norm.inverse(\r\n File \"/Users/jklymak/matplotlib/lib/matplotlib/colors.py\", line 1829, in inverse\r\n raise ValueError(\"BoundaryNorm is not invertible\")\r\nValueError: BoundaryNorm is not invertible\r\n```\r\n\r\nand interaction stops. \r\n\r\nNot sure if we should have a special check here, a try-except, or actually just make BoundaryNorm approximately invertible. \r\n\r\n\r\n### Matplotlib Version\r\n\r\nmain 3.5.0\r\n\r\n\n[Bug]: scalar mappable format_cursor_data crashes on BoundarNorm\n### Bug summary\r\n\r\nIn 3.5.0 if you do:\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\nimport matplotlib as mpl\r\n\r\nfig, ax = plt.subplots()\r\nnorm = mpl.colors.BoundaryNorm(np.linspace(-4, 4, 5), 256)\r\nX = np.random.randn(10, 10)\r\npc = ax.imshow(X, cmap='RdBu_r', norm=norm)\r\n```\r\n\r\nand mouse over the image, it crashes with\r\n\r\n```\r\nFile \"/Users/jklymak/matplotlib/lib/matplotlib/artist.py\", line 1282, in format_cursor_data\r\n neighbors = self.norm.inverse(\r\n File \"/Users/jklymak/matplotlib/lib/matplotlib/colors.py\", line 1829, in inverse\r\n raise ValueError(\"BoundaryNorm is not invertible\")\r\nValueError: BoundaryNorm is not invertible\r\n```\r\n\r\nand interaction stops. \r\n\r\nNot sure if we should have a special check here, a try-except, or actually just make BoundaryNorm approximately invertible. \r\n\r\n\r\n### Matplotlib Version\r\n\r\nmain 3.5.0\r\n\r\n\n", |
| 18 | "version": "3.5", |
| 19 | "FAIL_TO_PASS": [ |
| 20 | "lib/matplotlib/tests/test_artist.py::test_format_cursor_data_BoundaryNorm" |
| 21 | ], |
| 22 | "PASS_TO_PASS": [ |
| 23 | "lib/matplotlib/tests/test_artist.py::test_None_zorder", |
| 24 | "lib/matplotlib/tests/test_artist.py::test_artist_inspector_get_aliases", |
| 25 | "lib/matplotlib/tests/test_artist.py::test_artist_inspector_get_valid_values[*arg", |
| 26 | "lib/matplotlib/tests/test_artist.py::test_artist_inspector_get_valid_values[-unknown]", |
| 27 | "lib/matplotlib/tests/test_artist.py::test_artist_inspector_get_valid_values[..", |
| 28 | "lib/matplotlib/tests/test_artist.py::test_artist_inspector_get_valid_values[ACCEPTS:", |
| 29 | "lib/matplotlib/tests/test_artist.py::test_artist_inspector_get_valid_values[arg", |
| 30 | "lib/matplotlib/tests/test_artist.py::test_callbacks", |
| 31 | "lib/matplotlib/tests/test_artist.py::test_clipping[pdf]", |
| 32 | "lib/matplotlib/tests/test_artist.py::test_clipping[png]", |
| 33 | "lib/matplotlib/tests/test_artist.py::test_clipping_zoom[png]", |
| 34 | "lib/matplotlib/tests/test_artist.py::test_collection_transform_of_none", |
| 35 | "lib/matplotlib/tests/test_artist.py::test_cull_markers", |
| 36 | "lib/matplotlib/tests/test_artist.py::test_default_edges[png]", |
| 37 | "lib/matplotlib/tests/test_artist.py::test_hatching[pdf]", |
| 38 | "lib/matplotlib/tests/test_artist.py::test_hatching[png]", |
| 39 | "lib/matplotlib/tests/test_artist.py::test_patch_transform_of_none", |
| 40 | "lib/matplotlib/tests/test_artist.py::test_properties", |
| 41 | "lib/matplotlib/tests/test_artist.py::test_remove", |
| 42 | "lib/matplotlib/tests/test_artist.py::test_set_alpha", |
| 43 | "lib/matplotlib/tests/test_artist.py::test_set_alpha_for_array", |
| 44 | "lib/matplotlib/tests/test_artist.py::test_set_is_overwritten", |
| 45 | "lib/matplotlib/tests/test_artist.py::test_set_signature", |
| 46 | "lib/matplotlib/tests/test_artist.py::test_setp" |
| 47 | ], |
| 48 | "environment_setup_commit": "de98877e3dc45de8dd441d008f23d88738dc015d", |
| 49 | "patch": "diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py\n--- a/lib/matplotlib/artist.py\n+++ b/lib/matplotlib/artist.py\n@@ -12,6 +12,7 @@\n \n import matplotlib as mpl\n from . import _api, cbook\n+from .colors import BoundaryNorm\n from .cm import ScalarMappable\n from .path import Path\n from .transforms import (Bbox, IdentityTransform, Transform, TransformedBbox,\n@@ -1303,10 +1304,20 @@ def format_cursor_data(self, data):\n return \"[]\"\n normed = self.norm(data)\n if np.isfinite(normed):\n- # Midpoints of neighboring color intervals.\n- neighbors = self.norm.inverse(\n- (int(self.norm(data) * n) + np.array([0, 1])) / n)\n- delta = abs(neighbors - data).max()\n+ if isinstance(self.norm, BoundaryNorm):\n+ # not an invertible normalization mapping\n+ cur_idx = np.argmin(np.abs(self.norm.boundaries - data))\n+ neigh_idx = max(0, cur_idx - 1)\n+ # use max diff to prevent delta == 0\n+ delta = np.diff(\n+ self.norm.boundaries[neigh_idx:cur_idx + 2]\n+ ).max()\n+\n+ else:\n+ # Midpoints of neighboring color intervals.\n+ neighbors = self.norm.inverse(\n+ (int(normed * n) + np.array([0, 1])) / n)\n+ delta = abs(neighbors - data).max()\n g_sig_digits = cbook._g_sig_digits(data, delta)\n else:\n g_sig_digits = 3 # Consistent with default below.\n", |
| 50 | "pr_link": "https://github.com/matplotlib/matplotlib/pull/22835" |
| 51 | } |
| 52 | } |