Skip to content

Commit

Permalink
Merge pull request #2562 from zingale/annotate_list
Browse files Browse the repository at this point in the history
add a list_annotations() method
  • Loading branch information
munkm authored May 1, 2020
2 parents 7e4d84a + 1bd7177 commit d99f816
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
23 changes: 22 additions & 1 deletion doc/source/visualizing/callbacks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ The underlying functions are more thoroughly documented in :ref:`callback-api`.
.. _annotate-clear:

Clear Callbacks (Some or All)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. function:: annotate_clear(index=None)

Expand All @@ -115,6 +115,27 @@ Clear Callbacks (Some or All)
p.annotate_clear()
p.save()

.. _annotate-list:

List Currently Applied Callbacks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. function:: list_annotations()

This function will print a list of each of the currently applied
callbacks together with their index. The index can be used with
:ref:`annotate_clear() function <annotate-clear>` to remove a
specific callback.

.. python-script::

import yt
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
p = yt.SlicePlot(ds, 'z', 'density', center='c', width=(20, 'kpc'))
p.annotate_scale()
p.annotate_timestamp()
p.list_annotations()

.. _annotate-arrow:

Overplot Arrow
Expand Down
9 changes: 9 additions & 0 deletions yt/visualization/plot_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,15 @@ def annotate_clear(self, index=None):
self.setup_callbacks()
return self

def list_annotations(self):
"""
List the current callbacks for the plot, along with their index. This
index can be used with annotate_clear to remove a callback from the
current plot.
"""
for i, cb in enumerate(self._callbacks):
print(i, cb)

def run_callbacks(self):
for f in self.fields:
keys = self.frb.keys()
Expand Down

0 comments on commit d99f816

Please sign in to comment.