{"instance_id": "matplotlib__matplotlib-14623", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py\nindex 209a3f92ce..9462269294 100644\n--- a/lib/matplotlib/ticker.py\n+++ b/lib/matplotlib/ticker.py\n@@ -2379,7 +2379,8 @@ class LogLocator(Locator):\n         if not np.isfinite(vmin) or not np.isfinite(vmax):\n             return 1, 10  # initial range, no data plotted yet\n \n-        if vmin > vmax:\n+        swapped = vmin > vmax\n+        if swapped:\n             vmin, vmax = vmax, vmin\n         if vmax <= 0:\n             cbook._warn_external(\n@@ -2395,6 +2396,8 @@ class LogLocator(Locator):\n         if vmin == vmax:\n             vmin = _decade_less(vmin, self._base)\n             vmax = _decade_greater(vmax, self._base)\n+        if swapped:\n+            vmin, vmax = vmax, vmin\n         return vmin, vmax\n \n \n@@ -2624,7 +2627,8 @@ class LogitLocator(Locator):\n         if not np.isfinite(vmin) or not np.isfinite(vmax):\n             return initial_range  # no data plotted yet\n \n-        if vmin > vmax:\n+        swapped = vmin > vmax\n+        if swapped:\n             vmin, vmax = vmax, vmin\n \n         # what to do if a window beyond ]0, 1[ is chosen\n@@ -2647,6 +2651,8 @@ class LogitLocator(Locator):\n         if vmin == vmax:\n             return 0.1 * vmin, 1 - 0.1 * vmin\n \n+        if swapped:\n+            vmin, vmax = vmax, vmin\n         return vmin, vmax\n \n \n", "model": "claude-sonnet-5-5", "steps": 8, "finished": true, "patch_lines": 42, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 42, "steps": 8}], "ms": 21926}
{"instance_id": "matplotlib__matplotlib-20488", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py\nindex 95bb42d75c..b710e7ac09 100644\n--- a/lib/matplotlib/image.py\n+++ b/lib/matplotlib/image.py\n@@ -532,9 +532,9 @@ class _ImageBase(martist.Artist, cm.ScalarMappable):\n                 # we have re-set the vmin/vmax to account for small errors\n                 # that may have moved input values in/out of range\n                 s_vmin, s_vmax = vrange\n-                if isinstance(self.norm, mcolors.LogNorm):\n-                    if s_vmin < 0:\n-                        s_vmin = max(s_vmin, np.finfo(scaled_dtype).eps)\n+                if isinstance(self.norm, mcolors.LogNorm) and s_vmin <= 0:\n+                    # Don't give 0 or negative values to LogNorm\n+                    s_vmin = np.finfo(scaled_dtype).eps\n                 with cbook._setattr_cm(self.norm,\n                                        vmin=s_vmin,\n                                        vmax=s_vmax,\n", "model": "claude-sonnet-5-5", "steps": 5, "finished": true, "patch_lines": 17, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 17, "steps": 5}], "ms": 16206}
{"instance_id": "matplotlib__matplotlib-20676", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py\nindex a199e45d40..a92b877ed0 100644\n--- a/lib/matplotlib/widgets.py\n+++ b/lib/matplotlib/widgets.py\n@@ -2149,7 +2149,9 @@ class SpanSelector(_SelectorWidget):\n                                visible=False,\n                                **self._rectprops)\n \n-        self.ax.add_patch(self._rect)\n+        # Use add_artist rather than add_patch so that the initial (0, 0)\n+        # position of the rectangle does not affect the axes data limits.\n+        self.ax.add_artist(self._rect)\n         if len(self.artists) > 0:\n             self.artists[0] = self._rect\n         else:\n@@ -2366,10 +2368,19 @@ class ToolLineHandles:\n             line_props = {}\n         line_props.update({'visible': False, 'animated': useblit})\n \n-        line_fun = ax.axvline if self.direction == 'horizontal' else ax.axhline\n         self._line_props = line_props\n \n-        self.artists = [line_fun(p, **line_props) for p in positions]\n+        # Add the lines with add_artist rather than axvline/axhline so that\n+        # their (initial) positions do not affect the axes data limits.\n+        if self.direction == 'horizontal':\n+            trans = ax.get_xaxis_transform()\n+            make_line = lambda p: Line2D([p, p], [0, 1], transform=trans,\n+                                         **line_props)\n+        else:\n+            trans = ax.get_yaxis_transform()\n+            make_line = lambda p: Line2D([0, 1], [p, p], transform=trans,\n+                                         **line_props)\n+        self.artists = [ax.add_artist(make_line(p)) for p in positions]\n \n     @property\n     def positions(self):\n", "model": "claude-sonnet-5-5", "steps": 15, "finished": true, "patch_lines": 37, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 37, "steps": 15}], "ms": 58602}
{"instance_id": "matplotlib__matplotlib-20826", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py\nindex 802fd3c997..7e1910b33f 100644\n--- a/lib/matplotlib/axes/_base.py\n+++ b/lib/matplotlib/axes/_base.py\n@@ -650,6 +650,7 @@ class _AxesBase(martist.Artist):\n                 axis.callbacks.connect(\n                     'units', self._unit_change_handler(name)))\n \n+    def _reset_tick_params_from_rc(self):\n         rcParams = mpl.rcParams\n         self.tick_params(\n             top=rcParams['xtick.top'] and rcParams['xtick.minor.top'],\n@@ -1192,6 +1193,20 @@ class _AxesBase(martist.Artist):\n         xaxis_visible = self.xaxis.get_visible()\n         yaxis_visible = self.yaxis.get_visible()\n \n+        # stash tick/label visibility of shared axes (e.g. set by label_outer)\n+        _keys = ('tick1On', 'tick2On', 'label1On', 'label2On')\n+\n+        def _stash(axis):\n+            return {which: {k: kw[k] for k in _keys if k in kw}\n+                    for which, kw in [('major', axis._major_tick_kw),\n+                                      ('minor', axis._minor_tick_kw)]}\n+\n+        shared_ticks = {}\n+        if getattr(self, '_sharex', None) is not None:\n+            shared_ticks['x'] = _stash(self.xaxis)\n+        if getattr(self, '_sharey', None) is not None:\n+            shared_ticks['y'] = _stash(self.yaxis)\n+\n         self.xaxis.clear()\n         self.yaxis.clear()\n \n@@ -1297,6 +1312,13 @@ class _AxesBase(martist.Artist):\n \n         self.set_axis_on()\n \n+        self._reset_tick_params_from_rc()\n+        for name, saved in shared_ticks.items():\n+            axis = self.xaxis if name == 'x' else self.yaxis\n+            axis._major_tick_kw.update(saved['major'])\n+            axis._minor_tick_kw.update(saved['minor'])\n+            axis.reset_ticks()\n+\n         self.xaxis.set_clip_path(self.patch)\n         self.yaxis.set_clip_path(self.patch)\n \n", "model": "claude-sonnet-5-5", "steps": 12, "finished": true, "patch_lines": 47, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 47, "steps": 12}], "ms": 40885}
{"instance_id": "matplotlib__matplotlib-20859", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py\nindex f1a6711cb6..0761b32a11 100644\n--- a/lib/matplotlib/figure.py\n+++ b/lib/matplotlib/figure.py\n@@ -1986,6 +1986,7 @@ class SubFigure(FigureBase):\n         self._subplotspec = subplotspec\n         self._parent = parent\n         self.figure = parent.figure\n+        self._cachedRenderer = None\n         # subfigures use the parent axstack\n         self._axstack = parent._axstack\n         self.subplotpars = parent.subplotpars\ndiff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py\nindex 44ab024698..1b8cee8250 100644\n--- a/lib/matplotlib/legend.py\n+++ b/lib/matplotlib/legend.py\n@@ -360,7 +360,7 @@ class Legend(Artist):\n         \"\"\"\n         # local import only to avoid circularity\n         from matplotlib.axes import Axes\n-        from matplotlib.figure import Figure\n+        from matplotlib.figure import FigureBase\n \n         super().__init__()\n \n@@ -434,7 +434,7 @@ class Legend(Artist):\n             self.isaxes = True\n             self.axes = parent\n             self.set_figure(parent.figure)\n-        elif isinstance(parent, Figure):\n+        elif isinstance(parent, FigureBase):\n             self.isaxes = False\n             self.set_figure(parent)\n         else:\n", "model": "claude-sonnet-5-5", "steps": 16, "finished": true, "patch_lines": 34, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 2, "diff_lines": 34, "steps": 16}], "ms": 45932}
{"instance_id": "matplotlib__matplotlib-22871", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py\nindex 4d8ddf3ee5..0aa6c9a413 100644\n--- a/lib/matplotlib/dates.py\n+++ b/lib/matplotlib/dates.py\n@@ -797,7 +797,10 @@ class ConciseDateFormatter(ticker.Formatter):\n         # 3: hours, 4: minutes, 5: seconds, 6: microseconds\n         for level in range(5, -1, -1):\n             if len(np.unique(tickdate[:, level])) > 1:\n-                if level < 2:\n+                # Years are labelled directly at level 0; at level 1 the year\n+                # is only shown (on the January tick) if January is present.\n+                if level == 0 or (level == 1 and\n+                                  (tickdate[:, 1] == 1).any()):\n                     show_offset = False\n                 break\n             elif level == 0:\n", "model": "claude-sonnet-5-5", "steps": 7, "finished": true, "patch_lines": 16, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 16, "steps": 7}], "ms": 28119}
{"instance_id": "matplotlib__matplotlib-23299", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py\nindex c268a56724..a3ad346da6 100644\n--- a/lib/matplotlib/__init__.py\n+++ b/lib/matplotlib/__init__.py\n@@ -1087,7 +1087,11 @@ def rc_context(rc=None, fname=None):\n              plt.plot(x, y)  # uses 'print.rc'\n \n     \"\"\"\n-    orig = rcParams.copy()\n+    # Don't restore the backend: it may have been resolved (auto-sentinel) in\n+    # the context, and reverting would trigger another backend switch that\n+    # closes all figures.\n+    orig = dict(rcParams.copy())\n+    del orig['backend']\n     try:\n         if fname:\n             rc_file(fname)\n", "model": "claude-sonnet-5-5", "steps": 9, "finished": true, "patch_lines": 17, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 17, "steps": 9}], "ms": 22369}
{"instance_id": "matplotlib__matplotlib-23314", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py\nindex 9db44b7994..5479bc1af0 100644\n--- a/lib/mpl_toolkits/mplot3d/axes3d.py\n+++ b/lib/mpl_toolkits/mplot3d/axes3d.py\n@@ -387,6 +387,8 @@ class Axes3D(Axes):\n \n     @martist.allow_rasterization\n     def draw(self, renderer):\n+        if not self.get_visible():\n+            return\n         self._unstale_viewLim()\n \n         # draw the background patch\n", "model": "claude-sonnet-5-5", "steps": 6, "finished": true, "patch_lines": 13, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 13, "steps": 6}], "ms": 14847}
{"instance_id": "matplotlib__matplotlib-23412", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py\nindex e062249589..0c893aac3a 100644\n--- a/lib/matplotlib/patches.py\n+++ b/lib/matplotlib/patches.py\n@@ -586,10 +586,7 @@ class Patch(artist.Artist):\n         # docstring inherited\n         if not self.get_visible():\n             return\n-        # Patch has traditionally ignored the dashoffset.\n-        with cbook._setattr_cm(\n-                 self, _dash_pattern=(0, self._dash_pattern[1])), \\\n-             self._bind_draw_path_function(renderer) as draw_path:\n+        with self._bind_draw_path_function(renderer) as draw_path:\n             path = self.get_path()\n             transform = self.get_transform()\n             tpath = transform.transform_path_non_affine(path)\n", "model": "claude-sonnet-5-5", "steps": 7, "finished": true, "patch_lines": 16, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 16, "steps": 7}], "ms": 16839}
{"instance_id": "matplotlib__matplotlib-23476", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py\nindex c55864243a..65b9850775 100644\n--- a/lib/matplotlib/figure.py\n+++ b/lib/matplotlib/figure.py\n@@ -3026,6 +3026,9 @@ class Figure(FigureBase):\n         # add version information to the state\n         state['__mpl_version__'] = mpl.__version__\n \n+        # discard any changes to the dpi due to pixel ratio changes\n+        state[\"_dpi\"] = state.get('_original_dpi', state['_dpi'])\n+\n         # check whether the figure manager (if any) is registered with pyplot\n         from matplotlib import _pylab_helpers\n         if self.canvas.manager in _pylab_helpers.Gcf.figs.values():\n", "model": "claude-sonnet-5-5", "steps": 10, "finished": true, "patch_lines": 14, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 14, "steps": 10}], "ms": 27371}
