Repository: matplotlib/matplotlib
Pull request: Changed return type of get_{x,y}ticklabels to plain list
## PR Summary

Changed return type of get_{x,y}ticklabels to plain list
Fixes #16885

## PR Checklist

- [ ] Has Pytest style unit tests
- [ ] Code is [Flake 8](http://flake8.pycqa.org/en/latest/) compliant
- [ ] New features are documented, with examples if plot related
- [ ] Documentation is sphinx and numpydoc compliant
- [ ] Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
- [ ] Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

<!--
Thank you so much for your PR!  To help us review your contribution, please
consider the following points:

- A development guide is available at https://matplotlib.org/devdocs/devel/index.html.

- Help with git and github is available at
  https://matplotlib.org/devel/gitwash/development_workflow.html.

- Do not create the PR out of master, but out of a separate branch.

- The PR title should summarize the changes, for example "Raise ValueError on
  non-numeric input to set_xlim".  Avoid non-descriptive titles such as
  "Addresses issue #8576".

- The summary should provide at least 1-2 sentences describing the pull request
  in detail (Why is this change required?  What problem does it solve?) and
  link to any relevant issues.

- If you are contributing fixes to docstrings, please pay attention to
  http://matplotlib.org/devel/documenting_mpl.html#formatting.  In particular,
  note the difference between using single backquotes, double backquotes, and
  asterisks in the markup.

We understand that PRs can sometimes be overwhelming, especially as the
reviews start coming in.  Please let us know if the reviews are unclear or
the recommended next step seems overly demanding, if you would like help in
addressing a reviewer's comments, or if you have been waiting too long to hear
back on your PR.
-->


Problem statement:
Change return type get_{x,y}ticklabels to plain list
Its fairly often that I use `get_xticklabels` and other similar methods when exploring and visualizing data with matplotlib. I almost always use `list(ax.get_xticklabels())` or `ax.get_xticklabels()[0]` to view. When teaching, it's also much nicer to be able to see some of the labels without this workaround. One of the main purposes of the getter methods is to actually see a nice underlying representation of the object.

I see from the docstrings that the purpose of `silent_list` is to silence the repr, but perhaps this can change.  `get_xticks` returns an array. `get_lines` and `get_labels` return a silent list.

Is the silent list even necessary?

Hints from issue discussion:
I agree that especially for ticklabels, returning a plain list is fine -- it is "unlikely" that there are so many tick labels that this drowns out the terminal.
I think I see the purpose of a silent list - to shorten the output of those plotting methods that return many items (like `bar` or `plot`). I almost never want to see that output. 

Do tick labels or lines ever get returned outside of the getter methods? If not, then the only reason they are accessed is to view their values.

Another option is to display for first and last 3 values.
My point is not to switch to plain lists everywhere, but indeed only for ticklabels where plain lists do seem better than silent_list.
In the standard case `list(ax.get_xtickslabels())` would return something like

    [Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, ''), Text(0, 0, '')]

I don't see how this is useful to see as output.


Can you explain how thats the 'standard' case? The only time I view the repr for tick labels is when I purposefully access them with a getter method. Also, calling `set_xticklabels` returns a list and not a silent_list.
By standard case I mean:

```
import matplotlib.pyplot as plt
plt.plot([32,34,21])
print(list(plt.gca().get_xticklabels()))
```
The simplest path here is to consider changing the return type of `get_xticklabels()` to be a normal `list`.

Commit message: doc changes

Patch to review:
diff --git a/doc/api/next_api_changes/behaviour.rst b/doc/api/next_api_changes/behaviour.rst
index 9ebe3fe42240..a4d069f3a482 100644
--- a/doc/api/next_api_changes/behaviour.rst
+++ b/doc/api/next_api_changes/behaviour.rst
@@ -98,9 +98,9 @@ deprecation warning.
 `~.Axes.errorbar` now color cycles when only errorbar color is set
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-Previously setting the *ecolor* would turn off automatic color cycling for the plot, leading to the 
-the lines and markers defaulting to whatever the first color in the color cycle was in the case of 
-multiple plot calls. 
+Previously setting the *ecolor* would turn off automatic color cycling for the plot, leading to the
+the lines and markers defaulting to whatever the first color in the color cycle was in the case of
+multiple plot calls.
 
 `.rcsetup.validate_color_for_prop_cycle` now always raises TypeError for bytes input
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -155,3 +155,12 @@ support for it will be dropped in a future Matplotlib release.
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Previously, keyword arguments were silently ignored when no positional
 arguments were given.
+
+
+`get_minorticklabels` and `get_majorticklabels` now returns plain list
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Previously, get_minorticklabels and get_majorticklabels returns silent_list.
+Their return type is now changed to normal list. `get_xminorticklabels`,
+`get_yminorticklabels`, `get_zminorticklabels`, `get_ticklabels`,
+`get_xmajorticklabels`, `get_ymajorticklabels` and `get_zmajorticklabels`
+methods will be affected by this change.
diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py
index a68201068747..c7ac3267cc5d 100644
--- a/lib/matplotlib/axis.py
+++ b/lib/matplotlib/axis.py
@@ -1171,14 +1171,14 @@ def get_majorticklabels(self):
         ticks = self.get_major_ticks()
         labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
         labels2 = [tick.label2 for tick in ticks if tick.label2.get_visible()]
-        return cbook.silent_list('Text major ticklabel', labels1 + labels2)
+        return list('Text major ticklabel', labels1 + labels2)
 
     def get_minorticklabels(self):
         """Return a list of Text instances for the minor ticklabels."""
         ticks = self.get_minor_ticks()
         labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
         labels2 = [tick.label2 for tick in ticks if tick.label2.get_visible()]
-        return cbook.silent_list('Text minor ticklabel', labels1 + labels2)
+        return list('Text minor ticklabel', labels1 + labels2)
 
     def get_ticklabels(self, minor=False, which=None):
         """


Code review comments:
diff_hunk: @@ -155,3 +155,12 @@ support for it will be dropped in a future Matplotlib release.
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Previously, keyword arguments were silently ignored when no positional
 arguments were given.
+
+
+`get_minorticklabels` and `get_majorticklabels` now returns plain list
path: doc/api/next_api_changes/behaviour.rst
text: @user1:
you likely(?) need dotted names here (https://matplotlib.org/devel/documenting_mpl.html#referring-to-other-code) -- just adding a leading dot should do.
See also the note at the end of https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#cross-referencing-python-objects.

@author:
Thanks for these links :-)

@author:
Completed it!