diff --git a/.gitignore b/.gitignore index d494630f..2b6a92cd 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,7 @@ iterate.dat # git merge files # ################### -*.orig \ No newline at end of file +*.orig + +# pycharm IDE stuff +.idea/ diff --git a/GPy/plotting/__init__.py b/GPy/plotting/__init__.py index 359a841a..00c4fa82 100644 --- a/GPy/plotting/__init__.py +++ b/GPy/plotting/__init__.py @@ -5,7 +5,7 @@ current_lib = [None] supported_libraries = ['matplotlib', 'plotly', 'none'] error_suggestion = "Please make sure you specify your plotting library in your configuration file (/.config/GPy/user.cfg).\n\n[plotting]\nlibrary = \n\nCurrently supported libraries: {}".format(", ".join(supported_libraries)) -def change_plotting_library(lib): +def change_plotting_library(lib, **kwargs): try: #=========================================================================== # Load in your plotting library here and @@ -22,7 +22,7 @@ def change_plotting_library(lib): if lib == 'plotly': import plotly from .plotly_dep.plot_definitions import PlotlyPlots - current_lib[0] = PlotlyPlots() + current_lib[0] = PlotlyPlots(**kwargs) if lib == 'none': current_lib[0] = None inject_plotting() diff --git a/GPy/plotting/matplot_dep/plot_definitions.py b/GPy/plotting/matplot_dep/plot_definitions.py index 0e3bc32d..9aa72583 100644 --- a/GPy/plotting/matplot_dep/plot_definitions.py +++ b/GPy/plotting/matplot_dep/plot_definitions.py @@ -92,7 +92,7 @@ class MatplotlibPlots(AbstractPlottingLibrary): if title is not None: ax.figure.suptitle(title) return ax - def show_canvas(self, ax): + def show_canvas(self, ax, **kwargs): ax.figure.canvas.draw() return ax.figure diff --git a/GPy/plotting/plotly_dep/plot_definitions.py b/GPy/plotting/plotly_dep/plot_definitions.py index 9e021fd8..f7fa2054 100644 --- a/GPy/plotting/plotly_dep/plot_definitions.py +++ b/GPy/plotting/plotly_dep/plot_definitions.py @@ -31,8 +31,9 @@ import numpy as np from ..abstract_plotting_library import AbstractPlottingLibrary from .. import Tango from . import defaults +OFFLINE=False +import plotly from plotly import tools -from plotly import plotly as py from plotly.graph_objs import Scatter, Scatter3d, Line,\ Marker, ErrorX, ErrorY, Bar, Heatmap, Trace,\ Annotations, Annotation, Contour, Font, Surface @@ -53,10 +54,12 @@ SYMBOL_MAP = { } class PlotlyPlots(AbstractPlottingLibrary): - def __init__(self): + def __init__(self, offline=False): super(PlotlyPlots, self).__init__() self._defaults = defaults.__dict__ self.current_states = dict() + global OFFLINE + OFFLINE=offline def figure(self, rows=1, cols=1, specs=None, is_3d=False, **kwargs): if specs is None: @@ -96,7 +99,10 @@ class PlotlyPlots(AbstractPlottingLibrary): xref, yref = figure._grid_ref[row-1][col-1] for a in traces: append_annotation(a, xref, yref) - elif isinstance(traces, (Trace)): + # elif isinstance(traces, (Trace)): # doesn't work + # elif type(traces) in [v for k,v in go.__dict__.iteritems()]: + elif isinstance(traces, (Scatter, Scatter3d, Line, Marker, ErrorX, + ErrorY, Bar, Heatmap, Trace, Contour, Font, Surface)): try: append_trace(traces, row, col) except PlotlyDictKeyError: @@ -120,9 +126,16 @@ class PlotlyPlots(AbstractPlottingLibrary): figure.append_trace(Scatter(x=[], y=[], name='', showlegend=False), 1, 1) from ..gpy_plot.plot_util import in_ipynb if in_ipynb(): - return py.iplot(figure, filename=filename)#self.current_states[hex(id(figure))]['filename']) + if OFFLINE: + plotly.offline.init_notebook_mode(connected=True) + return plotly.offline.iplot(figure, filename=filename, **kwargs)#self.current_states[hex(id(figure))]['filename']) + else: + return plotly.plotly.iplot(figure, filename=filename, **kwargs) else: - return py.plot(figure, filename=filename)#self.current_states[hex(id(figure))]['filename']) + if OFFLINE: + return plotly.offline.plot(figure, filename=filename, **kwargs) + else: + return plotly.plotly.plot(figure, filename=filename, **kwargs)#self.current_states[hex(id(figure))]['filename']) def scatter(self, ax, X, Y, Z=None, color=Tango.colorsHex['mediumBlue'], cmap=None, label=None, marker='o', marker_kwargs=None, **kwargs): try: