Skip to content

More cleanup to annotations tutorial. #20531

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

Closed
wants to merge 1 commit into from
Closed
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: 12 additions & 11 deletions examples/shapes_and_collections/fancybox_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
The following examples show how to plot boxes with different visual properties.
"""

import inspect

import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
import matplotlib.patches as mpatch
Expand All @@ -15,17 +17,16 @@
# First we'll show some sample boxes with fancybox.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# First we'll show some sample boxes with fancybox.
# The following box styles are available:


styles = mpatch.BoxStyle.get_styles()
spacing = 1.2

figheight = (spacing * len(styles) + .5)
fig = plt.figure(figsize=(4 / 1.5, figheight / 1.5))
fontsize = 0.3 * 72

for i, stylename in enumerate(sorted(styles)):
fig.text(0.5, (spacing * (len(styles) - i) - 0.5) / figheight, stylename,
ha="center",
size=fontsize,
bbox=dict(boxstyle=stylename, fc="w", ec="k"))
ncol = 2
nrow = (len(styles) + 1) // ncol
axs = plt.figure(figsize=(3 * ncol, nrow)).subplots(nrow, ncol)
for ax in axs.flat:
ax.set_axis_off()
for ax, (stylename, stylecls) in zip(axs.T.flat, styles.items()):
ax.text(.5, .5,
f"{stylename}\n{inspect.signature(stylecls)}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced this stylecls inspection is an improvement. This plot should primarily illustrate the available boxstyles. Adding the parameters is rather distracting. And also these are only the defaults, which should be irrelevant to most users (well maybe if you start modifying them, but that should be discussed separately.

transform=ax.transAxes, ha="center", va="center",
bbox=dict(boxstyle=stylename, fc="w", ec="k"))


###############################################################################
Expand Down
19 changes: 0 additions & 19 deletions examples/userdemo/annotate_simple01.py

This file was deleted.

4 changes: 2 additions & 2 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -2138,7 +2138,7 @@ def _simpleprint_styles(_styles):
{stylename: styleclass}, return a string rep of the list of keys.
Used to update the documentation.
"""
return "[{}]".format("|".join(map(" '{}' ".format, sorted(_styles))))
return "[{}]".format("|".join(map(" '{}' ".format, _styles)))


class _Style:
Expand Down Expand Up @@ -2184,7 +2184,7 @@ def pprint_styles(cls):
f'``{name}``',
# [1:-1] drops the surrounding parentheses.
str(inspect.signature(cls))[1:-1] or 'None')
for name, cls in sorted(cls._style_list.items())]]
for name, cls in cls._style_list.items()]]
# Convert to rst table.
col_len = [max(len(cell) for cell in column) for column in zip(*table)]
table_formatstr = ' '.join('=' * cl for cl in col_len)
Expand Down
Loading