Skip to content

Color histogram with floats#18

Merged
zoccoler merged 56 commits intomainfrom
color_histogram_with_floats
Apr 11, 2025
Merged

Color histogram with floats#18
zoccoler merged 56 commits intomainfrom
color_histogram_with_floats

Conversation

@zoccoler
Copy link
Contributor

@zoccoler zoccoler commented May 15, 2024

This adds the possibility to assign an array with floats (like representing some feature) as an overlay to the histogram and to the scatter plot.

  • update documentation
  • check if more tests are needed
  • fix log scale problem for histogram

zoccoler added 4 commits May 10, 2024 15:31
…ion_method and calculates a median histogram to be used as overlay

Also add:
 - histogram_interpolation
- overlay_interpolation
 - overlay_opacity
- overlay_visible
 - calculate_statistic histogram
- array_to_pcolormesh_rgba
@zoccoler zoccoler self-assigned this May 15, 2024
@codecov
Copy link

codecov bot commented May 16, 2024

Codecov Report

Attention: Patch coverage is 91.66667% with 37 lines in your changes missing coverage. Please review.

Project coverage is 90.18%. Comparing base (6290895) to head (979103b).
Report is 57 commits behind head on main.

Files with missing lines Patch % Lines
src/biaplotter/artists.py 92.70% 20 Missing ⚠️
src/biaplotter/selectors.py 75.00% 12 Missing ⚠️
src/biaplotter/colormap.py 78.94% 4 Missing ⚠️
src/biaplotter/plotter.py 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #18      +/-   ##
==========================================
+ Coverage   89.65%   90.18%   +0.52%     
==========================================
  Files           7        8       +1     
  Lines         667      978     +311     
==========================================
+ Hits          598      882     +284     
- Misses         69       96      +27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

zoccoler added 10 commits May 16, 2024 08:34
ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.
…default categorical overlay_colormap, set min norm value to non-zero when norm is log
…tion for scatter and histogram for both categorical and continuous colormaps

categorical colormaps only accept linear normalization(log, symlog and centered are ignored in this case)
if data is float with categorical colormap, linear normalization is used

if colormap is continuous, all normalization methods are accepted, but limits may be adjusted
- remove 'normalization_method' parameter from array_to_pcolormesh_rgba
- rename indices_in_above_threshold_patches method to indices_in_patches_above_threshold
- don't draw the overlay if all values are NaN
- initialize self._overlay_visible
@zoccoler zoccoler marked this pull request as ready for review July 26, 2024 14:26
@zoccoler zoccoler requested a review from jo-mueller July 29, 2024 11:58
@zoccoler
Copy link
Contributor Author

Hi @jo-mueller ,

I am adding here the possibility to display the scatter colors or an histogram overlay based o another features column (not just a categorical array with integers, but rather any float array with a continuous colormap - I renamed categorical_colormap to overlay_colormap).

You can get a feeling of the changes by running the Artists notebook again, which I updated.

Of course a histogram overlay completely hides the original histogram, but it may be useful if the user hide and show it quickly or change its opacity for example.

When you get some time, could you please give it a try to check if we can merge this?

@jo-mueller
Copy link
Contributor

Hi @zoccoler ,

sorry for the late reply. I am a bit undecided on this implementation: On the one hand I like the simplicity of this: Simply change the colormap to something continuous, pass a float to the color indices and have your plot colored. On the other hand, it loads the same property (color) with potentially multiple meanings.

In the context of the clusters plotter, it would be hard to use colored scatter points in conjunction with the clustering. As an alternative suggestion: Would you think that it could make sense to forward the coloring done with color_indeces to the marker edge color? The coloring of the points according to a given feature could then still be done with the facecolor and the two colorings wouldn't superseed each other.

Let me know what you think!

# Create a ScalarMappable instance using chosen colormap and normalization
sm = ScalarMappable(norm=norm, cmap=self.overlay_colormap.cmap)
# Convert normalized data to RGBA
rgba_colors = sm.to_rgba(indices)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is problematic, I think. By applying a color normalization here, there is no longer a clear mapping between color_indices and the actually drawn color in the plot.

Usually, what should work is

color = active_artist.overlay_colormap(color_indices)

and the colors I get should be exactly the same as in the plot. However, the colors in the plot pass through an additional normalization step. To recover the colors from the plot (like needed for the clusters plotter), I need to do this:

        color_indices = active_artist.color_indices
        norm = active_artist._get_normalization(color_indices)
        colors = active_artist._get_rgba_colors(color_indices, norm)

Maybe there could be an additional convenience method to wrap the normalization and to_rgba step? Or the normalization step could go into the __call__ method of the new BiaColormap?

@jo-mueller
Copy link
Contributor

Hi @zoccoler , besides the above points, another problem for me is that with the color_indeces now also carrying continuous values, I cannot distinguish anymore between these two cases:

  • A cluster was drawn on the plotter canvas and the cluster indeces are emitted
  • Some continuous values were passed to the plotter and the values are subsequently emitted

In the scope of the clusters-plotter, this distinction is important though. Consider this workflow:

  • I plot some continuous feature in the clusters-plotter
  • When I start drawing and finish, the clusters should reset so that the MANUAL_CLUSTER_ID is plotted again.
  • In this case, the hue selector in the widget should jump to MANUAL_CLUSTER_ID as well.
  • I have no way of knowing to which value to set the hue selector from the cluster_indeces.

@zoccoler
Copy link
Contributor Author

zoccoler commented Apr 3, 2025

Hi @zoccoler , besides the above points, another problem for me is that with the color_indeces now also carrying continuous values, I cannot distinguish anymore between these two cases:

  • A cluster was drawn on the plotter canvas and the cluster indeces are emitted
  • Some continuous values were passed to the plotter and the values are subsequently emitted

In the scope of the clusters-plotter, this distinction is important though. Consider this workflow:

  • I plot some continuous feature in the clusters-plotter
  • When I start drawing and finish, the clusters should reset so that the MANUAL_CLUSTER_ID is plotted again.
  • In this case, the hue selector in the widget should jump to MANUAL_CLUSTER_ID as well.
  • I have no way of knowing to which value to set the hue selector from the cluster_indeces.

That is why I had placed this 😅 Does it help to solve that problem?

@jo-mueller
Copy link
Contributor

That should help :)

@jo-mueller
Copy link
Contributor

@zoccoler , just tested it, the new signal works on my end for clusters-plotter purposes. Can you have a look at PR #42 so that this PR can go through?

@zoccoler zoccoler merged commit 6633938 into main Apr 11, 2025
17 checks passed
@zoccoler
Copy link
Contributor Author

Hi @jo-mueller ,

This is now merged. I will make the new release early next week because I have to prepare a fix release for napari-phasors due to the breaking changes introduced here.

Please refer to the main branch for now while working in the clusters-plotter.

@zoccoler zoccoler deleted the color_histogram_with_floats branch April 11, 2025 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants