Commit d1bb1965 authored by Theo Steininger's avatar Theo Steininger
Browse files

Cleaned up the Figure classes

parent f70b2ae8
Pipeline #12139 passed with stage
in 5 minutes and 55 seconds
# -*- coding: utf-8 -*-
import os
from PIL import Image
import plotly.offline as ply_offline
import plotly.plotly as ply
from abc import abstractmethod
from nifty.plotting.plotly_wrapper import PlotlyWrapper
......@@ -17,28 +11,6 @@ class FigureBase(PlotlyWrapper):
self.width = width
self.height = height
def plot(self, filename=None, interactive=False):
if not filename:
filename = os.path.abspath('/tmp/temp-plot.html')
if interactive:
try:
__IPYTHON__
ply_offline.init_notebook_mode(connected=True)
ply_offline.iplot(self.to_plotly(), filename=filename)
except NameError:
ply_offline.plot(self.to_plotly(), filename=filename)
raise Warning('IPython not active! Running without interactive mode.')
else:
ply_offline.plot(self.to_plotly(), filename=filename)
def plot_image(self, filename=None, show=False):
if not filename:
filename = os.path.abspath('temp-plot.jpeg')
ply_obj = self.to_plotly()
ply.image.save_as(ply_obj, filename=filename)
if show:
img = Image.open(filename)
img.show()
@abstractmethod
def to_plotly(self):
raise NotImplementedError
......@@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
from abc import abstractmethod
from figure_base import FigureBase
......@@ -11,7 +10,6 @@ class FigureFromPlot(FigureBase):
super(FigureFromPlot, self).__init__(title, width, height)
self.plots = plots
@abstractmethod
def to_plotly(self):
data = [plt.to_plotly() for plt in self.plots]
layout = {'title': self.title,
......
......@@ -57,14 +57,3 @@ class MultiFigure(FigureBase):
title=self.title)
return multi_figure_plotly_object
@staticmethod
def from_figures_cols(figures, cols=2, title=None, width=None, height=None):
multi_figure = MultiFigure((len(figures) + cols -1)/cols , cols, title, width, height)
for i in range(len(figures)):
multi_figure.add_subfigure(figures[i], i/cols, i%cols)
return multi_figure
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment