Skip to content

Replace numeric loc by position string #11174

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 2 commits into from
May 9, 2018
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
8 changes: 4 additions & 4 deletions doc/users/prev_whats_new/whats_new_2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ rectangle for the size bar.

fig, ax = plt.subplots(figsize=(3, 3))

bar0 = AnchoredSizeBar(ax.transData, 0.3, 'unfilled', loc=3, frameon=False,
size_vertical=0.05, fill_bar=False)
bar0 = AnchoredSizeBar(ax.transData, 0.3, 'unfilled', loc='lower left',
Copy link
Member

Choose a reason for hiding this comment

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

I wonder whether we should really change old what's new entries at all?

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case, I'm in favor of changing. 'lower left' was already available at that time and should have been preferred to the number. We don't change any semantics but make the example more readable.

frameon=False, size_vertical=0.05, fill_bar=False)
ax.add_artist(bar0)
bar1 = AnchoredSizeBar(ax.transData, 0.3, 'filled', loc=4, frameon=False,
size_vertical=0.05, fill_bar=True)
bar1 = AnchoredSizeBar(ax.transData, 0.3, 'filled', loc='lower right',
frameon=False, size_vertical=0.05, fill_bar=True)
ax.add_artist(bar1)

plt.show()
Expand Down
2 changes: 1 addition & 1 deletion examples/api/sankey_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
orientations=[-1, -1, -1], prior=0, connect=(0, 0))
diagrams = sankey.finish()
diagrams[-1].patch.set_hatch('/')
plt.legend(loc='best')
plt.legend()

###############################################################################
# Notice that only one connection is specified, but the systems form a
Expand Down
4 changes: 2 additions & 2 deletions examples/axes_grid1/demo_anchored_direction_arrows.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
high_contrast_part_1 = AnchoredDirectionArrows(
ax.transAxes,
'111', r'11$\overline{2}$',
loc=1,
loc='upper right',
arrow_props={'ec': 'w', 'fc': 'none', 'alpha': 1,
'lw': 2}
)
Expand All @@ -29,7 +29,7 @@
high_contrast_part_2 = AnchoredDirectionArrows(
ax.transAxes,
'111', r'11$\overline{2}$',
loc=1,
loc='upper right',
arrow_props={'ec': 'none', 'fc': 'k'},
text_props={'ec': 'w', 'fc': 'k', 'lw': 0.4}
)
Expand Down
4 changes: 2 additions & 2 deletions examples/axes_grid1/demo_axes_grid2.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def add_inner_title(ax, title, loc, size=None, **kwargs):
ax.cax.colorbar(im)

for ax, im_title in zip(grid, ["Image 1", "Image 2", "Image 3"]):
t = add_inner_title(ax, im_title, loc=3)
t = add_inner_title(ax, im_title, loc='lower left')
t.patch.set_alpha(0.5)

for ax, z in zip(grid, ZS):
Expand Down Expand Up @@ -109,7 +109,7 @@ def add_inner_title(ax, title, loc, size=None, **kwargs):
ax.cax.toggle_label(True)

for ax, im_title in zip(grid2, ["(a)", "(b)", "(c)"]):
t = add_inner_title(ax, im_title, loc=2)
t = add_inner_title(ax, im_title, loc='upper left')
t.patch.set_ec("none")
t.patch.set_alpha(0.5)

Expand Down
4 changes: 2 additions & 2 deletions examples/axes_grid1/demo_colorbar_of_inset_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_demo_image():
ylim=(-20, 5))


axins = zoomed_inset_axes(ax, 2, loc=2) # zoom = 6
axins = zoomed_inset_axes(ax, zoom=2, loc='upper left')
im = axins.imshow(Z, extent=extent, interpolation="nearest",
origin="lower")

Expand All @@ -40,7 +40,7 @@ def get_demo_image():
cax = inset_axes(axins,
width="5%", # width = 10% of parent_bbox width
height="100%", # height : 50%
loc=3,
loc='lower left',
bbox_to_anchor=(1.05, 0., 1, 1),
bbox_transform=axins.transAxes,
borderpad=0,
Expand Down
4 changes: 2 additions & 2 deletions examples/axes_grid1/demo_colorbar_with_inset_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
axins1 = inset_axes(ax1,
width="50%", # width = 10% of parent_bbox width
height="5%", # height : 50%
loc=1)
loc='upper right')

im1 = ax1.imshow([[1, 2], [2, 3]])
plt.colorbar(im1, cax=axins1, orientation="horizontal", ticks=[1, 2, 3])
Expand All @@ -22,7 +22,7 @@
axins = inset_axes(ax2,
width="5%", # width = 10% of parent_bbox width
height="50%", # height : 50%
loc=3,
loc='lower left',
bbox_to_anchor=(1.05, 0., 1, 1),
bbox_transform=ax2.transAxes,
borderpad=0,
Expand Down
4 changes: 2 additions & 2 deletions examples/axes_grid1/inset_locator_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def add_sizebar(ax, size):
asb = AnchoredSizeBar(ax.transData,
size,
str(size),
loc=8,
loc='lower center',
pad=0.1, borderpad=0.5, sep=5,
frameon=False)
ax.add_artist(asb)
Expand All @@ -28,7 +28,7 @@ def add_sizebar(ax, size):
axins = inset_axes(ax,
width="30%", # width = 30% of parent_bbox
height=1., # height : 1 inch
loc=3)
loc='lower left')

plt.xticks(visible=False)
plt.yticks(visible=False)
Expand Down
2 changes: 1 addition & 1 deletion examples/axes_grid1/inset_locator_demo2.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_demo_image():
ax.imshow(Z2, extent=extent, interpolation="nearest",
origin="lower")

axins = zoomed_inset_axes(ax, 6, loc=1) # zoom = 6
axins = zoomed_inset_axes(ax, zoom=6, loc='upper right')
axins.imshow(Z2, extent=extent, interpolation="nearest",
origin="lower")

Expand Down
13 changes: 6 additions & 7 deletions examples/axes_grid1/simple_anchored_artists.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ def draw_text(ax):
corner of the figure.
"""
from matplotlib.offsetbox import AnchoredText
# loc=2 is equivalent to loc='upper left'
at = AnchoredText("Figure 1a",
loc=2, prop=dict(size=8), frameon=True,
loc='upper left', prop=dict(size=8), frameon=True,
)
at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
ax.add_artist(at)

# loc=3 is eqivalent to loc='lower left'
at2 = AnchoredText("Figure 1(b)",
loc=3, prop=dict(size=8), frameon=True,
loc='lower left', prop=dict(size=8), frameon=True,
bbox_to_anchor=(0., 1.),
bbox_transform=ax.transAxes
)
Expand All @@ -42,7 +40,7 @@ def draw_circle(ax):
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredDrawingArea
from matplotlib.patches import Circle
ada = AnchoredDrawingArea(20, 20, 0, 0,
loc=1, pad=0., frameon=False)
loc='upper right', pad=0., frameon=False)
p = Circle((10, 10), 10)
ada.da.add_artist(p)
ax.add_artist(ada)
Expand All @@ -54,7 +52,8 @@ def draw_ellipse(ax):
"""
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredEllipse
ae = AnchoredEllipse(ax.transData, width=0.1, height=0.15, angle=0.,
loc=3, pad=0.5, borderpad=0.4, frameon=True)
loc='lower left', pad=0.5, borderpad=0.4,
frameon=True)

ax.add_artist(ae)

Expand All @@ -68,7 +67,7 @@ def draw_sizebar(ax):
asb = AnchoredSizeBar(ax.transData,
0.1,
r"1$^{\prime}$",
loc=8,
loc='lower center',
pad=0.1, borderpad=0.5, sep=5,
frameon=False)
ax.add_artist(asb)
Expand Down
2 changes: 1 addition & 1 deletion examples/lines_bars_and_markers/markevery_prop_cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

for i in range(len(cases)):
ax.plot(yy[:, i], marker='o', label=str(cases[i]))
ax.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
ax.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.)

plt.title('Support for axes.prop_cycle cycler with markevery')

Expand Down
2 changes: 1 addition & 1 deletion examples/lines_bars_and_markers/scatter_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
label="Luck")
plt.xlabel("Leprechauns")
plt.ylabel("Gold")
plt.legend(loc=2)
plt.legend(loc='upper left')
plt.show()
2 changes: 1 addition & 1 deletion examples/lines_bars_and_markers/stackplot_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

fig, ax = plt.subplots()
ax.stackplot(x, y1, y2, y3, labels=labels)
ax.legend(loc=2)
ax.legend(loc='upper left')
plt.show()

fig, ax = plt.subplots()
Expand Down
10 changes: 5 additions & 5 deletions examples/misc/anchored_artists.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def draw_text(ax):
"""
Draw a text-box anchored to the upper-left corner of the figure.
"""
# loc=2 is equivalent to loc='upper left'
at = AnchoredText("Figure 1a", loc=2, frameon=True)
at = AnchoredText("Figure 1a", loc='upper left', frameon=True)
at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
ax.add_artist(at)

Expand All @@ -49,7 +48,7 @@ def draw_circle(ax):
"""
from matplotlib.patches import Circle
ada = AnchoredDrawingArea(20, 20, 0, 0,
loc=1, pad=0., frameon=False)
loc='upper right', pad=0., frameon=False)
p = Circle((10, 10), 10)
ada.da.add_artist(p)
ax.add_artist(ada)
Expand All @@ -75,7 +74,8 @@ def draw_ellipse(ax):
Draw an ellipse of width=0.1, height=0.15 in data coordinates
"""
ae = AnchoredEllipse(ax.transData, width=0.1, height=0.15, angle=0.,
loc=3, pad=0.5, borderpad=0.4, frameon=True)
loc='lower left', pad=0.5, borderpad=0.4,
frameon=True)

ax.add_artist(ae)

Expand Down Expand Up @@ -111,7 +111,7 @@ def draw_sizebar(ax):
asb = AnchoredSizeBar(ax.transData,
0.1,
r"1$^{\prime}$",
loc=8,
loc='lower center',
pad=0.1, borderpad=0.5, sep=5,
frameon=False)
ax.add_artist(asb)
Expand Down
2 changes: 1 addition & 1 deletion examples/misc/patheffect_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
# shadow as a path effect
ax3 = plt.subplot(133)
p1, = ax3.plot([0, 1], [0, 1])
leg = ax3.legend([p1], ["Line 1"], fancybox=True, loc=2)
leg = ax3.legend([p1], ["Line 1"], fancybox=True, loc='upper left')
leg.legendPatch.set_path_effects([PathEffects.withSimplePatchShadow()])

plt.show()
8 changes: 4 additions & 4 deletions examples/recipes/transparent_legends.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

ax.legend(loc='upper right')

Other times you don't know where your data is, and loc='best' will try
and place the legend::
Other times you don't know where your data is, and the default loc='best'
will try and place the legend::

ax.legend(loc='best')
ax.legend()

but still, your legend may overlap your data, and in these cases it's
nice to make the legend frame transparent.
Expand All @@ -27,7 +27,7 @@
ax.plot(np.random.rand(300), 's-', label='uniform distribution')
ax.set_ylim(-3, 3)

ax.legend(loc='best', fancybox=True, framealpha=0.5)
ax.legend(fancybox=True, framealpha=0.5)
ax.set_title('fancy, transparent legends')

plt.show()
3 changes: 2 additions & 1 deletion examples/text_labels_and_annotations/demo_text_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def draw(self, renderer=None):
offsetbox.add_artist(p)

# make anchored offset box
ao = AnchoredOffsetbox(loc=2, child=offsetbox, frameon=True, borderpad=0.2)
ao = AnchoredOffsetbox(loc='upper left', child=offsetbox, frameon=True,
borderpad=0.2)
ax.add_artist(ao)

# another text
Expand Down
2 changes: 1 addition & 1 deletion examples/userdemo/anchored_box01.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
fig, ax = plt.subplots(figsize=(3, 3))

at = AnchoredText("Figure 1a",
prop=dict(size=15), frameon=True, loc=2)
prop=dict(size=15), frameon=True, loc='upper left')
at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
ax.add_artist(at)

Expand Down
2 changes: 1 addition & 1 deletion examples/userdemo/anchored_box02.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
fig, ax = plt.subplots(figsize=(3, 3))

ada = AnchoredDrawingArea(40, 20, 0, 0,
loc=1, pad=0., frameon=False)
loc='upper right', pad=0., frameon=False)
p1 = Circle((10, 10), 10)
ada.drawing_area.add_artist(p1)
p2 = Circle((30, 10), 5, fc="r")
Expand Down
2 changes: 1 addition & 1 deletion examples/userdemo/anchored_box03.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

fig, ax = plt.subplots(figsize=(3, 3))

box = AnchoredAuxTransformBox(ax.transData, loc=2)
box = AnchoredAuxTransformBox(ax.transData, loc='upper left')
el = Ellipse((0, 0), width=0.1, height=0.4, angle=30) # in data coordinates!
box.drawing_area.add_artist(el)

Expand Down
2 changes: 1 addition & 1 deletion examples/userdemo/anchored_box04.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
align="center",
pad=0, sep=5)

anchored_box = AnchoredOffsetbox(loc=3,
anchored_box = AnchoredOffsetbox(loc='lower left',
child=box, pad=0.,
frameon=True,
bbox_to_anchor=(0., 1.02),
Expand Down
4 changes: 2 additions & 2 deletions examples/userdemo/simple_legend01.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
plt.plot([3, 2, 1], label="test2")
# Place a legend above this subplot, expanding itself to
# fully use the given bounding box.
plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3,
plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc='lower left',
ncol=2, mode="expand", borderaxespad=0.)

plt.subplot(223)
plt.plot([1, 2, 3], label="test1")
plt.plot([3, 2, 1], label="test2")
# Place a legend to the right of this smaller subplot.
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.)

plt.show()
4 changes: 2 additions & 2 deletions examples/userdemo/simple_legend02.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
line2, = ax.plot([3, 2, 1], label="Line 2", linewidth=4)

# Create a legend for the first line.
first_legend = ax.legend(handles=[line1], loc=1)
first_legend = ax.legend(handles=[line1], loc='upper right')

# Add the legend manually to the current Axes.
ax.add_artist(first_legend)

# Create another legend for the second line.
ax.legend(handles=[line2], loc=4)
ax.legend(handles=[line2], loc='lower right')

plt.show()
2 changes: 1 addition & 1 deletion lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2192,7 +2192,7 @@ def getname_val(identifier):
ax.set_xlabel('')

if not subplots:
ax.legend(ynamelist, loc='best')
ax.legend(ynamelist)

if xname=='date':
fig.autofmt_xdate()
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_bbox_tight.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_bbox_inches_tight():
remove_text=False, savefig_kwarg={'bbox_inches': 'tight'})
def test_bbox_inches_tight_suptile_legend():
plt.plot(np.arange(10), label='a straight line')
plt.legend(bbox_to_anchor=(0.9, 1), loc=2, )
plt.legend(bbox_to_anchor=(0.9, 1), loc='upper left')
plt.title('Axis title')
plt.suptitle('Figure title')

Expand Down
Loading