Skip to content

Commit edc6f5f

Browse files
committed
Merge branch 'master' of https://github.com/plotly/python-api
2 parents 62c5ee1 + b6fda38 commit edc6f5f

File tree

10 files changed

+257
-73
lines changed

10 files changed

+257
-73
lines changed

.gitmodules

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
[submodule "plotly/mplexporter"]
2-
path = plotly/mplexporter
1+
[submodule "submodules/mplexporter"]
2+
path = submodules/mplexporter
33
url = git://github.com/mpld3/mplexporter.git
4-
[submodule "plotly/graph_reference"]
5-
path = plotly/graph_reference
4+
[submodule "submodules/graph_reference"]
5+
path = submodules/graph_reference
66
url = git://github.com/plotly/graph_reference.git
7-
[submodule "plotly/chunked_requests"]
8-
path = plotly/chunked_requests
7+
[submodule "submodules/chunked_requests"]
8+
path = submodules/chunked_requests
99
url = git://github.com/chriddyp/chunked_requests.git

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ Now you can download, design, and upload Plotly figures--all from Python.
1919

2020
* Official docs: [https://plot.ly/python](https://plot.ly/python)
2121

22+
###Contributing?
23+
24+
This project uses git submodules! After forking and cloning, in your terminal
25+
run `make` from inside your local `python-api/` repository. That will spit out
26+
the `make_instructions.txt` file. Checkout the *Getting started* section in
27+
there for more info.
28+
2229
###Get in touch
2330

2431

make_instructions.txt

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#################
2+
MAKE INSTRUCTIONS
3+
#################
4+
5+
Contents:
6+
7+
Availble targets
8+
9+
Getting setup
10+
11+
Pulling in changes from subprojects
12+
13+
Why this is worthwhile
14+
15+
################################################################################
16+
17+
Available targets (i.e. $ make target):
18+
19+
readme -> `less` this file
20+
21+
setup_subs -> delete old submodule locations, init, update, and sync new
22+
23+
install -> 1. sync submodules 2. install plotly with setup.py
24+
25+
sync_subs -> sync all submodules
26+
27+
sync_mpl -> sync mplexporter submodule ONLY
28+
29+
sync_chunked -> sync chunked_requests submodule ONLY
30+
31+
sync_refs -> sync graph_reference submodule ONLY
32+
33+
pull_subs -> `cd` into *each* submodule and `git pull origin master`
34+
35+
pull_mpl -> pull in mplexporter *master* branch
36+
37+
pull_chunked -> pull in chunked_requests *master* branch
38+
39+
pull_refs -> pull in graph_reference *master* branch
40+
41+
################################################################################
42+
43+
Getting setup:
44+
45+
1. run `$ make setup_subs`
46+
2. if that doesn't work, DELETE your local repo, re-clone, try again.
47+
48+
################################################################################
49+
50+
Pulling in changes from subprojects:
51+
52+
1. Only pull submodules that you require (e.g., $ make pull_refs)
53+
2. Make sure to sync these changes (e.g., $ make sync_refs)
54+
55+
################################################################################
56+
57+
Why this is worthwhile:
58+
59+
This makefile is mostly to deal with git *submodules*. Since these
60+
*subprojects* only copy over their current commits (not the actual content),
61+
accepting pull requests is really sloppy! By *syncing* changes, we can
62+
more easily track pull new commits from other branches.

makefile

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,62 @@
1-
all : pull_all install
2-
3-
sync_mplexporter : plotly/mplexporter
4-
rsync -r plotly/mplexporter/mplexporter plotly/matplotlylib/
5-
6-
sync_chunked_requests : plotly/chunked_requests
7-
rsync -r plotly/chunked_requests/chunked_requests plotly/plotly/
8-
9-
install : sync_mplexporter sync_chunked_requests
1+
all : readme
2+
3+
readme :
4+
@echo ""
5+
@less make_instructions.txt
6+
7+
setup_subs :
8+
@echo "Deleting old submodule locations, if they exist"
9+
rm -rf plotly/graph_reference
10+
rm -rf plotly/mplexporter
11+
rm -rf plotly/chunked_requests
12+
rm -rf plotly/plotly/chunked_requests
13+
rm -rf plotly/matplotlylib/mplexporter
14+
@echo "Initializing submodules listed in project"
15+
git submodule init
16+
@echo "Updating submodules to their respective commits"
17+
git submodule update
18+
make sync_subs
19+
20+
install : sync_subs
21+
@echo ""
22+
@echo "Installing Python API with make"
1023
python setup.py install
1124

12-
pull_refs : plotly/graph_reference
13-
cd plotly/graph_reference; git pull origin master
14-
15-
pull_mpl : plotly/mplexporter
16-
cd plotly/mplexporter; git pull origin master
17-
18-
pull_chunked : plotly/chunked_requests
19-
cd plotly/chunked_requests; git pull origin master
20-
21-
pull_all : pull_refs pull_mpl pull_chunked
22-
23-
pull_subs :
24-
echo separated submodule pulls, run pull_refs, pull_chunked, or pull_mpl
25-
26-
show_subs : plotly/graph_reference plotly/chunked_requests plotly/mplexporter
27-
git for each ‘git remote -v’
28-
29-
html_nbs : notebooks
30-
cd notebooks; \
31-
ipython nbconvert 'Plotly and Python.ipynb'; \
32-
python add_some_css.py 'Plotly and Python.html'
33-
cd notebooks; \
34-
ipython nbconvert 'Plotly and matplotlib and mpld3.ipynb'; \
35-
python add_some_css.py 'Plotly and matplotlib and mpld3.html'
36-
cd notebooks; \
37-
ipython nbconvert Quickstart.ipynb; \
38-
python add_some_css.py Quickstart.html
25+
sync_subs : sync_mpl sync_chunked sync_refs
26+
@echo ""
27+
@echo "Submodules synced"
28+
29+
pull_subs : pull_mpl pull_chunked pull_refs
30+
@echo ""
31+
@echo "Submodules pulled"
32+
33+
sync_mpl : submodules/mplexporter
34+
@echo ""
35+
@echo "Syncing mplexporter directories"
36+
rsync -r submodules/mplexporter/mplexporter plotly/matplotlylib/
37+
38+
sync_chunked : submodules/chunked_requests
39+
@echo ""
40+
@echo "Syncing chunked_requests directories"
41+
rsync -r submodules/chunked_requests/chunked_requests plotly/plotly/
42+
43+
sync_refs : submodules/graph_reference
44+
@echo ""
45+
@echo "Syncing graph_reference directories"
46+
rsync -r submodules/graph_reference plotly/
47+
48+
pull_refs : submodules/graph_reference
49+
@echo ""
50+
@echo "Pulling down updates from graph_reference"
51+
cd submodules/graph_reference; git pull origin master
52+
53+
pull_mpl : submodules/mplexporter
54+
@echo ""
55+
@echo "Pulling down updates from mplexporter"
56+
cd submodules/mplexporter; git pull origin master
57+
58+
pull_chunked : submodules/chunked_requests
59+
@echo ""
60+
@echo "Pulling down updates from chunked_requests"
61+
cd submodules/chunked_requests; git pull origin master
62+

plotly/exceptions.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def __init__(self, obj='', key='', **kwargs):
7979
"'help(plotly.graph_objs.{obj_name})' for more information."
8080
"".format(key=key, obj_name=obj.__class__.__name__)
8181
)
82-
plain_message="invalid key, '{}', in dictionary".format(key)
82+
plain_message = ("Invalid key, '{key}', found in '{obj}' object"
83+
"".format(key=key, obj=obj.__class__.__name__))
8384
super(PlotlyDictKeyError, self).__init__(message=message,
8485
path=[key],
8586
plain_message=plain_message,
@@ -97,8 +98,8 @@ def __init__(self, obj='', key='', value='', val_types='', **kwargs):
9798
val_types=val_types,
9899
obj_name=obj.__class__.__name__)
99100
)
100-
plain_message = ("invalid value associated with key, '{}', in "
101-
"dictionary".format(key))
101+
plain_message = ("Invalid value found in '{obj}' associated with key, "
102+
"'{key}'".format(key=key, obj=obj.__class__.__name__))
102103
super(PlotlyDictValueError, self).__init__(message=message,
103104
plain_message=plain_message,
104105
path=[key],
@@ -112,8 +113,8 @@ def __init__(self, obj='', index='', entry='', **kwargs):
112113
"".format(index, obj.__class__.__name__)
113114
)
114115
plain_message = (
115-
"The entry at index, '{}', is invalid."
116-
"".format(index)
116+
"Invalid entry found in '{obj}' object at index, '{index}'."
117+
"".format(obj=obj.__class__.__name__, index=index)
117118
)
118119
super(PlotlyListEntryError, self).__init__(message=message,
119120
plain_message=plain_message,
@@ -129,9 +130,9 @@ def __init__(self, obj='', index='', **kwargs):
129130
"'{}' lists.".format(index, obj.__class__.__name__)
130131
)
131132
plain_message = (
132-
"The entry at index, '{}', is invalid because it does not "
133-
"contain a valid 'type' key-value. This is required for "
134-
"valid data lists.".format(index))
133+
"Invalid entry found in 'data' object at index, '{}'. It does "
134+
"not contain a valid 'type' key, required for 'data' lists."
135+
"".format(index))
135136
super(PlotlyDataTypeError, self).__init__(message=message,
136137
plain_message=plain_message,
137138
path=[index],

plotly/graph_objs/graph_objs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,11 @@ def __new__(mcs, name, bases, attrs):
237237
descr = str(obj_info[key]['description'])
238238
except KeyError:
239239
descr = undocumented
240-
str_1 = "{} [required={}] (value={}):\n".format(key, required,
241-
val_types)
240+
str_1 = "{} [required={}] (value={})".format(
241+
key, required, val_types)
242+
if "streamable" in obj_info[key] and obj_info[key]["streamable"]:
243+
str_1 += " (streamable)"
244+
str_1 += ":\n"
242245
str_1 = "\t" + "\n\t".join(textwrap.wrap(str_1,
243246
width=width1)) + "\n"
244247
str_2 = "\t\t" + "\n\t\t".join(textwrap.wrap(descr,

plotly/matplotlylib/mplexporter/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ def get_axes_properties(ax):
259259
'axesbgalpha': ax.patch.get_alpha(),
260260
'bounds': ax.get_position().bounds,
261261
'dynamic': ax.get_navigate(),
262+
'axison': ax.axison,
263+
'frame_on': ax.get_frame_on(),
262264
'axes': [get_axis_properties(ax.xaxis),
263265
get_axis_properties(ax.yaxis)]}
264266

plotly/plotly/plotly.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,15 @@ def get_figure(file_owner_or_url, file_id=None, raw=False):
279279
pass a valid plotly url as the first argument.
280280
281281
Note, if you're using a file_owner string as the first argument, you MUST
282-
specity a `file_id` keyword argument. Else, if you're using a url string
282+
specify a `file_id` keyword argument. Else, if you're using a url string
283283
as the first argument, you MUST NOT specify a `file_id` keyword argument, or
284284
file_id must be set to Python's None value.
285285
286286
Positional arguments:
287287
file_owner_or_url (string) -- a valid plotly username OR a valid plotly url
288288
289289
Keyword arguments:
290-
file_id (defualt=None) -- an int or string that can be converted to int
290+
file_id (default=None) -- an int or string that can be converted to int
291291
if you're using a url, don't fill this in!
292292
raw (default=False) -- if true, return unicode JSON string verbatim**
293293
@@ -417,21 +417,35 @@ def heartbeat(self, reconnect_on=(200, '', 408)):
417417
"cannot write to a closed connection. "
418418
"Call `open()` on the stream to open the stream.")
419419

420-
def write(self, data, layout=None, validate=True,
420+
def write(self, trace, layout=None, validate=True,
421421
reconnect_on=(200, '', 408)):
422-
""" Write `data` to your stream. This will plot the
423-
`data` in your graph in real-time.
422+
"""Write to an open stream.
424423
425-
`data` is a plotly formatted dict.
426-
Valid keys:
424+
Once you've instantiated a 'Stream' object with a 'stream_id',
425+
you can 'write' to it in real time.
426+
427+
positional arguments:
428+
trace - A valid plotly trace object (e.g., Scatter, Heatmap, etc.).
429+
Not all keys in these are `stremable` run help(Obj) on the type
430+
of trace your trying to stream, for each valid key, if the key
431+
is streamable, it will say 'streamable = True'. Trace objects
432+
must be dictionary-like.
433+
434+
keyword arguments:
435+
layout (default=None) - A valid Layout object
436+
Run help(plotly.graph_objs.Layout)
437+
validate (default = True) - Validate this stream before sending?
438+
This will catch local errors if set to True.
439+
440+
Some valid keys for trace dictionaries:
427441
'x', 'y', 'text', 'z', 'marker', 'line'
428442
429443
Examples:
430-
>>> write(dict(x = 1, y = 2))
431-
>>> write(dict(x = [1, 2, 3], y = [10, 20, 30]))
432-
>>> write(dict(x = 1, y = 2, text = 'scatter text'))
433-
>>> write(dict(x = 1, y = 3, marker = dict(color = 'blue')))
434-
>>> write(dict(z = [[1,2,3], [4,5,6]]))
444+
>>> write(dict(x=1, y=2)) # assumes 'scatter' type
445+
>>> write(Bar(x=[1, 2, 3], y=[10, 20, 30]))
446+
>>> write(Scatter(x=1, y=2, text='scatter text'))
447+
>>> write(Scatter(x=1, y=3, marker=Marker(color='blue')))
448+
>>> write(Heatmap(z=[[1, 2, 3], [4, 5, 6]]))
435449
436450
The connection to plotly's servers is checked before writing
437451
and reconnected if disconnected and if the response status code
@@ -442,7 +456,7 @@ def write(self, data, layout=None, validate=True,
442456
http://nbviewer.ipython.org/github/plotly/python-user-guide/blob/master/s7_streaming/s7_streaming.ipynb
443457
"""
444458
stream_object = dict()
445-
stream_object.update(data)
459+
stream_object.update(trace)
446460
if 'type' not in stream_object:
447461
stream_object['type'] = 'scatter'
448462
if validate:

0 commit comments

Comments
 (0)