-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Changes from 4 commits
2eef301
c5677c8
1afa30a
4d310d0
fc22d6d
4ed0b85
8486779
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
### Changelog | ||
|
||
- 1.6.7 | ||
Added `plot` method to `plotly.widgets.GraphWidget` for easy-to-use client-side graphing | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that darn |
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '1.6.6' | ||
__version__ = '1.6.7' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
from collections import deque | ||
import json | ||
import os | ||
import uuid | ||
|
||
# TODO: protected imports? | ||
from IPython.html import widgets | ||
from IPython.utils.traitlets import Unicode | ||
from IPython.display import Javascript, display | ||
|
||
from plotly import utils | ||
from plotly import utils, tools | ||
from pkg_resources import resource_string | ||
|
||
# Load JS widget code | ||
|
@@ -247,6 +246,18 @@ def message_handler(widget, ranges): | |
""" | ||
self._handle_registration('zoom', callback, remove) | ||
|
||
def plot(self, figure_or_data, validate=True): | ||
"""Plot figure_or_data in the Plotly graph. | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mind throwing in a couple extra lines for docs describing the args? |
||
figure = tools.return_figure_from_figure_or_data(figure_or_data, validate) | ||
message = { | ||
'task': 'newPlot', | ||
'data': figure['data'], | ||
'layout': figure.get('layout', {}), | ||
'graphId': self._graphId | ||
} | ||
self._handle_outgoing_message(message) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clean! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this support refreshing a blank graph? I.e., should this work?
or at least
Does validation mess with that or something? It seems like it would mirror the |
||
def restyle(self, data, indices=None): | ||
"""Update the style of existing traces in the Plotly graph. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ 💯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reasons for not using GitHub releases instead ?