|
237 | 237 | "metadata": {}, |
238 | 238 | "outputs": [], |
239 | 239 | "source": [ |
240 | | - "fig = plt.figure()\n", |
241 | | - "ax = fig.add_axes(\n", |
242 | | - " [0.1, 0.1, 0.8, 0.8]\n", |
243 | | - ") # left, bottom, width, height (range 0 to 1)\n", |
| 240 | + "fig = plt.subplots()\n", |
244 | 241 | "ax.plot(x, x**2, label=\"curve1\")\n", |
245 | 242 | "ax.plot(x, x**3, label=\"curve2\")\n", |
246 | 243 | "ax.legend();" |
|
252 | 249 | "source": [ |
253 | 250 | "The advantage with this method is that if curves are added or removed from the figure, the legend is automatically updated accordingly.\n", |
254 | 251 | "\n", |
255 | | - "The `legend` function takes an optional keyword argument `loc` that can be used to specify where in the figure the legend is to be drawn. The allowed values of `loc` are numerical codes for the various places the legend can be drawn. See http://`matplotlib`.org/users/legend_guide.html#legend-location for details. Some of the most common `loc` values are:\n", |
256 | | - "\n", |
257 | | - "```python\n", |
258 | | - "ax.legend(loc=0) # let `matplotlib` decide the optimal location\n", |
259 | | - "ax.legend(loc=1) # upper right corner\n", |
260 | | - "ax.legend(loc=2) # upper left corner\n", |
261 | | - "ax.legend(loc=3) # lower left corner\n", |
262 | | - "ax.legend(loc=4) # lower right corner\n", |
263 | | - "```\n", |
264 | | - "\n", |
265 | | - "# .. many more options are available\n", |
266 | | - "\n", |
267 | | - "Alternatively, location keywords can also be used.\n", |
| 252 | + "The `legend` function takes an optional keyword argument `loc` that can be used to specify where in the figure the legend is to be drawn. The allowed values of `loc` are keywords for the various places the legend can be drawn. See https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.legend.html#matplotlib.axes.Axes.legend for details. Some of the most common `loc` values are:\n", |
268 | 253 | "\n", |
269 | 254 | "```python\n", |
270 | 255 | "ax.legend(loc='best')\n", |
271 | 256 | "ax.legend(loc='upper right')\n", |
272 | 257 | "ax.legend(loc='upper left')\n", |
273 | 258 | "ax.legend(loc='lower left')\n", |
274 | 259 | "ax.legend(loc='lower right')\n", |
| 260 | + "ax.legend(loc='lower center')\n", |
275 | 261 | "```\n", |
276 | 262 | "\n", |
277 | 263 | "## Setting colors, linewidths, linetypes\n", |
|
0 commit comments