Repository navigation
[WIP] Plotly 3.0.0 - Deep Jupyter Integration, Validation, Performance, and More - #942
Conversation
| @@ -0,0 +1,909 @@ | |||
| { | |||
There was a problem hiding this comment.
I think at least a portion of these examples in the overview .ipynb should be in the README file. I prefer a README that has examples right there to get started
There was a problem hiding this comment.
Agreed (Added to the checklist above). Also, I didn't plan for these notebooks to stay here in the long run. I just wanted to share some examples for the team to use as part of the discussion.
| "outputs": [], | ||
| "source": [ | ||
| "# Set marker styles / colorbars to match between figures\n", | ||
| "scatt2.marker = scatt1.marker" |
There was a problem hiding this comment.
not a big deal, but running this cell more than once raises a ValueError :
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
I suggest changing the code so that an error doesn't get raised or writing a little blurb about the reason why this happens.
| "outputs": [], | ||
| "source": [ | ||
| "# Save figure 1 to a pdf in the exports directory (requires cairosvg be installed)\n", | ||
| "# f1.save_image('exports/f1.pdf')" |
There was a problem hiding this comment.
After installing cariosvg I get an error running this cell:
OSError: dlopen() failed to load a library: cairo / cairo-2
Looks like there's a thread open here: Kozea/CairoSVG#84
There was a problem hiding this comment.
Did you install through pip or conda? I've had better luck through conda as conda will also pull down the cairo binary without needing to build it. It might be that you have cairosvg installed but not cairo, in this case you might be able to install just cairo using conda.
There was a problem hiding this comment.
I think it's important that the install works w/ pip (as well as conda)
There was a problem hiding this comment.
very possible.
and yes I was using pip
There was a problem hiding this comment.
@cldougl Agreed. The trouble is that cairsosvg requires the non-python cairo executable be installed and pip can't (or at least doesn't) do that.
If cairo(svg) proves to be too much of a hassle to be even an optional dependency then one option is to allow users to register custom file type output filters. This way a user can register cairosvg.svg2png to be the function to be called when a plot is to be saved to a png file.
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 2 | ||
| } |
There was a problem hiding this comment.
Overall very good work here! The convenience bar for using Plotly in Jupyter has been greatly raised.
| if invalid_uids: | ||
| raise ValueError(('The trace property of a figure may only be assigned to ' | ||
| 'a permutation of a subset of itself\n' | ||
| ' Invalid trace(s) with uid(s): {invalid_uids}').format(invalid_uids=invalid_uids)) |
There was a problem hiding this comment.
A couple things:
- Your line has more than 79 characters. https://www.python.org/dev/peps/pep-0008/#id19
- Write the ValueError message something like this:
raise ValueError(
'The trace property of a figure may only be assigned to '
'a permutation of a subset of itself \n Invalid trace(s) with uid(s): '
'{invalid_uids}'.format(invalid_uids=invalid_uids)
)
it addresses 1) and it's more clean IMO
There was a problem hiding this comment.
Yeah, I started this as an independent project originally and chose to use a 119 character line width at the time. We can do a mass reformatting commit at some point (probably just run everything through yapf like I do in the codegen logic)
|
hey @jmmease - I'm having some trouble running Am I missing something? |
|
Looks like a circular dependency issue, not sure why I wasn't hitting it. Try commenting out graph_objs.py while running the codegen logic, then uncommenting. |
|
Any luck with that @chriddyp? |
|
@jmmease that worked, thanks! |
|
📣 I have published a pre-release version of this branch on PyPI. Try it out (python 3 only) with: |
|
@jmmease This is not a bug, but a suggestion to improve an error message: returns: I don't think it's a very user friendly error message for someone who is trying to select input an Perhaps a message that enumerates all of the scatter params or something that says: |
@Kully - I don't think that will actually happen it a lot, since all of our documentation will show Alternatively, perhaps the keyword arguments |
Thanks a lot for this Jon. I'm going to be hitting through these this week so it's nice to have them all written out cleanly. |
|
Sounds good @Kully |
- plotly/datatypes package is gone - codegen object hierarchy directly into plotly/graph_objs. - Refactor codegen output hierarchy to be compatible with legacy Figure/Layout/Trace types. e.g. go.Figure, go.Layout, go.Scatter. - Codegen deprecated classes as dict/list subclasses with deprecation warnings that point users to which classes to use instead. - The entire legacy graph_objs directory is gone (PlotlyDict/PlotlyList/etc.) - _plotly_utils package introduced as a package to hold code that should be available during both code generation and runtime. Moved base validators to this package so we can reuse their descriptions in docstrings. All of the order-dependency of code generation is now gone, and the plotly/ package is not imported. This makes code generation much less fragile to future extension.
|
@chriddyp @Kully
Give it a try and see what you think. I'm going to go back through and review/cleanup the entire |
(e.g. xaxis1 is now accepted and converted into xaxis)
…ct stable component.
Circle has been timeing out on this command sporadically
This was another source of flaky test failures
… failures at 30s)
|
Here's a summary of what I've done to (hopefully 🤞) get the tests running more reliably on circleci:
@cldougl @chriddyp Please take a quick look when you can, and let me know if you're uncomfortable with any of these changes. |
|
The changes look awesome! Do you have an ETA for Plotly 3.0.0? 😃 |
|
@Juanlu001 Thanks! We don't have a date, but "very soon" 🙂 Unless something pops up 3.0.0rc11 may well become 3.0.0 final, so give it a spin if you can! (Install instructions at the top of the thread) |
* Update CHANGELOG.md * (matplotlylib) Make convert_dash more robust to changes in matplotlib. Now handles the case where the dashes are scaled, have floating-point values, or were customized with `dashes=(N,M)`. * commit * remove unnecessary data files in tests and robust data-path searching * pep-8: l -> L variable name * bump version number up * remove shapefiles from folders and delete folders * removed data/ folder and modified choropleth code to match file names * changelog for fixed 2.4.1 * chelsea's comments * added fill_percent to params for insert, swap and remove * html preview not working * HTML preview now reflects the fill_percent param settings * tests are working * make update_default_schema * udpated changelog, removed TODOs, PEP-8 79 char line limit * turn off hover for the lines * 0-padding * changelog * update changelog and version number for 2.5.0 * change fill_percent example in doc to fill_percent=20 * sort all node generators to make HTML output consistent for py2 + py3 * dashboards now autosize based on GUI * update dash workshop announcement cc @chriddyp * version num to 2.5.0 * 4 equal height vertical stacked example in doc string * rename box_1 to box_a, etc * remove shapefiles in tests dir * change version back for testing purposes * version to 2.5.0 * try bumping npm v in circle.yml to 6.0.0 * Don't crash if figure_factory is imported but pandas isn't installed. Fixes plotly/plotly.py#941 * pr for plotly/plotly.py#958 PR * add PR reference * remove a comment * update plotlyjs for offline * moved py2.7 test env to last in core environments * remove ipyplotly folder * fixed assert Scatter() == dict(type='scatter') * fixed test_access_top_level in test_figure * more in test_figures fixes * remove junk in test_figure.py from before base merge * BaseFigure and BasePlotlyType inherit from PlotlyBase class * remove commented validation function * comment out validate error in test_scatter * add histogram2dcontour back to graph_reference TRACES * FigureWidget to OLD_CLASS_NAMES * add update to Data def in graph_objs//remove to_string in test_update * fixed test_offline in optional * test_plotl_mpl fixed * add py36 to core and optional test envs * break up datetime tests into multiple ones for better test control * fixed JSONEncoding errors * last assert test in test_utils * print statements for testing xaxis1 * construct paths to choropleth files intelligently * update the changelog * bump version * changelog comments * revert to current basedatatypes from plotly/plotly.py#942 * write in helper function for assert_dict_equal * fix trisurf: hoverinfo needs 'none', not 'None' * finished a few more classes in figure_factory tests * remove comment * change error msg for pip installs in choropleth * changelog update * fixed facet grid - annotations now tuples - FacetGrid tests in test_optional * remove DeprecationWarning from _dendrogram.py * remove unneeded comments in facet_grid * change height, width default to np.inf in _Dendogram * fixed all tests in optional figure_factory * PEP8 to greyscale list * fix Quiver tests; remove commented TestDisplot for duplicate * minor test fixes in test_tools resolved * playing around with matplotlylib - no success * chelsea's comment * fixed test_validate tests in test_core * fixed offline tests * change assert error in decorator * flawed annotations dont return error, so not checking for one * fix minor tests in test_data * fix test_error_bars * null changes * added white space * rework mock import for Py3.3+ compat * deepcopy in assert_fig_equal * fixed all but one test in make_subplots * fixed test_api - mock compatib issue * change errortype to ValueError to fix test * fix merge for rebase continue * reverted back to old test in test_figure * validators update * fix test_graph_objs.py in test_core * fix scatter.py * fix self.assert_fig_equal(ohlc.to_plotly_json()['data'][0], * assert_dict_equal typo * fix PotlyError -> ValueError for TestTable class * middle of putting .to_plotly_json in assert_fig_equal * updated test_tools - numpy arrays to lists * test_datetimes fixes * Fix typo (agruments) * test_offline changes * do not strip fig of invalid elements wen running .get_figure\nthis is consistent with favoring validation failure to user\nrelated to TODO plotly/plotly.py#283 Issue\n new valid charts created from old PlotlyImageTest examples * xaxis -> xaxis1 in make_subplots * xaxis -> xaxis1 * test_plot * fixed test_figure * fixed test_append_trace - added assert_fig_equal func clone in test_core * fixed TestDistplot tests * removed test_plotly_base_classes test as PlotlyDict/PlotlyList are removed * fixed tests in test_ff in optional
…tion Plotly 3.0.0 - Deep Jupyter Integration, Validation, Performance, and More
Update: June 27, 2018
This branch will mark a major release of the plotly.py branch, Version 3.0.0
There are many new and great features in this branch including deeper Jupyter integration, deeper figure validation, improved performance, and more.
You can try this out with a prerelease version, see https://pypi.org/project/plotly/#history for the latest.
To install and enable with Jupyter, run:
If you're using older versions of
notebookoripywidgetsyou may need to manually activate the widget extensions (this should not be needed fornotebook>=5.3andipywidgets>=7.2)In addition, to add JupyterLab support run the following commands:
The original message from February 19, 2018 is below:
Alright, here we go! @chriddyp @jackparmer
Overview
This is a first cut at integrating the work I started in the ipyplotly project into plotly.py.
Integration Approach
I moved the new object hierarchy to plotly/datatypes. I modified the
graph_objs.pycode generation logic to remapFigure,Layout, and all of the trace objects (Bar,Scatter, etc.) to the corresponding objects in the newdatatypeshierarchy. All of the other classes ingraph_objswere converted intolistordictsubclasses. This is simply for backwards compatibility for the time being, I'm not sure what we want to do with these in the long run.Widget notes
The backend ipywidget logic is implemented in the new
datatypes.Figureanddatatypes.FigureWidgetclasses. The front-end logic is implemented in thejs/directory.Examples
See the notebooks in
specs/ipyplotly_integrationfor an overview of the new functionality.TODO
dict-style.updatemethod on all datatypesFailing test modes
Summary of reasons for current test failures
unexpected keyword argument '_raise'(test_get_figure). Looks like old graph objects had a_raiseconstructor parameter to control whether validation was performed. I'm not sure why this was needed, but validation isn't optional for the new objects.graph_objs.pyclasses don't directly map to objects in the new hierarchy, and they are currently included as dict/list subclasses for source compatibility. e.g.Annotationsdon't have an equivalent because sequences are now represented as tuples of compound types. For instance, theannotationsproperty ofLayoutaccepts tuples ofdatatypes.layout.Annotationobjects and there is noAnnotationstype.Marker,ColorBar,ErrorX,Font,Line,Frames, etc. are replaced by more precise types. For example, there is now atrace.scatter.Markerclass and atrace.bar.Markerclass and they each contain only the properties that are valid for their trace type.validate()methodSubplot properties may only be suffixed by an integer > 1. See [wip] - ipyplotly fixes #956 (comment) for some comments. The documentation and schema of Plotly.js seem to disallowsubplotidproperties ending in 1. (x,x2,x3, but notx1).get_datamethod on datatype objects. This had aflattenoption to return a dict with keys likefoo.bar.baz. I think this could be implemented on the new objects if there's a need for.test_graph_objs.pybecause the collection of classes in graph_objs.py has changed.dictsubclasses so tests likeassert Scatter() == dict(type='scatter')fail.ValueErrorandKeyErrorexceptions. Many of the tests expect aPlotlyError.strip_stylemethod on datatypes. The new logic doesn't maintain thestylemeta-data after code generation, but it would be possible to add this if this method needs to be preserved.to_stringmethod, but again this could be added.Invalid value of type 'plotly.grid_objs.grid_objs.Column' received for the 'xsrc' property of trace.scatter: grid_objs aren't accepted as*srcpropertiesdata_arraytypes (e.g.scatter.x). This breaks some of the streaming tests which have things likemy_stream.write(Scatter(x=1, y=10), ...)layout.width/heightproperties are numbers (according to the schema), but the dendrogram figure_factory sets height to the string'100%'.data_arraytyped properties are converted to read-only numpy arrays internally. So comparisons that expect lists fail (seeTestStreamline/test_simple_streamline)TestTrisurf/test_trisurf_all_argsbecausehoverinfois set to'None'rather than'none''Figure' object has no attribute 'to_dataframe': I'm not really clear on what this method is supposed to do in general.'dot'is in invalid marker type (according to the schema). Used intest_optional/test_matplotlylib/data/scatter.py/SIMPLE_SCATTERAttributeError: module 'plotly.graph_objs.graph_objs' has no attribute 'Histogram2dcontour': It's Histogram2dContour. We could support both versions if we need to.Summary
Missing methods on datatypes
Next steps
strictflag in string validator (see Add number type toannotations.textchart schema plotly.js#2523).data_arrays as lists internally, but convert to tuples on property access.add_traces. Deprecateappend_tracesand remap toadd_traceswith row/col args.FigureWidgetconstructor is called.figure_factory,matplotlylib, etc.