def open_figure(self, fig, props): """Creates a new figure by beginning to fill out layout dict. The 'autosize' key is set to false so that the figure will mirror sizes set by mpl. The 'hovermode' key controls what shows up when you mouse around a figure in plotly, it's set to show the 'closest' point. Positional agurments: fig -- a matplotlib.figure.Figure object. props.keys(): [ 'figwidth', 'figheight', 'dpi' ] """ self.msg += "Opening figure\n" self.mpl_fig = fig self.plotly_fig['layout'] = go.Layout( width=int(props['figwidth'] * props['dpi']), height=int(props['figheight'] * props['dpi']), autosize=False, hovermode='closest') self.mpl_x_bounds, self.mpl_y_bounds = mpltools.get_axes_bounds(fig) margin = go.layout.Margin( l=int(self.mpl_x_bounds[0] * self.plotly_fig['layout']['width']), r=int( (1-self.mpl_x_bounds[1]) * self.plotly_fig['layout']['width']), t=int((1-self.mpl_y_bounds[1]) * self.plotly_fig['layout'][ 'height']), b=int(self.mpl_y_bounds[0] * self.plotly_fig['layout']['height']), pad=0) self.plotly_fig['layout']['margin'] = margin
def open_figure(self, fig, props): """Creates a new figure by beginning to fill out layout dict. The 'autosize' key is set to false so that the figure will mirror sizes set by mpl. The 'hovermode' key controls what shows up when you mouse around a figure in plotly, it's set to show the 'closest' point. Positional agurments: fig -- a matplotlib.figure.Figure object. props.keys(): [ 'figwidth', 'figheight', 'dpi' ] """ self.msg += "Opening figure\n" self.mpl_fig = fig self.plotly_fig['layout'] = go.Layout( width=int(props['figwidth'] * props['dpi']), height=int(props['figheight'] * props['dpi']), autosize=False, hovermode='closest') self.mpl_x_bounds, self.mpl_y_bounds = mpltools.get_axes_bounds(fig) margin = go.Margin( l=int(self.mpl_x_bounds[0] * self.plotly_fig['layout']['width']), r=int( (1-self.mpl_x_bounds[1]) * self.plotly_fig['layout']['width']), t=int((1-self.mpl_y_bounds[1]) * self.plotly_fig['layout'][ 'height']), b=int(self.mpl_y_bounds[0] * self.plotly_fig['layout']['height']), pad=0) self.plotly_fig['layout']['margin'] = margin