Skip to content
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 a list_annotations() method #2562

Merged
merged 2 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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