Repository: spyder-ide/spyder

Issue:
Another ZeroDivisionError in the Plots pane
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

A recurrent error which opens the pop-up for error reporting without affecting my work as I remember

### Traceback
```python-traceback
  File "C:\Users\ehadavi\Anaconda3\lib\site-packages\spyder\plugins\plots\widgets\figurebrowser.py", line 743, in eventFilter
    self._update_thumbnail_size()
  File "C:\Users\ehadavi\Anaconda3\lib\site-packages\spyder\plugins\plots\widgets\figurebrowser.py", line 847, in _update_thumbnail_size
    self._setup_thumbnail_size(thumbnail)
  File "C:\Users\ehadavi\Anaconda3\lib\site-packages\spyder\plugins\plots\widgets\figurebrowser.py", line 831, in _setup_thumbnail_size
    thumbnail.scale_canvas_size(max_canvas_size)
  File "C:\Users\ehadavi\Anaconda3\lib\site-packages\spyder\plugins\plots\widgets\figurebrowser.py", line 1051, in scale_canvas_size
    if fwidth / fheight > 1:
ZeroDivisionError: division by zero
```

## Versions

* Spyder version: 4.2.5 
* Python version: 3.8.8
* Qt version: 5.9.7
* PyQt5 version: 5.9.2
* Operating System: Windows 10

### Dependencies

```

# Mandatory:
atomicwrites >=1.2.0            :  1.4.0 (OK)
chardet >=2.0.0                 :  4.0.0 (OK)
cloudpickle >=0.5.0             :  1.6.0 (OK)
diff_match_patch >=20181111     :  20200713 (OK)
intervaltree >=3.0.2            :  3.1.0 (OK)
IPython >=7.6.0                 :  7.22.0 (OK)
jedi =0.17.2                    :  0.17.2 (OK)
jsonschema >=3.2.0              :  3.2.0 (OK)
keyring >=17.0.0                :  22.3.0 (OK)
nbconvert >=4.0                 :  6.0.7 (OK)
numpydoc >=0.6.0                :  1.1.0 (OK)
paramiko >=2.4.0                :  2.7.2 (OK)
parso =0.7.0                    :  0.7.0 (OK)
pexpect >=4.4.0                 :  4.8.0 (OK)
pickleshare >=0.4               :  0.7.5 (OK)
psutil >=5.3                    :  5.8.0 (OK)
pygments >=2.0                  :  2.8.1 (OK)
pylint >=1.0                    :  2.7.4 (OK)
pyls >=0.36.2;<1.0.0            :  0.36.2 (OK)
pyls_black >=0.4.6              :  0.4.6 (OK)
pyls_spyder >=0.3.2             :  0.3.2 (OK)
qdarkstyle >=2.8;<3.0           :  2.8.1 (OK)
qtawesome >=0.5.7               :  1.0.2 (OK)
qtconsole >=5.0.3               :  5.0.3 (OK)
qtpy >=1.5.0                    :  1.9.0 (OK)
rtree >=0.8.3                   :  0.9.7 (OK)
setuptools >=39.0.0             :  52.0.0.post20210125 (OK)
sphinx >=0.6.6                  :  4.0.1 (OK)
spyder_kernels >=1.10.2;<1.11.0 :  1.10.2 (OK)
textdistance >=4.2.0            :  4.2.1 (OK)
three_merge >=0.1.1             :  0.1.1 (OK)
watchdog >=0.10.3;<2.0.0        :  1.0.2 (OK)
zmq >=17                        :  20.0.0 (OK)

# Optional:
cython >=0.21                   :  0.29.23 (OK)
matplotlib >=2.0.0              :  3.3.4 (OK)
numpy >=1.7                     :  1.20.1 (OK)
pandas >=1.1.1                  :  1.2.4 (OK)
scipy >=0.17.0                  :  1.6.2 (OK)
sympy >=0.7.3                   :  1.8 (OK)
```



Discussion:
Hey @ehadavi, thanks for reporting. This error is generated by the Matplotlib figures that you are generating as part of your code, which seem to be broken.

We'll try to fix it in our next version (5.3.1), to be released in mid May.

Resolving patch:
diff --git a/spyder/plugins/plots/widgets/figurebrowser.py b/spyder/plugins/plots/widgets/figurebrowser.py
--- a/spyder/plugins/plots/widgets/figurebrowser.py
+++ b/spyder/plugins/plots/widgets/figurebrowser.py
@@ -499,7 +499,12 @@ def scale_image(self):
 
     def get_scaling(self):
         """Get the current scaling of the figure in percent."""
-        return round(self.figcanvas.width() / self.figcanvas.fwidth * 100)
+        width = self.figcanvas.width()
+        fwidth = self.figcanvas.fwidth
+        if fwidth != 0:
+            return round(width / fwidth * 100)
+        else:
+            return 100
 
     def reset_original_image(self):
         """Reset the image to its original size."""
@@ -1007,13 +1012,14 @@ def scale_canvas_size(self, max_canvas_size):
         """
         fwidth = self.canvas.fwidth
         fheight = self.canvas.fheight
-        if fwidth / fheight > 1:
-            canvas_width = max_canvas_size
-            canvas_height = canvas_width / fwidth * fheight
-        else:
-            canvas_height = max_canvas_size
-            canvas_width = canvas_height / fheight * fwidth
-        self.canvas.setFixedSize(int(canvas_width), int(canvas_height))
+        if fheight != 0:
+            if fwidth / fheight > 1:
+                canvas_width = max_canvas_size
+                canvas_height = canvas_width / fwidth * fheight
+            else:
+                canvas_height = max_canvas_size
+                canvas_width = canvas_height / fheight * fwidth
+            self.canvas.setFixedSize(int(canvas_width), int(canvas_height))
         self.layout().setColumnMinimumWidth(0, max_canvas_size)
 
     def eventFilter(self, widget, event):


Test patch: