Skip to content

plot method in GraphWidget #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 20, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
move figure_or_data argument logic to tools for use in widgets.py
  • Loading branch information
chriddyp committed Feb 17, 2015
commit 2eef30132f806d9f40153512c130b80efcf61332
29 changes: 2 additions & 27 deletions plotly/plotly/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,33 +163,8 @@ def plot(figure_or_data, validate=True, **plot_options):
False: do not open plot in the browser, but do return the unique url

"""
if isinstance(figure_or_data, dict):
figure = figure_or_data
elif isinstance(figure_or_data, list):
figure = {'data': figure_or_data}
else:
raise exceptions.PlotlyError("The `figure_or_data` positional argument "
"must be either `dict`-like or "
"`list`-like.")
if validate:
try:
tools.validate(figure, obj_type='Figure')
except exceptions.PlotlyError as err:
raise exceptions.PlotlyError("Invalid 'figure_or_data' argument. "
"Plotly will not be able to properly "
"parse the resulting JSON. If you "
"want to send this 'figure_or_data' "
"to Plotly anyway (not recommended), "
"you can set 'validate=False' as a "
"plot option.\nHere's why you're "
"seeing this error:\n\n{0}"
"".format(err))
if not figure['data']:
raise exceptions.PlotlyEmptyDataError(
"Empty data list found. Make sure that you populated the "
"list of data objects you're sending and try again.\n"
"Questions? support@plot.ly"
)
figure = tools.return_figure_from_figure_or_data(figure_or_data, validate)

for entry in figure['data']:
for key, val in list(entry.items()):
try:
Expand Down
32 changes: 32 additions & 0 deletions plotly/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,3 +1230,35 @@ def __init__(self, url, width, height):

def _repr_html_(self):
return self.embed_code


def return_figure_from_figure_or_data(figure_or_data, validate_figure):
if isinstance(figure_or_data, dict):
figure = figure_or_data
elif isinstance(figure_or_data, list):
figure = {'data': figure_or_data}
else:
raise exceptions.PlotlyError("The `figure_or_data` positional "
"argument must be either "
"`dict`-like or `list`-like.")
if validate_figure:
try:
validate(figure, obj_type='Figure')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that darn tools.validate. if that didn't exist, i woulda placed this function in utils.py since i can't imagine anyone actually needing it.

except exceptions.PlotlyError as err:
raise exceptions.PlotlyError("Invalid 'figure_or_data' argument. "
"Plotly will not be able to properly "
"parse the resulting JSON. If you "
"want to send this 'figure_or_data' "
"to Plotly anyway (not recommended), "
"you can set 'validate=False' as a "
"plot option.\nHere's why you're "
"seeing this error:\n\n{0}"
"".format(err))
if not figure['data']:
raise exceptions.PlotlyEmptyDataError(
"Empty data list found. Make sure that you populated the "
"list of data objects you're sending and try again.\n"
"Questions? support@plot.ly"
)

return figure
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy