zerothi / sisl

Electronic structure Python package for post analysis and large scale tight-binding DFT/NEGF calculations
https://zerothi.github.io/sisl
Mozilla Public License 2.0
182 stars 58 forks source link

Plot update on getting attributes #757

Closed pfebrer closed 5 months ago

pfebrer commented 5 months ago

With this PR plots are updated if one attempts to retreive an attribute that we know will be present in the figure.

This is to make things like plot.show() even when no plot has been computed yet. It was not intuitive for users that you had to plot.get().show(). This has the side effect that plot.show() will now update the plot.This means that the way of acting on the plot without updating it now is by getting the _output attribute. E.g. to show the current (possibly outdated) plot:

plot._output.show()

It fixes the broken docs.

codecov[bot] commented 5 months ago

Codecov Report

Attention: Patch coverage is 35.00000% with 13 lines in your changes are missing coverage. Please review.

Project coverage is 86.74%. Comparing base (0b964fe) to head (499feb6).

Files Patch % Lines
src/sisl/viz/figure/matplotlib.py 28.57% 5 Missing :warning:
src/sisl/viz/plot.py 16.66% 5 Missing :warning:
src/sisl/viz/figure/plotly.py 50.00% 2 Missing :warning:
src/sisl/viz/figure/figure.py 66.66% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #757 +/- ## ========================================== - Coverage 86.78% 86.74% -0.04% ========================================== Files 410 410 Lines 51811 51720 -91 ========================================== - Hits 44965 44866 -99 - Misses 6846 6854 +8 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

zerothi commented 5 months ago

@pfebrer could you have a look in the latest build (I just tried to rebuild), I got this: https://github.com/zerothi/sisl/actions/runs/8799290553/job/24148053929

Can you see the output?

CellExecutionError in tutorials/tutorial_es_1.ipynb:
------------------
coord = graphene.sub(0)
coord.plot(axes="xy", atoms_style={"color": "red"}).merge(
    graphene.remove(0).plot(axes="xy")
)
------------------
----- stdout -----
plot_actions False
------------------
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[5], line 2
      1 coord = graphene.sub(0)
----> 2 coord.plot(axes="xy", atoms_style={"color": "red"}).merge(
      3     graphene.remove(0).plot(axes="xy")
      4 )
File /opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/sisl/viz/plot.py:40, in Plot.merge(self, *others, **kwargs)
     37 def merge(self, *others, **kwargs):
     38     from .plots.merged import merge_plots
---> 40     return merge_plots(self, *others, **kwargs)
File /opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/sisl/viz/plots/merged.py:44, in merge_plots(composite_method, backend, *figures, **kwargs)
     40         plot.get()
     41     return plot
     43 plot_actions = combined(
---> 44     *[_san_plot(fig).plot_actions for fig in figures],
     45     composite_method=composite_method,
     46     **kwargs,
     47 )
     49 return get_figure(plot_actions=plot_actions, backend=backend)
File /opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/sisl/viz/plot.py:31, in Plot.__getattr__(self, key)
     29         return getattr(self.nodes.output.get(), key)
     30     else:
---> 31         raise AttributeError(
     32             f"'{key}' not found in {self.__class__.__name__} with backend '{selected_backend}'"
     33         )
     34 else:
     35     return super().__getattr__(key)
AttributeError: 'plot_actions' not found in GeometryPlot with backend 'plotly'
You can ignore this error by setting the following in conf.py:
    nbsphinx_allow_errors = True
make: *** [Makefile:22: html] Error 2
Error: Process completed with exit code 2.