Skip to content

Commit

Permalink
Fix ros-visualization#35 - "bottom cannot be >= top" matplotlib error
Browse files Browse the repository at this point in the history
Matplotlib emits errors like the following under specific canvas
layouts:

```console
Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rqt_plot/data_plot/mat_data_plot.py", line 107, in resizeEvent
    self.figure.tight_layout()
  File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1756, in tight_layout
    self.subplots_adjust(**kwargs)
  File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1612, in subplots_adjust
    self.subplotpars.update(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 230, in update
    raise ValueError('bottom cannot be >= top')
ValueError: bottom cannot be >= top
```

Current patch catches and suppresses that exception.

References:
- matplotlib/matplotlib#10915
- ros-visualization#35
  • Loading branch information
bergercookie committed Apr 3, 2020
1 parent 677e36d commit 206a894
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/rqt_plot/data_plot/mat_data_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,30 @@ def __init__(self, parent=None):
super(MatDataPlot.Canvas, self).__init__(Figure())
self.axes = self.figure.add_subplot(111)
self.axes.grid(True, color='gray')
self.figure.tight_layout()
self.do_tight_layout()
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.updateGeometry()

def resizeEvent(self, event):
super(MatDataPlot.Canvas, self).resizeEvent(event)
self.figure.tight_layout()
self.do_tight_layout

def do_tight_layout(self):
"""
Deal with "ValueError: bottom cannot be >= top" bug in older matplotlib versions
(before v2.2.3)
References:
- https://github.com/matplotlib/matplotlib/pull/10915
- https://github.com/ros-visualization/rqt_plot/issues/35
"""
if parse_version(matplotlib.__version__) < parse_version('2.2.3'):
try:
self.figure.tight_layout()
except ValueError:
pass
else:
self.figure.tight_layout()

limits_changed = Signal()

Expand Down

0 comments on commit 206a894

Please sign in to comment.