Skip to content

ptable_scatters allow 3rd data dimension for colormap #155

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

Merged
merged 27 commits into from
Jun 6, 2024

Conversation

DanielYang59
Copy link
Collaborator

@DanielYang59 DanielYang59 commented May 31, 2024

Summary

  • ptable_scatters allow 3rd data dimension for colormap, to close ptable_scatters allow 3rd data dimension for colormap #141.
  • Fix plotting of examples/diatomics/homo-nuclear-mace-medium.svg
  • Clarify PTableProjector property elem_colors:

    pymatviz/pymatviz/ptable.py

    Lines 300 to 304 in aaa7aa1

    @elem_colors.setter
    def elem_colors(self, elem_colors: dict[str, Any] | None) -> None:
    # TODO: set default colors
    # TODO: what is the type of values (str, tuple[float, ...] or both)
    self._elem_colors = elem_colors or {}
  • Fix a minor issue where the default text_color as element-types could overwrite default elem_type_color:
    elem_type_color = self.get_elem_type_color(symbol, default=text_color)
    text_color="element-types" if color_elem_strategy in {"both", "symbol"} else "black"

@DanielYang59 DanielYang59 self-assigned this May 31, 2024
@DanielYang59 DanielYang59 added matplotlib Concerning matplotlib-powered functions ptable Periodic table enhancement Improvement to existing features/functionality labels May 31, 2024
@DanielYang59 DanielYang59 marked this pull request as ready for review June 5, 2024 03:46
@DanielYang59
Copy link
Collaborator Author

@janosh Please review this.

One thing left though, we might need to set a good default for the elem_colors (color for each element)? Do you have any advice on this? This sounds a bit tricky as there are too many elements.

pymatviz/pymatviz/ptable.py

Lines 295 to 304 in 523101b

@property
def elem_colors(self) -> dict[str, Any]:
"""Element-based colors."""
return self._elem_colors
@elem_colors.setter
def elem_colors(self, elem_colors: dict[str, Any] | None) -> None:
# TODO: set default colors
# TODO: what is the type of values (str, tuple[float, ...] or both)
self._elem_colors = elem_colors or {}

@DanielYang59 DanielYang59 requested a review from janosh June 5, 2024 04:09
Copy link
Owner

@janosh janosh left a comment

Choose a reason for hiding this comment

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

thanks @DanielYang59, great work as usual! 🚀 just 2 minor comments

@janosh
Copy link
Owner

janosh commented Jun 5, 2024

One thing left though, we might need to set a good default for the elem_colors (color for each element)?

forgot to reply to this question earlier. how about we copy the VESTA and JMOL color palettes over from elementari? we could then define a Literal or Enum with special values

elem_colors: Literal["vesta", "jmol"]

Copy link
Owner

@janosh janosh left a comment

Choose a reason for hiding this comment

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

thanks a lot @DanielYang59, this looks great!

@janosh janosh merged commit 9e6be47 into janosh:main Jun 6, 2024
6 of 7 checks passed
@DanielYang59 DanielYang59 deleted the ptable-scatter-cmap branch June 7, 2024 01:29
@DanielYang59
Copy link
Collaborator Author

Thanks for the final beautiful touch :)

@@ -299,21 +299,21 @@ def elem_colors(self) -> dict[str, ColorType]:
@elem_colors.setter
def elem_colors(
self,
elem_colors: Literal["vesta", "jmol"] | dict[str, ColorType] = "vesta",
elem_colors: ElemColors | dict[str, ColorType] | None = ElemColors.vesta,
Copy link
Collaborator Author

@DanielYang59 DanielYang59 Jun 7, 2024

Choose a reason for hiding this comment

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

Wondering why do we need None here? which would resolve to vesta anyway?

pymatviz/pymatviz/ptable.py

Lines 308 to 309 in 9e6be47

if elem_colors in ("vesta", None):
self._elem_colors = ELEM_COLORS_VESTA

Copy link
Owner

@janosh janosh Jun 7, 2024

Choose a reason for hiding this comment

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

i imagine someone who wants to set the colors back to default and doesn't know what the default is might just try

projector.elem_colors = None

and see what happens. maybe that's just me in which case i'm open to changing this

Copy link
Collaborator Author

@DanielYang59 DanielYang59 Jun 7, 2024

Choose a reason for hiding this comment

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

i imagine someone who wants to set the colors back to default and doesn't know what the default is might just try

projector.elem_colors = None

and see what happens.

I think if a user don't read the docstring/manual at all, they may not image setting None would set the colors to default in the first place (they might expect the default to be a dict mapping). On the other hand, if they read the docstring, they would know how to set the colors, so I think None adds to ambiguity here :)

Also it might be easier for them to remove/comment out the argument to set it to default, instead of passing a None?

Copy link
Owner

Choose a reason for hiding this comment

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

fair, feel free to remove the None

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay!

janosh added a commit that referenced this pull request Mar 28, 2025
* remove TODO tag

* add placeholder docstrings

* enable color

* enable unit test

* set default cmap to None

* [partly] fix homo-nuclear-mace-medium.

* fix absent element handling

* update TODO tag

* tweak comments

* clarify ChildPlotters doc string

* rename PTableProjector instances plotter->projector

* update usage of `child_kwargs`

* update scatter example data

* add ptable_scatters to main readme

* add new ElemCountMode, ElemColorMode enums

former replaces CountMode in ptable.py

* copy elementari  colors

* remove `jmol_colors` need double check

* fix type alias

* fix jmol colors for structure_viz

* scale rgb values to 0-1 range

* rename _colors.py to colors.py

* replace pymatviz.colors.Color with matplotlib.typing.ColorType

* add ElemColors enum and test PTableProjector.elem_colors

* add 2nd example for ptable-scatters to readme showing parabolas

* compress SVGs

---------

Co-authored-by: Janosh Riebesell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement to existing features/functionality matplotlib Concerning matplotlib-powered functions ptable Periodic table
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ptable_scatters allow 3rd data dimension for colormap
2 participants