Can't set face color to property name with empty point set
See original GitHub issue🐛 Bug
Setting Points.face_color
as a property/feature fails with an empty point set - the error is not seen when a single point is present.
File "/Users/aburt/mambaforge/envs/SPB_relion40/lib/python3.9/site-packages/vispy/color/color_array.py", line 23, in _string_to_rgb
raise ValueError('Color "%s" unknown' % color)
ValueError: Color "my_awesome_feature" unknown
cc @andy-sweet as master of features 🙂
To Reproduce
import napari
viewer = napari.Viewer()
face_color_cycle = ['blue', 'green']
points_layer = viewer.add_points(
[],
features={'my_awesome_feature': []},
face_color='my_awesome_feature',
face_color_cycle=face_color_cycle,
)
napari.run()
Expected behavior
Non-failure, new points added will follow the color cycle
Environment
0.4.15rc1
Additional context
temporary workaround:
points_layer = viewer.add_points(
[0, 0, 0],
features={'my_awesome_feature': [0]},
face_color='my_awesome_feature',
face_color_cycle=face_color_cycle,
)
points_layer.selected_data = {0}
points_layer.remove_selected()
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Using CSS custom properties (variables) - MDN Web Docs
They are set using custom property notation (e.g., --main-color: black; ) and are accessed using the var() function (e.g., color: var(--main- ...
Read more >Cannot assign to read only property 'name' of object '[object ...
I ran into this issue in Angular, while setting a local variable from ActivatedRoute's queryParams, and attempting to conditionally either ...
Read more >Patch Properties (MATLAB Functions)
The FaceVertexCData property specifies the color of patches defined by the Faces and Vertices properties, and the values are used when FaceColor ,...
Read more >Attributes - Graphviz
The table gives the name of the attribute, the graph components (node, edge, etc.) ... Thus, to set the color of a node...
Read more >matplotlib.patches.Patch — Matplotlib 3.6.2 documentation
A patch is a 2D artist with a face color and an edge color. ... Return whether the given point is inside the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the clear write up @alisterburt !
An alternative workaround is to provide the (not yet deprecated)
property_choices
, like follows.I think you had to do that before
features
was introduced, as it’s what was introduced in the tests and also conveys the main intent ofproperty_choices
as I understand it.That will give
my_awesome_feature
a categorical dtype in the underlying dataframe, which might be OK for some usage (i.e. if you know all the possible values ahead of time) of a feature-based color cycle, but not others (e.g. you want to specify a cycle for an unbound integer value cycle).Equivalently, you set up the categorical dtype explicitly with
features
.I see the bug here as how to evaluate the default color when there are no data yet. We could fix
ColorManager
now withfeatures
or we could consider waiting untilColorManager
is replaced.Just as a reference, this bug should be closed when we complete the Use ColorEncoding for Points task in the properties project board: https://github.com/napari/napari/projects/11