diff --git a/plotly/plotly/plotly.py b/plotly/plotly/plotly.py index eb4a56a30e..bc98f14497 100644 --- a/plotly/plotly/plotly.py +++ b/plotly/plotly/plotly.py @@ -279,7 +279,7 @@ def get_figure(file_owner_or_url, file_id=None, raw=False): pass a valid plotly url as the first argument. Note, if you're using a file_owner string as the first argument, you MUST - specity a `file_id` keyword argument. Else, if you're using a url string + specify a `file_id` keyword argument. Else, if you're using a url string as the first argument, you MUST NOT specify a `file_id` keyword argument, or file_id must be set to Python's None value. @@ -287,7 +287,7 @@ def get_figure(file_owner_or_url, file_id=None, raw=False): file_owner_or_url (string) -- a valid plotly username OR a valid plotly url Keyword arguments: - file_id (defualt=None) -- an int or string that can be converted to int + file_id (default=None) -- an int or string that can be converted to int if you're using a url, don't fill this in! raw (default=False) -- if true, return unicode JSON string verbatim** diff --git a/plotly/tools.py b/plotly/tools.py index 8de8aafe52..4f51abc3bf 100644 --- a/plotly/tools.py +++ b/plotly/tools.py @@ -180,36 +180,107 @@ def reset_config_file(): ### embed tools ### -def get_embed(username, plot_id, width="100%", height=525): +def get_embed(file_owner_or_url, file_id=None, width="100%", height=525): + """Returns HTML code to embed figure on a webpage as an ").format( plotly_rest_url=plotly_rest_url, - username=username, plot_id=plot_id, + file_owner=file_owner, file_id=file_id, plot_width=width-padding, plot_height=height-padding, iframe_height=height, iframe_width=width) else: s = ("").format( plotly_rest_url=plotly_rest_url, - username=username, plot_id=plot_id, + file_owner=file_owner, file_id=file_id, iframe_height=height, iframe_width=width) return s -def embed(username, plot_id, width="100%", height=525): - s = get_embed(username, plot_id, width, height) +def embed(file_owner_or_url, file_id=None, width="100%", height=525): + """Embeds existing Plotly figure in IPython Notebook + + Plotly uniquely identifies figures with a 'file_owner'/'file_id' pair. + Since each file is given a corresponding unique url, you may also simply + pass a valid plotly url as the first argument. + + Note, if you're using a file_owner string as the first argument, you MUST + specify a `file_id` keyword argument. Else, if you're using a url string + as the first argument, you MUST NOT specify a `file_id` keyword argument, or + file_id must be set to Python's None value. + + Positional arguments: + file_owner_or_url (string) -- a valid plotly username OR a valid plotly url + + Keyword arguments: + file_id (default=None) -- an int or string that can be converted to int + if you're using a url, don't fill this in! + width (default="100%") -- an int or string corresp. to width of the figure + height (default="525") -- same as width but corresp. to the height of the figure + + """ + s = get_embed(file_owner_or_url, file_id, width, height) try: # see if we are in the SageMath Cloud from sage_salvus import html