lab-cosmo / chemiscope

An interactive structure/property explorer for materials and molecules
http://chemiscope.org
BSD 3-Clause "New" or "Revised" License
132 stars 32 forks source link

better support for coloring by a categorical value #381

Open bernstei opened 5 days ago

bernstei commented 5 days ago

As far as I can tell, the only truly categorical visual property that's available is symbol, but I find that it can be hard to find the one circle in a sea of squares, etc. I would find it very helpful if color could be used for a categorical property. That works now, but with very little control.

At a minimum, that could be done by allowing more standard matplotlib palettes, e.g. tab10, which currently lead to an only partially helpful error message (in particular the "are you sure" part):

invalid property 'tab10' for palette, are you sure the settings correspond to the current dataset?
    at HTMLOption.validate (http://localhost:8080/chemiscope-app.min.js:212328:15)
    at HTMLOption._update (http://localhost:8080/chemiscope-app.min.js:212481:14)
    at set value (http://localhost:8080/chemiscope-app.min.js:212362:14)
    at http://localhost:8080/chemiscope-app.min.js:212585:30
    at foreachOptionImpl (http://localhost:8080/chemiscope-app.min.js:212648:13)
    at MapOptions.foreachOption (http://localhost:8080/chemiscope-app.min.js:212622:9)
    at MapOptions.applySettings (http://localhost:8080/chemiscope-app.min.js:212564:14)
    at MapOptions.applySettings (http://localhost:8080/chemiscope-app.min.js:211512:15)
    at new MapOptions (http://localhost:8080/chemiscope-app.min.js:211484:14)
    at new PropertiesMap (http://localhost:8080/chemiscope-app.min.js:210020:25)

Additional control, e.g. mapping specific categorical values to numerical values in the scale, would be even better, but I think just letting me set the min and max of the mapping would be enough.

Luthaf commented 5 days ago

Adding new palettes should be very easy, they are all defined in https://github.com/lab-cosmo/chemiscope/blob/main/src/map/colorscales.ts.

lead to an only partially helpful error message (in particular the "are you sure" part):

Good point, this is a leftover from the time where the only way to save settings was to change them manually & export them. I'll update this.

I think just letting me set the min and max of the mapping would be enough.

You can already do this (or I am not getting your point). In the map settings, colors => more options => there is a min and max setting here that will be used.

bernstei commented 3 days ago

Are you interested in a patch with just the tab10 palette (from matplotlib)? Or only if it's part of a more complete PR that supports color for categorical variables more cleanly?

That plus setting the limits manually to 0 - 10 (since the categorical values are mapped to integers, and the palette has 10 slots) give me the behavior I want.

ceriottm commented 2 days ago

Doesn't hurt. Maybe you could do all the four tabXXX colormaps https://matplotlib.org/stable/users/explain/colors/colormaps.html so there's some choice and the PR is a tad more substantial. It'd be important that the colormap is defined so there are really sharp changes, I think it can be achieved by having each point twice, with the left and the right colors, but you may have to play a bit with it.

bernstei commented 2 days ago

My local branch has them with n * 0.1 - 1e-6 and n * 0.1, which is very (but not perfectly) sharp. I can try identical values. And yes, I can grab the other discontinuous ones. Do you want me to clone, or add me as a contributor to this repo?

ceriottm commented 2 days ago

invited you. IDK if they can be identical, worth checking as it'd be cleaner. I just added you