-
Notifications
You must be signed in to change notification settings - Fork 33
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
Improve plotting #157
Merged
Improve plotting #157
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- avoid using pandas indexing (=faster) - new parameter `radius_scale_factor` to scale radii - add `.vertex_map` property to resulting MeshNeuron
- plot2d: invert plot axes instead of data to match negative view ("-x") - meshes: use PolyCollection instead of Polygon+PatchCollection - update docstrings - use dataclasses to validate plotting settings - define depth colormap via global variable - change defaults: - radius=True - alpha=1 - figsize=None (i.e. use mpl default size) - rename parameters: - synapse_layout -> cn_layout - new parameters: - mesh_shade (default False) - non_view_axes3d (default = "hide") - make `view` parameter work with methods "3d" and "3d_complex" - shade/color_by now works with skeletons when radius=True - loose a bunch of unnecessary ballast - change style: - axis on by default - bump matplotlib minimum version 3.6 -> 3.7
- add octarine as default backend - use dataclasses to validate and pass around plotting parameters - update docstrings - change defaults: - radius=True (ignored if skeleton has no radius) - actually respect `cn_size` - `legendgroup` now also used as title for plotly backend - navis.Viewer: - `show()` now works properly in Jupyter - new .`size` property, including setter - a bunch of code formatting
- bump minimum matplotlib version 3.7 -> 3.9 (for add_collection3d) - make plotly an extra dependency - add octarine as extra dependency - add k3d as extra dependency - install jupyter_rfb alongside vispy (if requested)
(i.e. exclude from [all])
As expected, adding a new backend has played havoc with the test suite but all tests are passing now. Visualisation-related testing is still a bit of a hack and relies mostly on the tutorial notebooks. For example, not every functionality is tested with every backend. I don't think I want to address that in this PR. A couple more test-related notes:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR represents a medium-sized rework of the plotting system.
First up the unpleasant part as there are a few (minor) breaking changes:
synapse_layout
parameter was renamed tocn_layout
(matching e.g. other parameters such ascn_colors
)navis.plot2d
(e.g.view=("x", "-z")
) are now implemented by inverting axes rather than changing the underlying datamatplotlib
is now3.9
(was3.6
)plotly
backend is not part of a minimal install anymore (still installed withnavis[all]
)Now to the fun bits:
Octarine
This PR adds Octarine as the default backend for 3d plotting from terminal (it also works in Jupyter). With it comes a smart(er) backend selection where we check which backends are available and choose the nominally "best". For non-Jupyter the order is:
Octarine > Vispy > plotly
. For Jupyter the order is currentlyplotly > Octarine > k3d
. The latter may still change since this PR also makes the internalnavis.Viewer
Jupyter-capable.pip install navis[all]
will now install all supported backends. The minimal installpip install navis
installs onlymatplotlib
.Plot 2D style
The default style for
plot2d()
has been a bit of an eyesore and I noticed that in my own code I often heavily tinker with the defaults. With this PR we're changing the defaults so we get nice looking plots off the bat. Here are two examples:These are the major changes:
radius=True
by default (quietly ignored if skeleton has no radius)mesh_shade
parameter)view
parameter now also works with methods3d
and3d_complex
(previously it was quietly ignored)To account for the new
radius=True
default, thecolor_by
andshade_by
parameters should now also work when plotting skeletons withradius=True
(i.e. we internally map the skeleton node colors onto the derived mesh's vertices).Parameter validation
Previously, both
plot2d
andplot3d
accepted a vague number of keyword arguments, some of which were documented while others were not. Both plotting functions still accept keyword arguments but this PR introduces Python data classes to validate parameters. Here is a quick example of what this looks like:Advantages:
kwargs.get(parameter, default=XXX)
in multiple locationsIt's still not perfect because some features are backend-specific but definitely better than before.
Misc
legendgroup
parameter (plot3d
with plotly backend) now also sets the legend group's title (@Robbie1977)flybrains
andcloud-volume
are now treated as "specialised" dependency, meaning they aren't automatically installed withnavis[all]
(note to self: this may be an issue with e.g. the neuprint interface butneuprint-python
is also not installed by default)TODOs