question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:open
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
andy-sweetcommented, Mar 7, 2022

Thanks for the clear write up @alisterburt !

An alternative workaround is to provide the (not yet deprecated) property_choices, like follows.

    points_layer = viewer.add_points(
        [],
        property_choices={'my_awesome_feature': ['great', 'perfect']},
        face_color='my_awesome_feature',
        face_color_cycle=['blue', 'green'],
    )

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 of property_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.

    features = pd.DataFrame({
        'my_awesome_feature': pd.Series([], dtype=pd.CategoricalDtype(['great', 'perfect'])),
    })
    points_layer = viewer.add_points(
        [],
        features=features,
        face_color='my_awesome_feature',
        face_color_cycle=['blue', 'green'],
    )

I see the bug here as how to evaluate the default color when there are no data yet. We could fix ColorManager now with features or we could consider waiting until ColorManager is replaced.

1reaction
andy-sweetcommented, Apr 18, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found