Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1d5dc65

Browse files
committed
Add public method set_loc() for Legend
1 parent 2f762da commit 1d5dc65

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

doc/users/next_whats_new/set_loc.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@ Add a public method to modify the location of ``Legend``
77
:include-source: true
88

99
from matplotlib import pyplot as plt
10-
from matplotlib.legend import Legend
11-
1210

1311
fig = plt.figure()
1412
ax = fig.add_subplot(1, 1, 1)
1513

16-
x = [-10.0, -9.657349547286204, -9.318462608835684, -9.031177432527166, -8.691618609025815, -8.407140700722843, -8.152708015644635, -7.839130676473357, -7.499034134688037, -7.172556788526309, -6.847257574849716, -6.552316320455642, -6.230727469453974, -5.914856113060868]
17-
y = [4.5397868702434395e-05, 6.394971420131934e-05, 8.974373333525978e-05, 0.00011960725629360318, 0.00016795968412322188, 0.000223217496066253, 0.00028787162356623547, 0.00039385623135828983, 0.0005533125089980317, 0.0007667698609716984, 0.0010612377365216156, 0.0014247739486663552, 0.001964154207369101, 0.002691782877150404]
14+
x = list(range(-100, 101))
15+
y = [i**2 for i in x]
16+
1817
ax.plot(x, y, label="f(x)")
1918
ax.legend()
20-
ax.get_legend().set_loc("right")
21-
# Or
22-
# ax.get_legend().set(loc="right")
19+
ax.get_legend().set_loc("right")
20+
# Or
21+
# ax.get_legend().set(loc="right")
2322

2423
plt.show()

0 commit comments

Comments
 (0)