-
Notifications
You must be signed in to change notification settings - Fork 907
Breaking: Have plot methods return plt.Axes
object, not matplotlib
module
#3237
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
Conversation
This file contains hidden or 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
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! |
DanielYang59
added a commit
to DanielYang59/pymatgen
that referenced
this pull request
Aug 9, 2024
7 tasks
DanielYang59
added a commit
to DanielYang59/pymatgen
that referenced
this pull request
Sep 6, 2024
This reverts commit a8d04f9.
janosh
added a commit
that referenced
this pull request
Sep 6, 2024
* remove unused read_cube import * tweak test.yml comments * try to install BoltzTraP * fix decompress command * make installation script modular * try to modify PATH, test split 4 * fix boltztrap unit test * use rtol * properly skip unit test * fix fig.xticks to ax migration in #3237 * ax.gca -> plg.gca() * properly use ScalarFormatter * NEED CONFIRM: fix number of lines * NEED CONFIRM: fix unit test values * try to install open babel * NEED CONFIRM: include fdint * Revert "NEED CONFIRM: include fdint" This reverts commit 6b19836. * skip tests if no fdint * try to install Vampire * make vampire executable * relocate attribute to class docstring * try to use absolute path in PATH * use VAMPEXE * mark vampire test for fix and skip for now * restore conda openbabel install * use openbabel-wheel instead * make download and decompress less verbose * make module level var all capital * re-enable matgl tests * add TODO tag for skipped unit test * bump matgl version * bump matgl in optional * pin torch version in CI * add reference url * clarify comment * remove unused guarded matgl import * relocate import * update requirements.txt * bump openbabel version * bump openbabel-wheel to latest release 19 * remove matplotlib != 3.9.1 pin as it has been yanked * remove linux only pin for openbabel-wheel * add more comment about bolztrap2 * skip openbabel for windows for now * add TODO tag * make module var all cap * rename non test function to avoid test_xxx pattern * install tblite thru conda-forge * sort conda forge pack order alphabetically * fix io.qchem test dir path * add separate dir var for new qchem files * TO FIX: enable qchem test * I tried but failed, need someone smarter than me to fix this * remove non-win pin for openbabel-wheel * skip failing openbabel tests for Windows * skip left out tests for openbabel on win * uncomment hiphive * use numpy recommended 2.0.0rc1 * bumpy build sys numpy to 2.1.0 * fall back to numpy 2.0.1 as 2.1.0 don't support python39 * mark test_zsl as to be fixed in this PR * use float array as per fast_norm require * reverse numba version bump * drop upgrade arg for pip install torch * instead of hinting, just handle * re-raise from previous error * make ubuntu dep install inline * fix test skip and make module var all cap * add TODO tags * renames * Revert "properly use ScalarFormatter" This reverts commit e2ff5fa. * Revert "ax.gca -> plg.gca()" This reverts commit 1d104cb. * Revert "fix fig.xticks to ax migration in #3237" This reverts commit a8d04f9. * Revert "NEED CONFIRM: fix number of lines" This reverts commit eb7978d. * Revert "NEED CONFIRM: fix unit test values" This reverts commit f6a3fc7. * ruff fix * skip entire TestBoltztrapPlotter * use platform.system() == "Windows" over os.name == "nt" * use platform.system() == "Windows" over sys.platform == "win32" --------- Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>
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.