Repository: matplotlib/matplotlib

Issue:
[Bug]: get_default_filename removes '0' from file name instead of '\0' from window title
### Bug summary

removed_chars = r'<>:"/\|?*\0 ' in get_default_filename has r before string so escape char '\' is ignored in the string, so it just replace regular zero character '0' with '_'
just replace removed_chars = r'<>:"/\|?*\0 ' with removed_chars = '<>:"/\\|?*\0 '
https://github.com/matplotlib/matplotlib/blob/c887ecbc753763ff4232041cc84c9c6a44d20fd4/lib/matplotlib/backend_bases.py#L2223


### Code for reproduction

```Python
# create a plot and set title to sth with 0 in it
fig.canvas.set_window_title('120')
# then click on save button
```

### Actual outcome

It shows save dialog with 12_.png file name

### Expected outcome

It should show save dialog with 120.png file name

### Additional information

_No response_

### Operating system

_No response_

### Matplotlib Version

All

### Matplotlib Backend

All

### Python version

All

### Jupyter version

All

### Installation

None


Discussion:

Patch:
diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py
index 62c26a90a91c..2c22808800a8 100644
--- a/lib/matplotlib/backend_bases.py
+++ b/lib/matplotlib/backend_bases.py
@@ -2220,7 +2220,7 @@ def get_default_filename(self):
         # Characters to be avoided in a NT path:
         # https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#naming_conventions
         # plus ' '
-        removed_chars = r'<>:"/\|?*\0 '
+        removed_chars = '<>:"/\\|?*\0 '
         default_basename = default_basename.translate(
             {ord(c): "_" for c in removed_chars})
         default_filetype = self.get_default_filetype()
@@ -2730,23 +2730,24 @@ def resize(self, w, h):
         """For GUI backends, resize the window (in physical pixels)."""
 
     def get_window_title(self):
-        """
-        Return the title text of the window containing the figure, or None
-        if there is no window (e.g., a PS backend).
-        """
-        return 'image'
+        """Return the title text of the window containing the figure."""
+        return self._window_title
 
     def set_window_title(self, title):
         """
         Set the title text of the window containing the figure.
 
-        This has no effect for non-GUI (e.g., PS) backends.
-
         Examples
         --------
         >>> fig = plt.figure()
         >>> fig.canvas.manager.set_window_title('My figure')
         """
+        # This attribute is not defined in __init__ (but __init__ calls this
+        # setter), as derived classes (real GUI managers) will store this
+        # information directly on the widget; only the base (non-GUI) manager
+        # class needs a specific attribute for it (so that filename escaping
+        # can be checked in the test suite).
+        self._window_title = title
 
 
 cursors = tools.cursors


Test patch:
diff --git a/lib/matplotlib/tests/test_backend_bases.py b/lib/matplotlib/tests/test_backend_bases.py
index ef5a52d988bb..30db5ebf5511 100644
--- a/lib/matplotlib/tests/test_backend_bases.py
+++ b/lib/matplotlib/tests/test_backend_bases.py
@@ -64,7 +64,10 @@ def test_canvas_ctor():
 
 
 def test_get_default_filename():
-    assert plt.figure().canvas.get_default_filename() == 'image.png'
+    fig = plt.figure()
+    assert fig.canvas.get_default_filename() == "Figure_1.png"
+    fig.canvas.manager.set_window_title("0:1/2<3")
+    assert fig.canvas.get_default_filename() == "0_1_2_3.png"
 
 
 def test_canvas_change():