Skip to content

MEP12 text alignment example #8228

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

Merged
merged 3 commits into from
Mar 8, 2017
Merged
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
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
"""
===================
Precise text layout
===================

You can precisely layout text in data or axes (0,1) coordinates. This
example shows you some of the alignment and rotation specifications to
layout text
example shows you some of the alignment and rotation specifications for text
layout.
"""

import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
from matplotlib.patches import Rectangle

# build a rectangle in axes coords
# Build a rectangle in axes coords
left, width = .25, .5
bottom, height = .25, .5
right = left + width
top = bottom + height
ax = plt.gca()
p = plt.Rectangle((left, bottom), width, height,
fill=False,
)
p = plt.Rectangle((left, bottom), width, height, fill=False)
p.set_transform(ax.transAxes)
p.set_clip_on(False)
ax.add_patch(p)
Expand Down Expand Up @@ -47,24 +49,24 @@
verticalalignment='top',
transform=ax.transAxes)

ax.text(left, 0.5*(bottom + top), 'right center',
ax.text(left, 0.5 * (bottom + top), 'right center',
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm -1 on this and the following changes. Note that PEP8 AFAIK does not recommend to add whitespace before and after this operator.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

It says 'Use your own judgment;'

Copy link
Contributor

Choose a reason for hiding this comment

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

"If operators with different priorities are used, consider adding whitespace around the operators with the lowest priority(ies)."

Copy link
Contributor

Choose a reason for hiding this comment

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

In the above line the operator with the lowest priority is the plus operator around which whitespace is added. PEP8 does not say anything about adding whitespace to all operators independent of their priorities.

horizontalalignment='right',
verticalalignment='center',
rotation='vertical',
transform=ax.transAxes)

ax.text(left, 0.5*(bottom + top), 'left center',
ax.text(left, 0.5 * (bottom + top), 'left center',
horizontalalignment='left',
verticalalignment='center',
rotation='vertical',
transform=ax.transAxes)

ax.text(0.5*(left + right), 0.5*(bottom + top), 'middle',
ax.text(0.5 * (left + right), 0.5 * (bottom + top), 'middle',
horizontalalignment='center',
verticalalignment='center',
transform=ax.transAxes)

ax.text(right, 0.5*(bottom + top), 'centered',
ax.text(right, 0.5 * (bottom + top), 'centered',
horizontalalignment='center',
verticalalignment='center',
rotation='vertical',
Expand Down