Skip to content

Commit e5a3b31

Browse files
committed
Merge pull request #144 from plotly/grid_docs
grid and meta docstrings
2 parents 5586407 + 5f71a1b commit e5a3b31

File tree

5 files changed

+344
-14
lines changed

5 files changed

+344
-14
lines changed

plotly/grid_objs/grid_objs.py

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,51 @@
1313

1414
__all__ = None
1515

16+
1617
class Column(object):
18+
"""
19+
Columns make up Plotly Grids and can be the source of
20+
data for Plotly Graphs.
21+
They have a name and an array of data.
22+
They can be uploaded to Plotly with the `plotly.plotly.grid_ops`
23+
class.
24+
25+
Usage example 1: Upload a set of columns as a grid to Plotly
26+
```
27+
from plotly.grid_objs import Grid, Column
28+
import plotly.plotly as py
29+
column_1 = Column([1, 2, 3], 'time')
30+
column_2 = Column([4, 2, 5], 'voltage')
31+
grid = Grid([column_1, column_2])
32+
py.grid_ops.upload(grid, 'time vs voltage')
33+
```
34+
35+
Usage example 2: Make a graph based with data that is sourced
36+
from a newly uploaded Plotly columns
37+
```
38+
import plotly.plotly as py
39+
from plotly.grid_objs import Grid, Column
40+
from plotly.graph_objs import Scatter
41+
# Upload a grid
42+
column_1 = Column([1, 2, 3], 'time')
43+
column_2 = Column([4, 2, 5], 'voltage')
44+
grid = Grid([column_1, column_2])
45+
py.grid_ops.upload(grid, 'time vs voltage')
46+
47+
# Build a Plotly graph object sourced from the
48+
# grid's columns
49+
trace = Scatter(xsrc=grid[0], ysrc=grid[1])
50+
py.plot([trace], filename='graph from grid')
51+
```
52+
"""
1753
def __init__(self, data, name):
54+
"""
55+
Initialize a Plotly column with `data` and `name`.
56+
`data` is an array of strings, numbers, or dates.
57+
`name` is the name of the column as it will apppear
58+
in the Plotly grid. Names must be unique to a grid.
59+
"""
60+
1861
# TODO: data type checking
1962
self.data = data
2063
# TODO: name type checking
@@ -40,7 +83,57 @@ def to_plotly_json(self):
4083

4184

4285
class Grid(MutableSequence):
86+
"""
87+
Grid is Plotly's Python representation of Plotly Grids.
88+
Plotly Grids are tabular data made up of columns. They can be
89+
uploaded, appended to, and can source the data for Plotly
90+
graphs.
91+
92+
A plotly.grid_objs.Grid object is essentially a list.
93+
94+
Usage example 1: Upload a set of columns as a grid to Plotly
95+
```
96+
from plotly.grid_objs import Grid, Column
97+
import plotly.plotly as py
98+
column_1 = Column([1, 2, 3], 'time')
99+
column_2 = Column([4, 2, 5], 'voltage')
100+
grid = Grid([column_1, column_2])
101+
py.grid_ops.upload(grid, 'time vs voltage')
102+
```
103+
104+
Usage example 2: Make a graph based with data that is sourced
105+
from a newly uploaded Plotly columns
106+
```
107+
import plotly.plotly as py
108+
from plotly.grid_objs import Grid, Column
109+
from plotly.graph_objs import Scatter
110+
# Upload a grid
111+
column_1 = Column([1, 2, 3], 'time')
112+
column_2 = Column([4, 2, 5], 'voltage')
113+
grid = Grid([column_1, column_2])
114+
py.grid_ops.upload(grid, 'time vs voltage')
115+
116+
# Build a Plotly graph object sourced from the
117+
# grid's columns
118+
trace = Scatter(xsrc=grid[0], ysrc=grid[1])
119+
py.plot([trace], filename='graph from grid')
120+
```
121+
"""
43122
def __init__(self, iterable_of_columns):
123+
"""
124+
Initialize a grid with an iterable of
125+
`plotly.grid_objs.Column objects
126+
127+
Usage example:
128+
```
129+
column_1 = Column([1, 2, 3], 'time')
130+
column_2 = Column([4, 2, 5], 'voltage')
131+
grid = Grid([column_1, column_2])
132+
```
133+
"""
134+
135+
# TODO: verify that columns are actually columns
136+
44137
column_names = [column.name for column in iterable_of_columns]
45138
duplicate_name = utils.get_first_duplicate(column_names)
46139
if duplicate_name:
@@ -95,4 +188,3 @@ def get_column(self, column_name):
95188
for column in self._columns:
96189
if column.name == column_name:
97190
return column
98-

0 commit comments

Comments
 (0)