-
Notifications
You must be signed in to change notification settings - Fork 865
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
Add more flexibility to PhononDOSPlotter
and PhononBSPlotter
#3700
Conversation
pymatgen/phonon/plotter.py
Outdated
@@ -590,7 +619,7 @@ def get_ticks(self) -> dict[str, list]: | |||
|
|||
def plot_compare( | |||
self, | |||
other_plotter: PhononBSPlotter, | |||
other_plotter: PhononBSPlotter | Sequence[PhononBSPlotter], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about we use dict[str, PhononBSPlotter]
here so we can label other band structures? would be great to add a legend mapping colors to dict keys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also labels
a few lines below, doesn't that do the same? I could refactor though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i think refactoring would make for a better API here. labels
was only added 3 months in 9268942 ago so i think even a breaking change would be acceptable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed labels
. I changed the logic so that no legend is shown if the Plotter is initialised without a label (i.e. if the "original" PhononBS has no label).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's important to still support passing in single PhononBSPlotters
. made some changes to that effect in
26fb878. also i think if there are multiple band structures, we should always show a legend
could you make sure we test both the dict
and single PhononBSPlotter
case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a test for the single PhononBSPlottter
case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janosh Is there a best way to add custom colours for the comparison? With PhononDOSPlotter
, it is done via add_dos()
, but here it is not obvious to me. Is it better to add the colour to the init or passing multiple colours to plot_compare
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
definitely plot_compare
. usually it's best for arguments to be as close to where they're used as possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a colors
variable to plot_compare()
.
…rd, change other_plotter type to PhononBSPlotter | dict[str, PhononBSPlotter]
WalkthroughThe recent update introduces an Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks a lot @ab5424, nice work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- pymatgen/phonon/plotter.py (10 hunks)
- tests/phonon/test_plotter.py (4 hunks)
Additional comments: 9
tests/phonon/test_plotter.py (9)
- 6-6: Consider using a more specific import for
matplotlib.pyplot
if only a few functions are used, to improve code readability and potentially reduce import overhead.- 13-13: Disabling LaTeX rendering in matplotlib globally might affect other tests if they run in the same environment. Consider using a fixture to ensure this setting is only applied to the tests that require it.
- 20-22: Creating multiple instances of
PhononDosPlotter
with different configurations in thesetUp
method is a good practice for testing various scenarios. Ensure that each instance is adequately tested in separate test methods to cover all configurations.- 34-34: Using a set comparison to assert the keys in the dictionary is a robust way to ensure that all expected elements are present, regardless of order. Good use of Python's set operations for testing.
- 41-43: Asserting the type of the returned object and the labels on the axes is a good practice to ensure the plotter's functionality. Consider also adding assertions for the plot data to ensure the correctness of the plotted values.
- 46-49: Testing the
invert_axes
feature by asserting the swapped labels is a good approach. Additionally, consider verifying that the axes' limits are correctly inverted to ensure the feature works as expected.- 71-74: Asserting the type of the returned object and the labels on the axes for the
PhononBSPlotter
is consistent with the tests forPhononDosPlotter
. This consistency in testing approach is commendable.- 89-101: Testing the
plot_compare
method with different scenarios and asserting the legend labels and colors is thorough. It ensures that the comparison feature works correctly for multiple cases. Consider adding a test to verify the handling of incompatible band structures if not already covered.- 111-120: Testing various thermodynamic properties plotting functions in
ThermoPlotter
and asserting the type of the returned object is a good practice. It would be beneficial to also verify the correctness of the plotted data, possibly by checking specific values at known points.
@ab5424 actually, maybe these two CodeRabbit comments are worth addressing. would you be able to add these checks to
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- pymatgen/phonon/plotter.py (10 hunks)
- tests/phonon/test_plotter.py (4 hunks)
Files skipped from review as they are similar to previous changes (2)
- pymatgen/phonon/plotter.py
- tests/phonon/test_plotter.py
@janosh I changed the code according to the suggestions. Interestingly, I found that I was able to get the NaCl/STO comparison though the checking block because the distances lists had the same length (but not the same shape so there was an |
Summary
Major changes:
invert_axes
toPhononDOSPlotter
(similar toDOSPlotter
)PhononBSPlotter
Checklist
ruff
.mypy
.duecredit
@due.dcite
decorators to reference relevant papers by DOI (example)Summary by CodeRabbit
invert_axes
parameter to various plotting methods for axis inversion, enhancing plot customization.matplotlib.pyplot
.