|
256 | 256 | # Implicit: ``pyplot``
|
257 | 257 | # --------------------
|
258 | 258 | #
|
259 |
| -# To use implicit programming for Matplotlib involves using the ``pyplot`` |
| 259 | +# Implicit programming for Matplotlib centers around using the ``pyplot`` |
260 | 260 | # module. The Figure and Axes are automatically generated by the module.
|
261 |
| -# Pass data through as arguments using methods within the module. |
| 261 | +# The methods and functions within the module take incoming data as arguments. |
262 | 262 | # Additional parts of the Figure are also available through the module
|
263 | 263 | # methods.
|
264 | 264 |
|
|
303 | 303 | # ==============
|
304 | 304 | #
|
305 | 305 | # There are two main parts to building a visualization with Matplotlib, the
|
306 |
| -# `Figure`_ and the `Axes`_. |
| 306 | +# ``Figure`` and the ``Axes``. |
307 | 307 | #
|
308 | 308 | # Components of Matplotlib Figure
|
309 | 309 | # -------------------------------
|
310 | 310 | #
|
311 |
| -# The image below depicts each visible element of a Matplotlib graph. |
312 |
| -# **Note**: ``Figure`` and ``Axes`` identify empty regions of the diagram; |
313 |
| -# however, these elements are foundational in operation. |
| 311 | +# The image below depicts each visible element of a Matplotlib graph. The |
| 312 | +# graphic uses Matplotlib to display and highlight each individual part of the |
| 313 | +# visualization. The source code is available as :ref:`Anatomy-of-a-figure`. |
| 314 | +# |
| 315 | +# .. note:: |
| 316 | +# |
| 317 | +# ``Figure`` and ``Axes`` identify empty regions of the diagram; |
| 318 | +# however, these elements are foundational in operation. |
314 | 319 | #
|
315 | 320 | # .. image:: ../../_static/anatomy.png
|
316 | 321 | #
|
317 | 322 | # :class:`~matplotlib.figure.Figure`
|
318 |
| -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
319 | 323 | #
|
320 | 324 | # The Figure is the working space for the programming. All visible
|
321 | 325 | # objects on a graph are located within the Figure.
|
322 | 326 | #
|
323 | 327 | # :class:`~matplotlib.axes.Axes`
|
324 |
| -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
325 | 328 | #
|
326 | 329 | # Axes are subplots within the Figure. They contain Figure elements and
|
327 | 330 | # are responsible for plotting and configuring additional details. Each
|
|
331 | 334 | # Other Components
|
332 | 335 | # ^^^^^^^^^^^^^^^^
|
333 | 336 | #
|
334 |
| -# * :class:`~matplotlib.artist.Artist` |
| 337 | +# :class:`~matplotlib.artist.Artist` |
335 | 338 | #
|
336 | 339 | # Artists are the visible elements when the Figure is rendered. They
|
337 | 340 | # correspond to a specific Axes and cannot be shared or transferred.
|
|
352 | 355 | # Axes involved.
|
353 | 356 | #
|
354 | 357 | # When looking for more complex solutions to multiple graphs within a Figure,
|
355 |
| -# use the GridSpec module to organize the layout. |
| 358 | +# use the :class:`matplotlib.gridspec.GridSpec` module to organize the layout. |
356 | 359 | #
|
357 | 360 | # Explicit
|
358 | 361 | # ^^^^^^^^
|
|
363 | 366 | sharey='row',
|
364 | 367 | figsize=[8, 4],
|
365 | 368 | constrained_layout=True)
|
366 |
| -# Figure and two Axes unpacked from arguments (1, 2) as row & column |
| 369 | +# Figure and two Axes unpacked from arguments (1, 2) as row & column. |
367 | 370 | # Keyword arguments provide additional details of sharing Y-axis, Figure size
|
368 | 371 | # and layout formatting.
|
369 | 372 |
|
|
462 | 465 | # Matplotlib auotmatically manages the specific Axes so that each action of
|
463 | 466 | # plotting data does not interfere with the previous instance.
|
464 | 467 | #
|
| 468 | +# .. note:: |
| 469 | +# |
| 470 | +# There are limitations for customizing the implicit approach without |
| 471 | +# referencing specific Axes and Artists within the Figure. For more |
| 472 | +# advanced configurations, the explicit approach is recommended. |
| 473 | +# |
| 474 | +# Generalized Function Guidelines |
| 475 | +# ------------------------------- |
| 476 | +# |
| 477 | +# For users with that have recurring plots and graphs, the Matplotlib |
| 478 | +# community recommends a signature function similar to the format below. |
| 479 | + |
| 480 | + |
| 481 | +def my_plotter(ax, data1, data2, param_dict): |
| 482 | + """ |
| 483 | + Parameters |
| 484 | + ---------- |
| 485 | + :param ax: Axes |
| 486 | + :param data1: array of X data |
| 487 | + :param data2: array of Y data |
| 488 | + :param param_dict: Dictionary of keyword arguments to pass to method |
| 489 | +
|
| 490 | + Returns |
| 491 | + ------- |
| 492 | + :returns: out : list of artists added |
| 493 | + """ |
| 494 | + out = ax.plot(data1, data2, **param_dict) |
| 495 | + # Note: Other methods from Axes class are also applicable. |
| 496 | + return out |
| 497 | + |
| 498 | +############################################################################## |
| 499 | +# |
| 500 | +# .. currentmodule:: getting_started |
| 501 | +# .. autofunction:: my_plotter |
| 502 | +# |
465 | 503 | # Additional Resources
|
466 | 504 | # ====================
|
467 | 505 | #
|
0 commit comments