Skip to content

Commit db2f01c

Browse files
authored
Merge branch 'master' into master
2 parents cd22a75 + 778e27e commit db2f01c

12 files changed

Lines changed: 126 additions & 36 deletions

File tree

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: python
2+
3+
python:
4+
- "3.4"
5+
- "3.5"
6+
- "3.6"
7+
8+
install:
9+
- pip install --upgrade pip
10+
- pip install --upgrade setuptools wheel
11+
- pip install --upgrade pytest
12+
- pip install --upgrade plotly
13+
14+
script: pytest

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
## simpleplotly
2-
##### An easy to use plotly wrapper for python / jupyter notebooks
1+
## SimplePlotly
2+
3+
[![PyPI Version](https://img.shields.io/pypi/v/simpleplotly.svg)](https://pypi.python.org/pypi/simpleplotly) [![Build Status](https://travis-ci.org/arraystream/simpleplotly.svg?branch=master)](https://travis-ci.org/arraystream/simpleplotly)
4+
5+
SimplePlotly is an easy to use plotly wrapper for python / jupyter notebooks
36

47
### Authors
58

@@ -10,7 +13,7 @@ ArrayStream (Yu Zheng, Ran Fan, Yongxin Yang)
1013

1114
### Documentation
1215

13-
Please see our blog post on: [http://www.arraystream.com/blog/simpleplotly](http://www.arraystream.com/blog/simpleplotly)
16+
Please see our blog post on: [http://www.arraystream.com/blog/simpleplotly.html](http://www.arraystream.com/blog/simpleplotly.html)
1417

1518
### Contributing
1619

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[metadata]
2+
description-file = README.md

setup.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
# -*- coding: utf-8 -*-
22

3+
import sys
4+
35
from setuptools import setup, find_packages
46

57
exec(open('simpleplotly/version.py').read())
68

79

10+
def check_python_version():
11+
if sys.version_info[:2] < (3, 4):
12+
print('Python 3.4 or newer is required. Python version detected: {}'.format(sys.version_info))
13+
sys.exit(-1)
14+
15+
816
def main():
917
setup(name='simpleplotly',
1018
version=__version__,
11-
author='ArrayStream',
19+
author='ArrayStream (Yu Zheng, Ran Fan, Yongxin Yang)',
1220
author_email='team@arraystream.com',
1321
url='https://github.com/arraystream/simpleplotly',
14-
description="simpleplotly makes generating charts with plotly easy",
15-
long_description=__doc__,
22+
description='An easy to use plotly wrapper for python / jupyter notebooks',
23+
long_description='simpleplotly makes generating charts with plotly easy',
1624
classifiers=[
1725
'Development Status :: 4 - Beta',
1826
'Programming Language :: Python :: 3',
@@ -28,4 +36,5 @@ def main():
2836

2937

3038
if __name__ == '__main__':
39+
check_python_version()
3140
main()

simpleplotly/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
FigureBuilder,
55
FigureHolder,
66
)
7+
from .layout import (
8+
Annotation,
9+
Shape,
10+
XAxis,
11+
YAxis,
12+
ZAxis,
13+
)
714
from .plot import (
815
Scatter,
916
Line,
@@ -15,10 +22,4 @@
1522
Line3D,
1623
Surface,
1724
)
18-
from .layout import (
19-
Annotation,
20-
Shape,
21-
XAxis,
22-
YAxis,
23-
ZAxis,
24-
)
25+
from .version import __version__

simpleplotly/figure.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# -*- coding: utf-8 -*-
22

3+
import itertools
4+
35
import plotly.graph_objs as go
46
from plotly import tools
57
import copy
68
from .layout import ElementBuilder
79
from .plot import AtomBuilder
810
from .subplot import SubPlotSpec, PlotCanvas
9-
import itertools
1011

1112

1213
class FigureHolder(object):
@@ -24,33 +25,34 @@ def update_layout(self, **kwargs):
2425
self.figure.layout.update(**kwargs)
2526
return self
2627

27-
def drop_key_layout(self, key):
28+
def drop_layout_key(self, key):
2829
if key in self.figure.layout:
2930
del self.figure.layout[key]
3031
return self
3132

3233

3334
class FigureBuilder(object):
34-
def __init__(self, *builders):
35-
self.builders = list(builders)
36-
self.specs = [None for _ in range(len(builders))]
35+
def __init__(self):
36+
self.builders = []
37+
self.specs = []
3738
self.layout = {}
3839
self.canvas = PlotCanvas()
3940

40-
def __add__(self,fig_builder,default_layout='blank'):
41-
# new builder
41+
def __add__(self, other_builder):
42+
return self.combine(other_builder)
43+
44+
def combine(self, other_builder, layout=None):
4245
new_fig_builder = FigureBuilder()
4346
new_fig_builder.builders.extend(self.builders)
44-
new_fig_builder.builders.extend(fig_builder.builders)
45-
if default_layout=='left':
46-
new_fig_builder.layout=self.layout
47-
elif default_layout=='right':
48-
new_fig_builder.layout=fig_builder.layout
49-
else:
50-
new_fig_builder.layout={}
47+
new_fig_builder.builders.extend(other_builder.builders)
48+
if layout == 'left':
49+
new_fig_builder.layout = self.layout
50+
elif layout == 'right':
51+
new_fig_builder.layout = other_builder.layout
52+
elif layout is not None:
53+
raise ValueError('layout can only be left, right or None')
5154
return new_fig_builder
5255

53-
5456
def add(self, builder, row=None, col=None, row_span=1, col_span=1):
5557
if isinstance(builder, AtomBuilder):
5658
self.builders.append(builder)
@@ -98,7 +100,7 @@ def build_subplot(self, print_grid=True, **kwargs):
98100

99101
holder = FigureHolder(go.Figure(data=fig.data, layout=fig.layout))
100102
holder.update_layout(**self.layout)
101-
holder.drop_key_layout('xaxis').drop_key_layout('yaxis')
103+
holder.drop_layout_key('xaxis').drop_layout_key('yaxis')
102104
return holder
103105

104106
def subplot(self, row=None, col=None, print_grid=True, **kwargs):

simpleplotly/layout.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ def __call__(self, layout):
5454

5555

5656
class XAxis(AxisBuilder):
57-
def __init__(self, title, name='xaxis', autorange=True, showgrid=True, zeroline=True, showline=False, **kwargs):
58-
super().__init__(go.XAxis, name=name, title=title, autorange=autorange, showgrid=showgrid, zeroline=zeroline, showline=showline, **kwargs)
57+
def __init__(self, title, autorange=True, showgrid=True, zeroline=True, showline=False, **kwargs):
58+
super().__init__(go.XAxis, name='xaxis', title=title, autorange=autorange, showgrid=showgrid, zeroline=zeroline, showline=showline, **kwargs)
5959

6060

6161
class YAxis(AxisBuilder):
62-
def __init__(self, title, name='yaxis', autorange=True, showgrid=True, zeroline=True, showline=False, **kwargs):
63-
super().__init__(go.YAxis, title=title, name=name, autorange=autorange, showgrid=showgrid, zeroline=zeroline, showline=showline, **kwargs)
62+
def __init__(self, title, autorange=True, showgrid=True, zeroline=True, showline=False, **kwargs):
63+
super().__init__(go.YAxis, title=title, name='yaxis', autorange=autorange, showgrid=showgrid, zeroline=zeroline, showline=showline, **kwargs)
6464

6565

6666
class ZAxis(AxisBuilder):
67-
def __init__(self, title, name='zaxis', autorange=True, showgrid=True, zeroline=True, showline=False, **kwargs):
68-
super().__init__(go.ZAxis, title=title, name=name, autorange=autorange, showgrid=showgrid, zeroline=zeroline, showline=showline, **kwargs)
67+
def __init__(self, title, autorange=True, showgrid=True, zeroline=True, showline=False, **kwargs):
68+
super().__init__(go.ZAxis, title=title, name='zaxis', autorange=autorange, showgrid=showgrid, zeroline=zeroline, showline=showline, **kwargs)

simpleplotly/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# -*- coding: utf-8 -*-
22

3-
__version__ = '0.0.1'
3+
__version__ = '0.0.5'

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: utf-8 -*-

tests/test_figure.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import unittest
4+
import simpleplotly as sp
5+
import plotly.graph_objs as go
6+
7+
8+
class FigureHolderTest(unittest.TestCase):
9+
def test_can_update_layout(self):
10+
fh = sp.FigureHolder(go.Figure())
11+
fh.update_layout(barmode='group', title='test plot')
12+
self.assertDictEqual(fh.figure.layout, dict(barmode='group', title='test plot'))
13+
14+
fh.drop_layout_key('barmode')
15+
self.assertDictEqual(fh.figure.layout, dict(title='test plot'))
16+
17+
18+
class FigureBuilderTest(unittest.TestCase):
19+
def test_figure_builder_operations(self):
20+
pass

0 commit comments

Comments
 (0)