-
Notifications
You must be signed in to change notification settings - Fork 840
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
Breaking: Have plot methods return plt.Axes
object, not matplotlib
module
#3237
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
E AttributeError: 'Axes' object has no attribute 'subplot' /home/runner/work/pymatgen/pymatgen/pymatgen/electronic_structure/plotter.py:1082
E AttributeError: 'Axes' object has no attribute 'ylim' /home/runner/work/pymatgen/pymatgen/pymatgen/electronic_structure/plotter.py:3834
E AttributeError: 'Axes' object has no attribute 'gca' /home/runner/work/pymatgen/pymatgen/pymatgen/electronic_structure/plotter.py:360:
E AttributeError: 'Axes' object has no attribute 'ylim' /home/runner/work/pymatgen/pymatgen/pymatgen/electronic_structure/plotter.py:3838: AttributeError
E AttributeError: 'Axes' object has no attribute 'xlim' pymatgen/electronic_structure/plotter.py:3836: AttributeError
E AttributeError: 'Axes' object has no attribute 'gca' /home/runner/work/pymatgen/pymatgen/pymatgen/phonon/plotter.py:266: AttributeError
E AttributeError: 'Axes' object has no attribute 'setp' pymatgen/electronic_structure/plotter.py:3875: AttributeError
…t_range_map and get_ir_spectra
…expect plt.axes instead of plt
… downstream repercussions
janosh
changed the title
Plot methods return
Breaking: Have plot methods return Aug 17, 2023
plt.Axes
object, not plt
moduleplt.Axes
object, not matplotlib
module
def test_plot(self): # Disabling latex for testing. from matplotlib import axes, rc rc("text", usetex=False) self.plotter.add_dos("Total", self.dos) self.plotter.get_plot(units="mev") self.plotter_nostack.add_dos("Total", self.dos) plt = self.plotter_nostack.get_plot(units="mev") > ax = plt.gca() also attempt fix get_elt_projected_plots
> assert plt.ylim() == (-4.0, 7.6348), "wrong ylim" and > ax.set_title(ax.get_title(), size=width * 4) E AttributeError: 'numpy.ndarray' object has no attribute 'set_title'
@fraricci Thanks for reporting and troubleshooting! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #3138.
pymatgen
plotting methods using thematplotlib
backend return thematplotlib.pyplot
module (plt
), rather than an object related to the plot itself, such as theFigure
orAxes
. This is suboptimal API design and inconsistent with theplotly
backend which returnsgo.Figure
.This PR changes all plotting methods to return a
plt.Axes
object (same aspymatviz
) instead ofplt
.Reasons:
Axes
actually contains the plot attributes (lines, legend, labels, etc.), and is more in line with what users may expect and what they typically interact with when customizing plots.pymatviz
andpymatgen
's ownplotly
backend.