Repository: scikit-image/scikit-image

Issue:
Fix warnings regarding invalid escape sequences.
Fixes #4413 


Discussion:
Thank you @tirkarthi !
Thanks for the review and merge :)
This Fix introduces a new bug:
Raw strings don't accept escape sequences. Therefore two examples are messed up now:

- plot_denoise_wavelet.py has 3 raw strings that need to be split into raw strings and regular strings
https://github.com/scikit-image/scikit-image/pull/4414/files#diff-5c59b3d49744f9b5dccf3adee829c42eR88
should look like:
  ```py
  ax[0, 2].set_title(
      ('Wavelet denoising\n(VisuShrink, ' r'$\sigma=\sigma_{est}$' ')\n'
       f'PSNR={psnr_visushrink:0.4g}'))
  ```

- plot_nonlocal_means.py has 2 errors
https://github.com/scikit-image/scikit-image/pull/4414/files#diff-cf567bb7df257049be9c7302e63eaac6R83


Resolving patch:
diff --git a/doc/examples/filters/plot_denoise_wavelet.py b/doc/examples/filters/plot_denoise_wavelet.py
--- a/doc/examples/filters/plot_denoise_wavelet.py
+++ b/doc/examples/filters/plot_denoise_wavelet.py
@@ -85,21 +85,21 @@
 ax[0, 2].imshow(im_visushrink)
 ax[0, 2].axis('off')
 ax[0, 2].set_title(
-    (r'Wavelet denoising\n(VisuShrink, $\sigma=\sigma_{est}$)\n'
-     'PSNR=%0.4g' % psnr_visushrink))
+    'Wavelet denoising\n(VisuShrink, $\\sigma=\\sigma_{est}$)\n'
+     'PSNR=%0.4g' % psnr_visushrink)
 ax[1, 0].imshow(original)
 ax[1, 0].axis('off')
 ax[1, 0].set_title('Original')
 ax[1, 1].imshow(im_visushrink2)
 ax[1, 1].axis('off')
 ax[1, 1].set_title(
-    (r'Wavelet denoising\n(VisuShrink, $\sigma=\sigma_{est}/2$)\n'
-     'PSNR=%0.4g' % psnr_visushrink2))
+    'Wavelet denoising\n(VisuShrink, $\\sigma=\\sigma_{est}/2$)\n'
+     'PSNR=%0.4g' % psnr_visushrink2)
 ax[1, 2].imshow(im_visushrink4)
 ax[1, 2].axis('off')
 ax[1, 2].set_title(
-    (r'Wavelet denoising\n(VisuShrink, $\sigma=\sigma_{est}/4$)\n'
-     'PSNR=%0.4g' % psnr_visushrink4))
+    'Wavelet denoising\n(VisuShrink, $\\sigma=\\sigma_{est}/4$)\n'
+     'PSNR=%0.4g' % psnr_visushrink4)
 fig.tight_layout()
 
 plt.show()
diff --git a/doc/examples/filters/plot_nonlocal_means.py b/doc/examples/filters/plot_nonlocal_means.py
--- a/doc/examples/filters/plot_nonlocal_means.py
+++ b/doc/examples/filters/plot_nonlocal_means.py
@@ -80,7 +80,7 @@
 ax[0, 1].set_title('non-local means\n(slow)')
 ax[0, 2].imshow(denoise2)
 ax[0, 2].axis('off')
-ax[0, 2].set_title(r'non-local means\n(slow, using $\sigma_{est}$)')
+ax[0, 2].set_title('non-local means\n(slow, using $\\sigma_{est}$)')
 ax[1, 0].imshow(astro)
 ax[1, 0].axis('off')
 ax[1, 0].set_title('original\n(noise free)')
@@ -89,7 +89,7 @@
 ax[1, 1].set_title('non-local means\n(fast)')
 ax[1, 2].imshow(denoise2_fast)
 ax[1, 2].axis('off')
-ax[1, 2].set_title(r'non-local means\n(fast, using $\sigma_{est}$)')
+ax[1, 2].set_title('non-local means\n(fast, using $\\sigma_{est}$)')
 
 fig.tight_layout()
 
diff --git a/doc/ext/plot2rst.py b/doc/ext/plot2rst.py
--- a/doc/ext/plot2rst.py
+++ b/doc/ext/plot2rst.py
@@ -397,7 +397,7 @@ def write_example(src_name, src_dir, rst_dir, cfg):
                          for role in sphinx_roles)
 
     # Grab all references to inject them in cells where needed
-    ref_regexp = re.compile(r'\n(\.\. \[(\d+)\].*(?:\n[ ]{7,8}.*)+)')
+    ref_regexp = re.compile('\n(\\.\\. \\[(\\d+)\\].*(?:\n[ ]{7,8}.*)+)')
     math_role_regexp = re.compile(':math:`(.*?)`')
 
     text = '\n'.join((content for (cell_type, _, content) in blocks


Test patch: