Skip to content

Commit

Permalink
Ensure Matplotlib pane handles explicit width/height settings correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Nov 16, 2022
1 parent b0fc124 commit 6ce5298
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions panel/pane/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ def applies(cls, obj: Any) -> float | bool | None:
def __init__(self, object=None, **params):
super().__init__(object, **params)
self._managers = {}
self._explicit_width = params.get('width') is not None
self._explicit_height = params.get('height') is not None

def _get_widget(self, fig):
import matplotlib.backends
Expand All @@ -223,12 +225,30 @@ def closer(event):
canvas.mpl_connect('close_event', closer)
return manager

@param.depends('width', watch=True)
def _set_explicict_width(self):
self._explicit_width = self.width is not None

@param.depends('height', watch=True)
def _set_explicict_height(self):
self._explicit_height = self.height is not None

def _update_dimensions(self):
w, h = self.object.get_size_inches()
dpi = self.dpi / 2. if self.high_dpi else self.dpi
with param.discard_events(self):
self.width = self.width or int(dpi * w)
self.height = self.height or int(dpi * h)
if not self._explicit_width:
if self._explicit_height:
self.width = int(self.height * (w/h))
else:
self.width = int(dpi * w)
self._explicit_width = False
if not self._explicit_height:
if self._explicit_width:
self.height = int(self.width * (w/h))
else:
self.height = self.height or int(dpi * h)
self._explicit_height = False

def _get_model(
self, doc: Document, root: Optional[Model] = None,
Expand Down

0 comments on commit 6ce5298

Please sign in to comment.