Skip to content

Commit 48d9d08

Browse files
committed
grid and meta docstrings
1 parent 5d86ef4 commit 48d9d08

File tree

2 files changed

+334
-10
lines changed

2 files changed

+334
-10
lines changed

plotly/grid_objs/grid_objs.py

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,49 @@
1414
__all__ = None
1515

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

4183

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

0 commit comments

Comments
 (0)