GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — UltraPlot/ultraplot/axes/plot.py at main · Ultraplot/UltraPlot Expand file tree/ Copy pathplot.pyMore file actions 8064 lines (7441 loc) · 309 KB / Copy pathplot.pyFile metadata and controls8064 lines (7441 loc) · 309 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 #!/usr/bin/env python3 """ The second-level axes subclass used for all ultraplot figures. Implements plotting method overrides. """ import contextlib import inspect import itertools import re import sys from collections.abc import Callable, Iterable from numbers import Integral, Number from typing import ( TYPE_CHECKING, Any, Literal, Iterable, Mapping, Optional, Sequence, TypeAlias, Union, ) import matplotlib as mpl import matplotlib.artist as martist import matplotlib.axes as maxes import matplotlib.cbook as cbook import matplotlib.cm as mcm import matplotlib.collections as mcollections import matplotlib.colors as mcolors import matplotlib.container as mcontainer import matplotlib.contour as mcontour import matplotlib.image as mimage import matplotlib.lines as mlines import matplotlib.patches as mpatches import matplotlib.pyplot as mplt import matplotlib.ticker as mticker import numpy as np import numpy.ma as ma from numpy.typing import ArrayLike from packaging import version from .. import _sharing as psharing from .. import colors as pcolors from .. import constructor, utils from .._config import rc from ..internals import ( _alias_kwargs, _canonicalize_kwargs, _get_aliases, _not_none, _pop_kwargs, _pop_params, _pop_props, _version_mpl, context, docstring, guides, ic, # noqa: F401 inputs, warnings, ) from ..utils import units from . import base try: from cartopy.crs import PlateCarree except ModuleNotFoundError: PlateCarree = object __all__ = ["PlotAxes"] if TYPE_CHECKING: from .plot_types.treemap import ( Bounds, TreemapColors, TreemapData, TreemapInput, TreemapResult, ValueFormat, ) # Constants # NOTE: Increased from native linewidth of 0.25 matplotlib uses for grid box edges. # This is half of rc['patch.linewidth'] of 0.6. Half seems like a nice default. EDGEWIDTH = 0.3 DataInput: TypeAlias = ArrayLike ColorTupleRGB: TypeAlias = tuple[float, float, float] ColorTupleRGBA: TypeAlias = tuple[float, float, float, float] ColorInput: TypeAlias = DataInput | str | ColorTupleRGB | ColorTupleRGBA | None ParsedColor: TypeAlias = DataInput | list[str] | str | None # Data argument docstrings _args_1d_docstring = """ *args : {y} or {x}, {y} The data passed as positional or keyword arguments. Interpreted as follows: * If only `{y}` coordinates are passed, try to infer the `{x}` coordinates from the `~pandas.Series` or :class:`~pandas.DataFrame` indices or the :class:`~xarray.DataArray` coordinates. Otherwise, the `{x}` coordinates are ``np.arange(0, {y}.shape[0])``. * If the `{y}` coordinates are a 2D array, plot each column of data in succession (except where each column of data represents a statistical distribution, as with ``boxplot``, ``violinplot``, or when using ``means=True`` or ``medians=True``). * If any arguments are `pint.Quantity`, auto-add the pint unit registry to matplotlib's unit registry using `~pint.UnitRegistry.setup_matplotlib`. A `pint.Quantity` embedded in an `xarray.DataArray` is also supported. """ _args_1d_multi_docstring = """ *args : {y}2 or {x}, {y}2, or {x}, {y}1, {y}2 The data passed as positional or keyword arguments. Interpreted as follows: * If only `{y}` coordinates are passed, try to infer the `{x}` coordinates from the `~pandas.Series` or :class:`~pandas.DataFrame` indices or the :class:`~xarray.DataArray` coordinates. Otherwise, the `{x}` coordinates are ``np.arange(0, {y}2.shape[0])``. * If only `{x}` and `{y}2` coordinates are passed, set the `{y}1` coordinates to zero. This draws elements originating from the zero line. * If both `{y}1` and `{y}2` are provided, draw elements between these points. If either are 2D, draw elements by iterating over each column. * If any arguments are `pint.Quantity`, auto-add the pint unit registry to matplotlib's unit registry using `~pint.UnitRegistry.setup_matplotlib`. A `pint.Quantity` embedded in an `xarray.DataArray` is also supported. """ _args_2d_docstring = """ *args : {z} or x, y, {z} The data passed as positional or keyword arguments. Interpreted as follows: * If only {zvar} coordinates are passed, try to infer the `x` and `y` coordinates from the :class:`~pandas.DataFrame` indices and columns or the :class:`~xarray.DataArray` coordinates. Otherwise, the `y` coordinates are ``np.arange(0, y.shape[0])`` and the `x` coordinates are ``np.arange(0, y.shape[1])``. * For ``pcolor`` and ``pcolormesh``, calculate coordinate *edges* using `~ultraplot.utils.edges` or :func:`~ultraplot.utils.edges2d` if *centers* were provided. For all other methods, calculate coordinate *centers* if *edges* were provided. * If the `x` or `y` coordinates are `pint.Quantity`, auto-add the pint unit registry to matplotlib's unit registry using `~pint.UnitRegistry.setup_matplotlib`. If the {zvar} coordinates are `pint.Quantity`, pass the magnitude to the plotting command. A `pint.Quantity` embedded in an `xarray.DataArray` is also supported. """ docstring._snippet_manager["plot.args_1d_y"] = _args_1d_docstring.format(x="x", y="y") docstring._snippet_manager["plot.args_1d_x"] = _args_1d_docstring.format(x="y", y="x") docstring._snippet_manager["plot.args_1d_multiy"] = _args_1d_multi_docstring.format( x="x", y="y" ) # noqa: E501 docstring._snippet_manager["plot.args_1d_multix"] = _args_1d_multi_docstring.format( x="y", y="x" ) # noqa: E501 docstring._snippet_manager["plot.args_2d"] = _args_2d_docstring.format( z="z", zvar="`z`" ) # noqa: E501 docstring._snippet_manager["plot.args_2d_flow"] = _args_2d_docstring.format( z="u, v", zvar="`u` and `v`" ) # noqa: E501 # Shared docstrings _args_1d_shared_docstring = """ data : dict-like, optional A dict-like dataset container (e.g., :class:`~pandas.DataFrame` or `~xarray.Dataset`). If passed, each data argument can optionally be a string `key` and the arrays used for plotting are retrieved with ``data[key]``. This is a `native matplotlib feature <https://matplotlib.org/stable/gallery/misc/keyword_plotting.html>`__. autoformat : bool, default: :rc:`autoformat` Whether the `x` axis labels, `y` axis labels, axis formatters, axes titles, legend titles, and colorbar labels are automatically configured when a `~pandas.Series`, :class:`~pandas.DataFrame`, :class:`~xarray.DataArray`, or `~pint.Quantity` is passed to the plotting command. Formatting of `pint.Quantity` unit strings is controlled by :rc:`unitformat`. """ _args_2d_shared_docstring = """ %(plot.args_1d_shared)s transpose : bool, default: False Whether to transpose the input data. This should be used when passing datasets with column-major dimension order ``(x, y)``. Otherwise row-major dimension order ``(y, x)`` is expected. order : {'C', 'F'}, default: 'C' Alternative to `transpose`. ``'C'`` corresponds to the default C-cyle row-major ordering (equivalent to ``transpose=False``). ``'F'`` corresponds to Fortran-style column-major ordering (equivalent to ``transpose=True``). globe : bool, default: False For `ultraplot.axes.GeoAxes` only. Whether to enforce global coverage. When set to ``True`` this does the following: #. Interpolates input data to the North and South poles by setting the data values at the poles to the mean from latitudes nearest each pole. #. Makes meridional coverage "circular", i.e. the last longitude coordinate equals the first longitude coordinate plus 360\N{DEGREE SIGN}. #. When basemap is the backend, cycles 1D longitude vectors to fit within the map edges. For example, if the central longitude is 90\N{DEGREE SIGN}, the data is shifted so that it spans -90\N{DEGREE SIGN} to 270\N{DEGREE SIGN}. """ docstring._snippet_manager["plot.args_1d_shared"] = _args_1d_shared_docstring docstring._snippet_manager["plot.args_2d_shared"] = _args_2d_shared_docstring _curved_quiver_docstring = """ Draws curved vector field arrows (streamlines with arrows) for 2D vector fields. Parameters ---------- x, y : 1D or 2D arrays Grid coordinates. u, v : 2D arrays Vector components. color : color or 2D array, optional Streamline color. density : float or (float, float), optional Controls the closeness of streamlines. grains : int or (int, int), optional Number of seed points in x and y. linewidth : float or 2D array, optional Width of streamlines. cmap, norm : optional Colormap and normalization for array colors. colorbar, colorbar_kw : optional Add a colorbar for array-valued streamline colors. arrowsize : float, optional Arrow size scaling. arrowstyle : str, optional Arrow style specification. transform : optional Matplotlib transform. zorder : float, optional Z-order for lines/arrows. start_points : (N, 2) array, optional Starting points for streamlines. Returns ------- CurvedQuiverSet Container with attributes: - lines: LineCollection of streamlines - arrows: PatchCollection of arrows """ docstring._snippet_manager["plot.curved_quiver"] = _curved_quiver_docstring _sankey_docstring = """ Draw a Sankey diagram. Parameters ---------- flows : sequence of float or flow tuples If a numeric sequence, use Matplotlib's Sankey implementation. Otherwise, expect flow tuples or dicts describing (source, target, value). nodes : sequence or dict, optional Node identifiers or dicts with ``id``/``label``/``color`` keys. If omitted, nodes are inferred from flow sources/targets. labels : sequence of str, optional Labels for each flow in Matplotlib's Sankey mode. orientations : sequence of int, optional Flow orientations (-1: down, 0: right, 1: up) for Matplotlib's Sankey. pathlengths : float or sequence of float, optional Path lengths for each flow in Matplotlib's Sankey. Defaults to :rc:`sankey.pathlengths` when omitted. trunklength : float, optional Length of the trunk between the input and output flows. Defaults to :rc:`sankey.trunklength` when omitted. patchlabel : str, optional Label for the main patch in Matplotlib's Sankey mode. Defaults to :rc:`sankey.pathlabel` when omitted. scale, unit, format, gap, radius, shoulder, offset, head_angle, margin, tolerance : optional Passed to `matplotlib.sankey.Sankey`. prior : int, optional Index of a prior diagram to connect to. connect : (int, int), optional Flow indices for the prior and current diagram connection. Defaults to :rc:`sankey.connect` when omitted. rotation : float, optional Rotation angle in degrees. Defaults to :rc:`sankey.rotation` when omitted. node_kw, flow_kw, label_kw : dict-like, optional Style dictionaries for the layered Sankey renderer. node_label_kw, flow_label_kw : dict-like, optional Label style dictionaries for node and flow labels in layered mode. node_label_box : bool or dict-like, optional If ``True``, draw a rounded box behind node labels. If dict-like, used as the ``bbox`` argument for node label styling. style : {'budget', 'pastel', 'mono'}, optional Built-in styling presets for layered mode. node_order : sequence, optional Explicit node ordering for layered mode. layer_order : sequence, optional Explicit layer ordering for layered mode. group_cycle : sequence, optional Cycle for flow group colors (defaults to flow cycle). flow_other : float, optional Aggregate flows below this threshold into a single ``other_label``. other_label : str, optional Label for the aggregated flow target. Defaults to :rc:`sankey.other_label` when omitted. value_format : str or callable, optional Formatter for flow labels when not explicitly provided. node_label_outside : {'auto', True, False}, optional Place node labels outside narrow nodes. Defaults to :rc:`sankey.node_label_outside` when omitted. node_label_offset : float, optional Offset for outside node labels (axes-relative units). Defaults to :rc:`sankey.node_label_offset` when omitted. flow_sort : bool, optional Whether to sort flows by target position to reduce crossings. Defaults to :rc:`sankey.flow_sort` when omitted. flow_label_pos : float, optional Horizontal placement for single flow labels (0 to 1 along the ribbon). Defaults to :rc:`sankey.flow_label_pos` when omitted. When flow labels overlap, positions are redistributed between 0.25 and 0.75. node_labels, flow_labels : bool, optional Whether to draw node or flow labels in layered mode. Defaults to :rc:`sankey.node_labels` and :rc:`sankey.flow_labels` when omitted. align : {'center', 'top', 'bottom'}, optional Vertical alignment for nodes within each layer in layered mode. Defaults to :rc:`sankey.align` when omitted. layers : dict-like, optional Manual layer assignments for nodes in layered mode. **kwargs Patch properties passed to `matplotlib.sankey.Sankey.add` in Matplotlib mode. Layered defaults ---------------- Layered mode uses :rc:`sankey.nodepad`, :rc:`sankey.nodewidth`, :rc:`sankey.margin`, :rc:`sankey.flow.alpha`, :rc:`sankey.flow.curvature`, and :rc:`sankey.node.facecolor` when not set explicitly. Returns ------- matplotlib.sankey.Sankey or list or SankeyDiagram The Sankey diagram instance, or a list for multi-diagram usage. For layered mode, returns a `~ultraplot.axes.plot_types.sankey.SankeyDiagram`. """ docstring._snippet_manager["plot.sankey"] = _sankey_docstring _chord_docstring = """ Draw a chord diagram using pyCirclize. Parameters ---------- matrix : str, Path, pandas.DataFrame, or Matrix Input matrix for the chord diagram. start, end : float, optional Plot start and end degrees (-360 <= start < end <= 360). space : float or sequence of float, optional Space degrees between sectors. endspace : bool, optional If True, insert space after the final sector. r_lim : 2-tuple of float, optional Outer track radius limits (0 to 100). cmap : str or dict, optional Colormap name or name-to-color mapping for sectors and links. If omitted, UltraPlot's color cycle is used. link_cmap : list of (from, to, color), optional Override link colors. ticks_interval : int, optional Tick interval for sector tracks. If None, no ticks are shown. order : {'asc', 'desc'} or list, optional Node ordering strategy or explicit node order. label_kw, ticks_kw, link_kw : dict-like, optional Keyword arguments passed to pyCirclize for labels, ticks, and links. link_kw_handler : callable, optional Callback to customize per-link keyword arguments. tooltip : bool, optional Enable interactive tooltips (requires ipympl). Returns ------- pycirclize.Circos The underlying Circos instance. """ docstring._snippet_manager["plot.chord_diagram"] = _chord_docstring _radar_docstring = """ Draw a radar chart using pyCirclize. Parameters ---------- table : str, Path, pandas.DataFrame, or RadarTable Input table for the radar chart. r_lim : 2-tuple of float, optional Radar chart radius limits (0 to 100). vmin, vmax : float, optional Value range for the radar chart. fill : bool, optional Whether to fill the radar polygons. marker_size : int, optional Marker size for radar points. bg_color : color-spec or None, optional Background fill color. circular : bool, optional Whether to draw circular grid lines. cmap : str or dict, optional Colormap name or row-name-to-color mapping. If omitted, UltraPlot's color cycle is used. show_grid_label : bool, optional Whether to show radial grid labels. grid_interval_ratio : float or None, optional Grid interval ratio (0 to 1). grid_line_kw, grid_label_kw : dict-like, optional Keyword arguments passed to pyCirclize for grid lines and labels. grid_label_formatter : callable, optional Formatter for grid label values. label_kw_handler, line_kw_handler, marker_kw_handler : callable, optional Per-series styling callbacks passed to pyCirclize. Returns ------- pycirclize.Circos The underlying Circos instance. """ docstring._snippet_manager["plot.radar_chart"] = _radar_docstring _circos_docstring = """ Create a Circos instance using pyCirclize. Parameters ---------- sectors : mapping Sector name and size (or range) mapping. start, end : float, optional Plot start and end degrees (-360 <= start < end <= 360). space : float or sequence of float, optional Space degrees between sectors. endspace : bool, optional If True, insert space after the final sector. sector2clockwise : dict, optional Override clockwise settings per sector. show_axis_for_debug : bool, optional Show the polar axis for debug layout. plot : bool, optional If True, immediately render the circos figure on this axes. tooltip : bool, optional Enable interactive tooltips (requires ipympl). Returns ------- pycirclize.Circos The underlying Circos instance. """ docstring._snippet_manager["plot.circos"] = _circos_docstring _phylogeny_docstring = """ Draw a phylogenetic tree using pyCirclize. Parameters ---------- tree_data : str, Path, or Tree Tree data (file, URL, Tree object, or tree string). start, end : float, optional Plot start and end degrees (-360 <= start < end <= 360). r_lim : 2-tuple of float, optional Tree track radius limits (0 to 100). format : str, optional Tree format (`newick`, `phyloxml`, `nexus`, `nexml`, `cdao`). outer : bool, optional If True, plot tree on the outer side. align_leaf_label : bool, optional If True, align leaf labels. ignore_branch_length : bool, optional Ignore branch lengths when plotting. leaf_label_size : float, optional Leaf label size. leaf_label_rmargin : float, optional Leaf label radius margin. reverse : bool, optional Reverse tree direction. ladderize : bool, optional Ladderize tree. line_kw, align_line_kw : dict-like, optional Keyword arguments for tree line styling. label_formatter : callable, optional Formatter for leaf labels. tooltip : bool, optional Enable interactive tooltips (requires ipympl). Returns ------- pycirclize.Circos, pycirclize.TreeViz The Circos instance and TreeViz helper. """ docstring._snippet_manager["plot.phylogeny"] = _phylogeny_docstring _circos_bed_docstring = """ Create a Circos instance from a BED file using pyCirclize. Parameters ---------- bed_file : str or Path BED file describing chromosome ranges. start, end : float, optional Plot start and end degrees (-360 <= start < end <= 360). space : float or sequence of float, optional Space degrees between sectors. endspace : bool, optional If True, insert space after the final sector. sector2clockwise : dict, optional Override clockwise settings per sector. plot : bool, optional If True, immediately render the circos figure on this axes. tooltip : bool, optional Enable interactive tooltips (requires ipympl). Returns ------- pycirclize.Circos The underlying Circos instance. """ docstring._snippet_manager["plot.circos_bed"] = _circos_bed_docstring # Auto colorbar and legend docstring _guide_docstring = """ colorbar : bool, int, or str, optional If not ``None``, this is a location specifying where to draw an *inset* or *outer* colorbar from the resulting object(s). If ``True``, the default :rc:`colorbar.loc` is used. If the same location is used in successive plotting calls, object(s) will be added to the existing colorbar in that location (valid for colorbars built from lists of artists). Valid locations are shown in in `~ultraplot.axes.Axes.colorbar`. colorbar_kw : dict-like, optional Extra keyword args for the call to `~ultraplot.axes.Axes.colorbar`. legend : bool, int, or str, optional Location specifying where to draw an *inset* or *outer* legend from the resulting object(s). If ``True``, the default :rc:`legend.loc` is used. If the same location is used in successive plotting calls, object(s) will be added to existing legend in that location. Valid locations are shown in :meth:`~ultraplot.axes.Axes.legend`. legend_kw : dict-like, optional Extra keyword args for the call to :class:`~ultraplot.axes.Axes.legend`. """ docstring._snippet_manager["plot.guide"] = _guide_docstring # Misc shared 1D plotting docstrings _inbounds_docstring = """ inbounds : bool, default: :rc:`axes.inbounds` Whether to restrict the default `y` (`x`) axis limits to account for only in-bounds data when the `x` (`y`) axis limits have been locked. See also :rcraw:`axes.inbounds` and :rcraw:`cmap.inbounds`. """ _error_means_docstring = """ means : bool, default: False Whether to plot the means of each column for 2D `{y}` coordinates. Means are calculated with `numpy.nanmean`. If no other arguments are specified, this also sets ``barstd=True`` (and ``boxstd=True`` for violin plots). medians : bool, default: False Whether to plot the medians of each column for 2D `{y}` coordinates. Medians are calculated with `numpy.nanmedian`. If no other arguments arguments are specified, this also sets ``barstd=True`` (and ``boxstd=True`` for violin plots). """ _error_bars_docstring = """ barstds : bool, float, or 2-tuple of float, optional Valid only if `mean` or `median` is ``True``. Standard deviation multiples for *thin error bars* with optional whiskers (i.e., caps). If scalar, then +/- that multiple is used. If ``True``, the default standard deviation range of +/-3 is used. barpctiles : bool, float, or 2-tuple of float, optional Valid only if `mean` or `median` is ``True``. As with `barstd`, but instead using percentiles for the error bars. If scalar, that percentile range is used (e.g., ``90`` shows the 5th to 95th percentiles). If ``True``, the default percentile range of 0 to 100 is used. bardata : array-like, optional Valid only if `mean` and `median` are ``False``. If shape is 2 x N, these are the lower and upper bounds for the thin error bars. If shape is N, these are the absolute, symmetric deviations from the central points. boxstds, boxpctiles, boxdata : optional As with `barstd`, `barpctile`, and `bardata`, but for *thicker error bars* representing a smaller interval than the thin error bars. If `boxstds` is ``True``, the default standard deviation range of +/-1 is used. If `boxpctiles` is ``True``, the default percentile range of 25 to 75 is used (i.e., the interquartile range). When "boxes" and "bars" are combined, this has the effect of drawing miniature box-and-whisker plots. capsize : float, default: :rc:`errorbar.capsize` The cap size for thin error bars in points. barz, barzorder, boxz, boxzorder : float, default: 2.5 The "zorder" for the thin and thick error bars. barc, barcolor, boxc, boxcolor \ : color-spec, default: :rc:`boxplot.whiskerprops.color` Colors for the thin and thick error bars. barlw, barlinewidth, boxlw, boxlinewidth \ : float, default: :rc:`boxplot.whiskerprops.linewidth` Line widths for the thin and thick error bars, in points. The default for boxes is 4 times :rcraw:`boxplot.whiskerprops.linewidth`. boxm, boxmarker : bool or marker-spec, default: 'o' Whether to draw a small marker in the middle of the box denoting the mean or median position. Ignored if `boxes` is ``False``. boxms, boxmarkersize : size-spec, default: ``(2 * boxlinewidth) ** 2`` The marker size for the `boxmarker` marker in points ** 2. boxmc, boxmarkercolor, boxmec, boxmarkeredgecolor : color-spec, default: 'w' Color, face color, and edge color for the `boxmarker` marker. """ _error_shading_docstring = """ shadestds, shadepctiles, shadedata : optional As with `barstd`, `barpctile`, and `bardata`, but using *shading* to indicate the error range. If `shadestds` is ``True``, the default standard deviation range of +/-2 is used. If `shadepctiles` is ``True``, the default percentile range of 10 to 90 is used. fadestds, fadepctiles, fadedata : optional As with `shadestd`, `shadepctile`, and `shadedata`, but for an additional, more faded, *secondary* shaded region. If `fadestds` is ``True``, the default standard deviation range of +/-3 is used. If `fadepctiles` is ``True``, the default percentile range of 0 to 100 is used. shadec, shadecolor, fadec, fadecolor : color-spec, default: None Colors for the different shaded regions. The parent artist color is used by default. shadez, shadezorder, fadez, fadezorder : float, default: 1.5 The "zorder" for the different shaded regions. shadea, shadealpha, fadea, fadealpha : float, default: 0.4, 0.2 The opacity for the different shaded regions. shadelw, shadelinewidth, fadelw, fadelinewidth : float, default: :rc:`patch.linewidth`. The edge line width for the shading patches. shdeec, shadeedgecolor, fadeec, fadeedgecolor : float, default: 'none' The edge color for the shading patches. shadelabel, fadelabel : bool or str, optional Labels for the shaded regions to be used as separate legend entries. To toggle labels "on" and apply a *default* label, use e.g. ``shadelabel=True``. To apply a *custom* label, use e.g. ``shadelabel='label'``. Otherwise, the shading is drawn underneath the line and/or marker in the legend entry. """ docstring._snippet_manager["plot.inbounds"] = _inbounds_docstring docstring._snippet_manager["plot.error_means_y"] = _error_means_docstring.format(y="y") docstring._snippet_manager["plot.error_means_x"] = _error_means_docstring.format(y="x") docstring._snippet_manager["plot.error_bars"] = _error_bars_docstring docstring._snippet_manager["plot.error_shading"] = _error_shading_docstring # Color docstrings _cycle_docstring = """ cycle : cycle-spec, optional The cycle specifer, passed to the `~ultraplot.constructor.Cycle` constructor. If the returned cycler is unchanged from the current cycler, the axes cycler will not be reset to its first position. To disable property cycling and just use black for the default color, use ``cycle=False``, ``cycle='none'``, or ``cycle=()`` (analogous to disabling ticks with e.g. ``xformatter='none'``). To restore the default property cycler, use ``cycle=True``. cycle_kw : dict-like, optional Passed to `~ultraplot.constructor.Cycle`. """ _cmap_norm_docstring = """ cmap : colormap-spec, default: \ :rc:`cmap.sequential` or :rc:`cmap.diverging` The colormap specifer, passed to the :class:`~ultraplot.constructor.Colormap` constructor function. If :rcraw:`cmap.autodiverging` is ``True`` and the normalization range contains negative and positive values then :rcraw:`cmap.diverging` is used. Otherwise :rcraw:`cmap.sequential` is used. cmap_kw : dict-like, optional Passed to :class:`~ultraplot.constructor.Colormap`. colors : color-spec or sequence of color-spec, optional The color(s) used to create a :class:`~ultraplot.colors.DiscreteColormap`. If not passed, `cmap` is used. norm : norm-spec, default: \ `~matplotlib.colors.Normalize` or `~ultraplot.colors.DivergingNorm` The data value normalizer, passed to the `~ultraplot.constructor.Norm` constructor function. If `discrete` is ``True`` then 1) this affects the default level-generation algorithm (e.g. ``norm='log'`` builds levels in log-space) and 2) this is passed to `~ultraplot.colors.DiscreteNorm` to scale the colors before they are discretized (if `norm` is not already a `~ultraplot.colors.DiscreteNorm`). If :rcraw:`cmap.autodiverging` is ``True`` and the normalization range contains negative and positive values then `~ultraplot.colors.DivergingNorm` is used. Otherwise `~matplotlib.colors.Normalize` is used. norm_kw : dict-like, optional Passed to `~ultraplot.constructor.Norm`. vcenter : float, optional The data value at the center of a diverging normalizer. If `norm` is omitted, selects `~ultraplot.colors.DivergingNorm`. Also accepted in `norm_kw`. For a pre-constructed normalizer, set the center in its constructor instead. extend : {'neither', 'both', 'min', 'max'}, default: 'neither' Direction for drawing colorbar "extensions" indicating out-of-bounds data on the end of the colorbar. discrete : bool, default: :rc:`cmap.discrete` If ``False``, then `~ultraplot.colors.DiscreteNorm` is not applied to the colormap. Instead, for non-contour plots, the number of levels will be roughly controlled by :rcraw:`cmap.lut`. This has a similar effect to using `levels=large_number` but it may improve rendering speed. Default is ``True`` only for contouring commands like `~ultraplot.axes.Axes.contourf` and pseudocolor commands like `~ultraplot.axes.Axes.pcolor`. sequential, diverging, cyclic, qualitative : bool, default: None Boolean arguments used if `cmap` is not passed. Set these to ``True`` to use the default :rcraw:`cmap.sequential`, :rcraw:`cmap.diverging`, :rcraw:`cmap.cyclic`, and :rcraw:`cmap.qualitative` colormaps. The `diverging` option also applies `~ultraplot.colors.DivergingNorm` as the default continuous normalizer. """ docstring._snippet_manager["plot.cycle"] = _cycle_docstring docstring._snippet_manager["plot.cmap_norm"] = _cmap_norm_docstring _log_doc = """ Plot {kind} UltraPlot is optimized for visualizing logarithmic scales by default. For cases with large differences in magnitude, we recommend setting `rc["formatter.log"] = True` to enhance axis label formatting. {matplotlib_doc} """ docstring._snippet_manager["plot.loglog"] = _log_doc.format( kind="loglog", matplotlib_doc=mplt.loglog.__doc__ ) docstring._snippet_manager["plot.semilogy"] = _log_doc.format( kind="semilogy", matplotlib_doc=mplt.semilogy.__doc__ ) docstring._snippet_manager["plot.semilogx"] = _log_doc.format( kind="semilogx", matplotlib_doc=mplt.semilogx.__doc__ ) # Levels docstrings # NOTE: In some functions we only need some components _vmin_vmax_docstring = """ vmin, vmax : float, optional The minimum and maximum color scale values used with the `norm` normalizer. If `discrete` is ``False`` these are the absolute limits, and if `discrete` is ``True`` these are the approximate limits used to automatically determine `levels` or `values` lists at "nice" intervals. If `levels` or `values` were already passed as lists, these are ignored, and `vmin` and `vmax` are set to the minimum and maximum of the lists. If `robust` was passed, the default `vmin` and `vmax` are some percentile range of the data values. Otherwise, the default `vmin` and `vmax` are the minimum and maximum of the data values. """ _manual_levels_docstring = """ levels : int or sequence of float, default: :rc:`cmap.levels` The number of level edges or a sequence of level edges. If the former, `locator` is used to generate this many level edges at "nice" intervals. If the latter, the levels should be monotonically increasing or decreasing (note decreasing levels fail with ``contour`` plots). values : int or sequence of float, default: None The number of level centers or a sequence of level centers. If the former, `locator` is used to generate this many level centers at "nice" intervals. If the latter, levels are inferred using `~ultraplot.utils.edges`. This will override any `levels` input. center_levels : bool, default False If set to true, the discrete color bar bins will be centered on the level values instead of using the level values as the edges of the discrete bins. This option can be used for diverging, discrete color bars with both positive and negative data to ensure data near zero is properly represented. """ _auto_levels_docstring = """ robust : bool, float, or 2-tuple, default: :rc:`cmap.robust` If ``True`` and `vmin` or `vmax` were not provided, they are determined from the 2nd and 98th data percentiles rather than the minimum and maximum. If float, this percentile range is used (for example, ``90`` corresponds to the 5th to 95th percentiles). If 2-tuple of float, these specific percentiles should be used. This feature is useful when your data has large outliers. inbounds : bool, default: :rc:`cmap.inbounds` If ``True`` and `vmin` or `vmax` were not provided, when axis limits have been explicitly restricted with :func:`~matplotlib.axes.Axes.set_xlim` or :func:`~matplotlib.axes.Axes.set_ylim`, out-of-bounds data is ignored. See also :rcraw:`cmap.inbounds` and :rcraw:`axes.inbounds`. locator : locator-spec, default: `matplotlib.ticker.MaxNLocator` The locator used to determine level locations if `levels` or `values` were not already passed as lists. Passed to the `~ultraplot.constructor.Locator` constructor. Default is `~matplotlib.ticker.MaxNLocator` with `levels` integer levels. locator_kw : dict-like, optional Keyword arguments passed to `matplotlib.ticker.Locator` class. symmetric : bool, default: False If ``True``, the normalization range or discrete colormap levels are symmetric about zero. positive : bool, default: False If ``True``, the normalization range or discrete colormap levels are positive with a minimum at zero. negative : bool, default: False If ``True``, the normaliation range or discrete colormap levels are negative with a minimum at zero. nozero : bool, default: False If ``True``, ``0`` is removed from the level list. This is mainly useful for single-color `~matplotlib.axes.Axes.contour` plots. """ docstring._snippet_manager["plot.vmin_vmax"] = _vmin_vmax_docstring docstring._snippet_manager["plot.levels_manual"] = _manual_levels_docstring docstring._snippet_manager["plot.levels_auto"] = _auto_levels_docstring # Labels docstrings _label_docstring = """ label, value : float or str, optional The single legend label or colorbar coordinate to be used for this plotted element. Can be numeric or string. This is generally used with 1D positional arguments. """ _labels_1d_docstring = """ %(plot.label)s labels, values : sequence of float or sequence of str, optional The legend labels or colorbar coordinates used for each plotted element. Can be numeric or string, and must match the number of plotted elements. This is generally used with 2D positional arguments. """ _labels_2d_docstring = """ label : str, optional The legend label to be used for this object. In the case of contours, this is paired with the the central artist in the artist list returned by `matplotlib.contour.ContourSet.legend_elements`. labels : bool, optional Whether to apply labels to contours and grid boxes. The text will be white when the luminance of the underlying filled contour or grid box is less than 50 and black otherwise. labels_kw : dict-like, optional Ignored if `labels` is ``False``. Extra keyword args for the labels. For contour plots, this is passed to `~matplotlib.axes.Axes.clabel`. Otherwise, this is passed to `~matplotlib.axes.Axes.text`. formatter : formatter-spec, optional The `~matplotlib.ticker.Formatter` used to format number labels. Passed to the `~ultraplot.constructor.Formatter` constructor. formatter_kw : dict-like, optional Keyword arguments passed to `matplotlib.ticker.Formatter` class. precision : int, optional The maximum number of decimal places for number labels generated with the default formatter `~ultraplot.ticker.Simpleformatter`. """ docstring._snippet_manager["plot.label"] = _label_docstring docstring._snippet_manager["plot.labels_1d"] = _labels_1d_docstring docstring._snippet_manager["plot.labels_2d"] = _labels_2d_docstring # Negative-positive colors _negpos_docstring = """ negpos : bool, default: False Whether to shade {objects} where ``{pos}`` with `poscolor` and where ``{neg}`` with `negcolor`. If ``True`` this function will return a length-2 silent list of handles. negcolor, poscolor : color-spec, default: :rc:`negcolor`, :rc:`poscolor` Colors to use for the negative and positive {objects}. Ignored if `negpos` is ``False``. """ docstring._snippet_manager["plot.negpos_fill"] = _negpos_docstring.format( objects="patches", neg="y2 < y1", pos="y2 >= y1" ) docstring._snippet_manager["plot.negpos_lines"] = _negpos_docstring.format( objects="lines", neg="ymax < ymin", pos="ymax >= ymin" ) docstring._snippet_manager["plot.negpos_bar"] = _negpos_docstring.format( objects="bars", neg="height < 0", pos="height >= 0" ) # Plot docstring _plot_docstring = """ Plot standard lines. Parameters ---------- %(plot.args_1d_{y})s %(plot.args_1d_shared)s Other parameters ---------------- %(plot.cycle)s %(artist.line)s %(plot.error_means_{y})s %(plot.error_bars)s %(plot.error_shading)s %(plot.inbounds)s %(plot.labels_1d)s %(plot.guide)s **kwargs Passed to :func:`~matplotlib.axes.Axes.plot`. See also -------- PlotAxes.plot PlotAxes.plotx matplotlib.axes.Axes.plot """ docstring._snippet_manager["plot.plot"] = _plot_docstring.format(y="y") docstring._snippet_manager["plot.plotx"] = _plot_docstring.format(y="x") # Step docstring # NOTE: Internally matplotlib implements step with thin wrapper of plot _step_docstring = """ Plot step lines. Parameters ---------- %(plot.args_1d_{y})s %(plot.args_1d_shared)s Other parameters ---------------- %(plot.cycle)s %(artist.line)s %(plot.inbounds)s %(plot.labels_1d)s %(plot.guide)s **kwargs Passed to `~matplotlib.axes.Axes.step`. See also -------- PlotAxes.step PlotAxes.stepx matplotlib.axes.Axes.step """ docstring._snippet_manager["plot.step"] = _step_docstring.format(y="y") docstring._snippet_manager["plot.stepx"] = _step_docstring.format(y="x") # Stem docstring _stem_docstring = """ Plot stem lines. Parameters ---------- %(plot.args_1d_{y})s %(plot.args_1d_shared)s Other parameters ---------------- %(plot.cycle)s %(plot.inbounds)s %(plot.guide)s **kwargs Passed to `~matplotlib.axes.Axes.stem`. """ docstring._snippet_manager["plot.stem"] = _stem_docstring.format(y="x") docstring._snippet_manager["plot.stemx"] = _stem_docstring.format(y="x") # Lines docstrings _lines_docstring = """ Plot {orientation} lines. Parameters ---------- %(plot.args_1d_multi{y})s %(plot.args_1d_shared)s Other parameters ---------------- stacked : bool, default: False Whether to "stack" lines from successive columns of {y} data or plot lines on top of each other. %(plot.cycle)s %(artist.line)s %(plot.negpos_lines)s %(plot.inbounds)s %(plot.labels_1d)s %(plot.guide)s **kwargs Passed to `~matplotlib.axes.Axes.{prefix}lines`. See also -------- PlotAxes.vlines PlotAxes.hlines matplotlib.axes.Axes.vlines matplotlib.axes.Axes.hlines """ docstring._snippet_manager["plot.vlines"] = _lines_docstring.format( y="y", prefix="v", orientation="vertical" ) docstring._snippet_manager["plot.hlines"] = _lines_docstring.format( y="x", prefix="h", orientation="horizontal" ) # Scatter docstring _parametric_docstring = """ Plot a parametric line. Parameters ---------- %(plot.args_1d_y)s c, color, colors, values, labels : sequence of float, str, or color-spec, optional The parametric coordinate(s). These can be passed as a third positional argument or as a keyword argument. If they are float, the colors will be determined from `norm` and `cmap`. If they are strings, the color values will be ``np.arange(len(colors))`` and eventual colorbar ticks will be labeled with the strings. If they are colors, they are used for the line segments and `cmap` is ignored -- for example, ``colors='blue'`` makes a monochromatic "parametric" line. interp : int, default: 0 Interpolate to this many additional points between the parametric coordinates. This can be increased to make the color gradations between a small number of coordinates appear "smooth". %(plot.args_1d_shared)s Other parameters ---------------- %(plot.cmap_norm)s %(plot.vmin_vmax)s %(plot.inbounds)s scalex, scaley : bool, optional Whether the view limits are adapted to the data limits. The values are passed on to `~matplotlib.axes.Axes.autoscale_view`. %(plot.label)s %(plot.guide)s **kwargs Valid :class:`~matplotlib.collections.LineCollection` properties. Returns ------- :class:`~matplotlib.collections.LineCollection` The parametric line. See `this matplotlib example \ <https://matplotlib.org/stable/gallery/lines_bars_and_markers/multicolored_line>`__. See also -------- PlotAxes.plot |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |