Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
d1bb1965
Commit
d1bb1965
authored
May 08, 2017
by
Theo Steininger
Browse files
Cleaned up the Figure classes
parent
f70b2ae8
Pipeline
#12139
passed with stage
in 5 minutes and 55 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nifty/plotting/figures/figure_base.py
View file @
d1bb1965
# -*- 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
nifty/plotting/figures/figure_from_plot.py
View file @
d1bb1965
...
...
@@ -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
,
...
...
nifty/plotting/figures/multi_figure.py
View file @
d1bb1965
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment