doc_content
stringlengths
1
386k
doc_id
stringlengths
5
188
inverse(value)[source]
matplotlib._as_gen.matplotlib.colors.symlognorm#matplotlib.colors.SymLogNorm.inverse
matplotlib.colors.to_hex matplotlib.colors.to_hex(c, keep_alpha=False)[source] Convert c to a hex color. Parameters ccolor or numpy.ma.masked keep_alpha: bool, default: False If False, use the #rrggbb format, otherwise use #rrggbbaa. Returns str #rrggbb or #rrggbbaa hex color string
matplotlib._as_gen.matplotlib.colors.to_hex
matplotlib.colors.to_rgb matplotlib.colors.to_rgb(c)[source] Convert c to an RGB color, silently dropping the alpha channel. Examples using matplotlib.colors.to_rgb List of named colors
matplotlib._as_gen.matplotlib.colors.to_rgb
matplotlib.colors.to_rgba matplotlib.colors.to_rgba(c, alpha=None)[source] Convert c to an RGBA color. Parameters cMatplotlib color or np.ma.masked alphafloat, optional If alpha is given, force the alpha value of the returned RGBA tuple to alpha. If None, the alpha value from c is used. If c does not have an alpha channel, then alpha defaults to 1. alpha is ignored for the color value "none" (case-insensitive), which always maps to (0, 0, 0, 0). Returns tuple Tuple of floats (r, g, b, a), where each channel (red, green, blue, alpha) can assume values between 0 and 1. Examples using matplotlib.colors.to_rgba Line, Poly and RegularPoly Collection with autoscaling Line Collection Lasso Demo Ribbon Box
matplotlib._as_gen.matplotlib.colors.to_rgba
matplotlib.colors.to_rgba_array matplotlib.colors.to_rgba_array(c, alpha=None)[source] Convert c to a (n, 4) array of RGBA colors. Parameters cMatplotlib color or array of colors If c is a masked array, an ndarray is returned with a (0, 0, 0, 0) row for each masked value or row in c. alphafloat or sequence of floats, optional If alpha is given, force the alpha value of the returned RGBA tuple to alpha. If None, the alpha value from c is used. If c does not have an alpha channel, then alpha defaults to 1. alpha is ignored for the color value "none" (case-insensitive), which always maps to (0, 0, 0, 0). If alpha is a sequence and c is a single color, c will be repeated to match the length of alpha. Returns array (n, 4) array of RGBA colors, where each channel (red, green, blue, alpha) can assume values between 0 and 1. Examples using matplotlib.colors.to_rgba_array Specifying Colors
matplotlib._as_gen.matplotlib.colors.to_rgba_array
matplotlib.colors.TwoSlopeNorm classmatplotlib.colors.TwoSlopeNorm(vcenter, vmin=None, vmax=None)[source] Bases: matplotlib.colors.Normalize Normalize data with a set center. Useful when mapping data with an unequal rates of change around a conceptual center, e.g., data that range from -2 to 4, with 0 as the midpoint. Parameters vcenterfloat The data value that defines 0.5 in the normalization. vminfloat, optional The data value that defines 0.0 in the normalization. Defaults to the min value of the dataset. vmaxfloat, optional The data value that defines 1.0 in the normalization. Defaults to the max value of the dataset. Examples This maps data value -4000 to 0., 0 to 0.5, and +10000 to 1.0; data between is linearly interpolated: >>> import matplotlib.colors as mcolors >>> offset = mcolors.TwoSlopeNorm(vmin=-4000., vcenter=0., vmax=10000) >>> data = [-4000., -2000., 0., 2500., 5000., 7500., 10000.] >>> offset(data) array([0., 0.25, 0.5, 0.625, 0.75, 0.875, 1.0]) __call__(value, clip=None)[source] Map value to the interval [0, 1]. The clip argument is unused. autoscale_None(A)[source] Get vmin and vmax, and then clip at vcenter inverse(value)[source] propertyvcenter Examples using matplotlib.colors.TwoSlopeNorm Colormap Normalization
matplotlib._as_gen.matplotlib.colors.twoslopenorm
__call__(value, clip=None)[source] Map value to the interval [0, 1]. The clip argument is unused.
matplotlib._as_gen.matplotlib.colors.twoslopenorm#matplotlib.colors.TwoSlopeNorm.__call__
autoscale_None(A)[source] Get vmin and vmax, and then clip at vcenter
matplotlib._as_gen.matplotlib.colors.twoslopenorm#matplotlib.colors.TwoSlopeNorm.autoscale_None
inverse(value)[source]
matplotlib._as_gen.matplotlib.colors.twoslopenorm#matplotlib.colors.TwoSlopeNorm.inverse
matplotlib.container classmatplotlib.container.BarContainer(*args, **kwargs)[source] Bases: matplotlib.container.Container Container for the artists of bar plots (e.g. created by Axes.bar). The container can be treated as a tuple of the patches themselves. Additionally, you can access these and further parameters by the attributes. Attributes patcheslist of Rectangle The artists of the bars. errorbarNone or ErrorbarContainer A container for the error bar artists if error bars are present. None otherwise. datavaluesNone or array-like The underlying data values corresponding to the bars. orientation{'vertical', 'horizontal'}, default: None If 'vertical', the bars are assumed to be vertical. If 'horizontal', the bars are assumed to be horizontal. classmatplotlib.container.Container(*args, **kwargs)[source] Bases: tuple Base class for containers. Containers are classes that collect semantically related Artists such as the bars of a bar plot. add_callback(func)[source] Add a callback function that will be called whenever one of the Artist's properties changes. Parameters funccallable The callback function. It must have the signature: def func(artist: Artist) -> Any where artist is the calling Artist. Return values may exist but are ignored. Returns int The observer id associated with the callback. This id can be used for removing the callback with remove_callback later. See also remove_callback get_children()[source] get_label()[source] Return the label used for this artist in the legend. pchanged()[source] Call all of the registered callbacks. This function is triggered internally when a property is changed. See also add_callback remove_callback remove()[source] remove_callback(oid)[source] Remove a callback based on its observer id. See also add_callback set_label(s)[source] Set a label that will be displayed in the legend. Parameters sobject s will be converted to a string by calling str. classmatplotlib.container.ErrorbarContainer(*args, **kwargs)[source] Bases: matplotlib.container.Container Container for the artists of error bars (e.g. created by Axes.errorbar). The container can be treated as the lines tuple itself. Additionally, you can access these and further parameters by the attributes. Attributes linestuple Tuple of (data_line, caplines, barlinecols). data_line : Line2D instance of x, y plot markers and/or line. caplines : tuple of Line2D instances of the error bar caps. barlinecols : list of LineCollection with the horizontal and vertical error ranges. has_xerr, has_yerrbool True if the errorbar has x/y errors. classmatplotlib.container.StemContainer(*args, **kwargs)[source] Bases: matplotlib.container.Container Container for the artists created in a Axes.stem() plot. The container can be treated like a namedtuple (markerline, stemlines, baseline). Attributes markerlineLine2D The artist of the markers at the stem heads. stemlineslist of Line2D The artists of the vertical lines for all stems. baselineLine2D The artist of the horizontal baseline. Parameters markerline_stemlines_baselinetuple Tuple of (markerline, stemlines, baseline). markerline contains the LineCollection of the markers, stemlines is a LineCollection of the main lines, baseline is the Line2D of the baseline.
matplotlib.container_api
classmatplotlib.container.BarContainer(*args, **kwargs)[source] Bases: matplotlib.container.Container Container for the artists of bar plots (e.g. created by Axes.bar). The container can be treated as a tuple of the patches themselves. Additionally, you can access these and further parameters by the attributes. Attributes patcheslist of Rectangle The artists of the bars. errorbarNone or ErrorbarContainer A container for the error bar artists if error bars are present. None otherwise. datavaluesNone or array-like The underlying data values corresponding to the bars. orientation{'vertical', 'horizontal'}, default: None If 'vertical', the bars are assumed to be vertical. If 'horizontal', the bars are assumed to be horizontal.
matplotlib.container_api#matplotlib.container.BarContainer
classmatplotlib.container.Container(*args, **kwargs)[source] Bases: tuple Base class for containers. Containers are classes that collect semantically related Artists such as the bars of a bar plot. add_callback(func)[source] Add a callback function that will be called whenever one of the Artist's properties changes. Parameters funccallable The callback function. It must have the signature: def func(artist: Artist) -> Any where artist is the calling Artist. Return values may exist but are ignored. Returns int The observer id associated with the callback. This id can be used for removing the callback with remove_callback later. See also remove_callback get_children()[source] get_label()[source] Return the label used for this artist in the legend. pchanged()[source] Call all of the registered callbacks. This function is triggered internally when a property is changed. See also add_callback remove_callback remove()[source] remove_callback(oid)[source] Remove a callback based on its observer id. See also add_callback set_label(s)[source] Set a label that will be displayed in the legend. Parameters sobject s will be converted to a string by calling str.
matplotlib.container_api#matplotlib.container.Container
add_callback(func)[source] Add a callback function that will be called whenever one of the Artist's properties changes. Parameters funccallable The callback function. It must have the signature: def func(artist: Artist) -> Any where artist is the calling Artist. Return values may exist but are ignored. Returns int The observer id associated with the callback. This id can be used for removing the callback with remove_callback later. See also remove_callback
matplotlib.container_api#matplotlib.container.Container.add_callback
get_children()[source]
matplotlib.container_api#matplotlib.container.Container.get_children
get_label()[source] Return the label used for this artist in the legend.
matplotlib.container_api#matplotlib.container.Container.get_label
pchanged()[source] Call all of the registered callbacks. This function is triggered internally when a property is changed. See also add_callback remove_callback
matplotlib.container_api#matplotlib.container.Container.pchanged
remove()[source]
matplotlib.container_api#matplotlib.container.Container.remove
remove_callback(oid)[source] Remove a callback based on its observer id. See also add_callback
matplotlib.container_api#matplotlib.container.Container.remove_callback
set_label(s)[source] Set a label that will be displayed in the legend. Parameters sobject s will be converted to a string by calling str.
matplotlib.container_api#matplotlib.container.Container.set_label
classmatplotlib.container.ErrorbarContainer(*args, **kwargs)[source] Bases: matplotlib.container.Container Container for the artists of error bars (e.g. created by Axes.errorbar). The container can be treated as the lines tuple itself. Additionally, you can access these and further parameters by the attributes. Attributes linestuple Tuple of (data_line, caplines, barlinecols). data_line : Line2D instance of x, y plot markers and/or line. caplines : tuple of Line2D instances of the error bar caps. barlinecols : list of LineCollection with the horizontal and vertical error ranges. has_xerr, has_yerrbool True if the errorbar has x/y errors.
matplotlib.container_api#matplotlib.container.ErrorbarContainer
classmatplotlib.container.StemContainer(*args, **kwargs)[source] Bases: matplotlib.container.Container Container for the artists created in a Axes.stem() plot. The container can be treated like a namedtuple (markerline, stemlines, baseline). Attributes markerlineLine2D The artist of the markers at the stem heads. stemlineslist of Line2D The artists of the vertical lines for all stems. baselineLine2D The artist of the horizontal baseline. Parameters markerline_stemlines_baselinetuple Tuple of (markerline, stemlines, baseline). markerline contains the LineCollection of the markers, stemlines is a LineCollection of the main lines, baseline is the Line2D of the baseline.
matplotlib.container_api#matplotlib.container.StemContainer
matplotlib.contour Classes to support contour plotting and labelling for the Axes class. classmatplotlib.contour.ClabelText(x=0, y=0, text='', color=None, verticalalignment='baseline', horizontalalignment='left', multialignment=None, fontproperties=None, rotation=None, linespacing=None, rotation_mode=None, usetex=None, wrap=False, transform_rotates_text=False, *, parse_math=True, **kwargs)[source] Bases: matplotlib.text.Text Unlike the ordinary text, the get_rotation returns an updated angle in the pixel coordinate assuming that the input rotation is an angle in data coordinate (or whatever transform set). Create a Text instance at x, y with string text. Valid keyword arguments are: Property Description agg_filter a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array alpha scalar or None animated bool backgroundcolor color bbox dict with properties for patches.FancyBboxPatch clip_box unknown clip_on unknown clip_path unknown color or c color figure Figure fontfamily or family {FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'} fontproperties or font or font_properties font_manager.FontProperties or str or pathlib.Path fontsize or size float or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'} fontstretch or stretch {a numeric value in range 0-1000, 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'} fontstyle or style {'normal', 'italic', 'oblique'} fontvariant or variant {'normal', 'small-caps'} fontweight or weight {a numeric value in range 0-1000, 'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'} gid str horizontalalignment or ha {'center', 'right', 'left'} in_layout bool label object linespacing float (multiple of font size) math_fontfamily str multialignment or ma {'left', 'right', 'center'} parse_math bool path_effects AbstractPathEffect picker None or bool or float or callable position (float, float) rasterized bool rotation float or {'vertical', 'horizontal'} rotation_mode {None, 'default', 'anchor'} sketch_params (scale: float, length: float, randomness: float) snap bool or None text object transform Transform transform_rotates_text bool url str usetex bool or None verticalalignment or va {'center', 'top', 'bottom', 'baseline', 'center_baseline'} visible bool wrap bool x float y float zorder float get_rotation()[source] Return the text angle in degrees between 0 and 360. set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, backgroundcolor=<UNSET>, bbox=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, color=<UNSET>, fontfamily=<UNSET>, fontproperties=<UNSET>, fontsize=<UNSET>, fontstretch=<UNSET>, fontstyle=<UNSET>, fontvariant=<UNSET>, fontweight=<UNSET>, gid=<UNSET>, horizontalalignment=<UNSET>, in_layout=<UNSET>, label=<UNSET>, linespacing=<UNSET>, math_fontfamily=<UNSET>, multialignment=<UNSET>, parse_math=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, position=<UNSET>, rasterized=<UNSET>, rotation=<UNSET>, rotation_mode=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, text=<UNSET>, transform=<UNSET>, transform_rotates_text=<UNSET>, url=<UNSET>, usetex=<UNSET>, verticalalignment=<UNSET>, visible=<UNSET>, wrap=<UNSET>, x=<UNSET>, y=<UNSET>, zorder=<UNSET>)[source] Set multiple properties at once. Supported properties are Property Description agg_filter a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array alpha scalar or None animated bool backgroundcolor color bbox dict with properties for patches.FancyBboxPatch clip_box Bbox clip_on bool clip_path Patch or (Path, Transform) or None color or c color figure Figure fontfamily or family {FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'} fontproperties or font or font_properties font_manager.FontProperties or str or pathlib.Path fontsize or size float or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'} fontstretch or stretch {a numeric value in range 0-1000, 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'} fontstyle or style {'normal', 'italic', 'oblique'} fontvariant or variant {'normal', 'small-caps'} fontweight or weight {a numeric value in range 0-1000, 'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'} gid str horizontalalignment or ha {'center', 'right', 'left'} in_layout bool label object linespacing float (multiple of font size) math_fontfamily str multialignment or ma {'left', 'right', 'center'} parse_math bool path_effects AbstractPathEffect picker None or bool or float or callable position (float, float) rasterized bool rotation float or {'vertical', 'horizontal'} rotation_mode {None, 'default', 'anchor'} sketch_params (scale: float, length: float, randomness: float) snap bool or None text object transform Transform transform_rotates_text bool url str usetex bool or None verticalalignment or va {'center', 'top', 'bottom', 'baseline', 'center_baseline'} visible bool wrap bool x float y float zorder float classmatplotlib.contour.ContourLabeler[source] Bases: object Mixin to provide labelling capability to ContourSet. add_label(x, y, rotation, lev, cvalue)[source] Add contour label using Text class. add_label_clabeltext(x, y, rotation, lev, cvalue)[source] Add contour label using ClabelText class. add_label_near(x, y, inline=True, inline_spacing=5, transform=None)[source] Add a label near the point (x, y). Parameters x, yfloat The approximate location of the label. inlinebool, default: True If True remove the segment of the contour beneath the label. inline_spacingint, default: 5 Space in pixels to leave on each side of label when placing inline. This spacing will be exact for labels at locations where the contour is straight, less so for labels on curved contours. transformTransform or False, default: self.axes.transData A transform applied to (x, y) before labeling. The default causes (x, y) to be interpreted as data coordinates. False is a synonym for IdentityTransform; i.e. (x, y) should be interpreted as display coordinates. calc_label_rot_and_inline(slc, ind, lw, lc=None, spacing=5)[source] Calculate the appropriate label rotation given the linecontour coordinates in screen units, the index of the label location and the label width. If lc is not None or empty, also break contours and compute inlining. spacing is the empty space to leave around the label, in pixels. Both tasks are done together to avoid calculating path lengths multiple times, which is relatively costly. The method used here involves computing the path length along the contour in pixel coordinates and then looking approximately (label width / 2) away from central point to determine rotation and then to break contour if desired. clabel(levels=None, *, fontsize=None, inline=True, inline_spacing=5, fmt=None, colors=None, use_clabeltext=False, manual=False, rightside_up=True, zorder=None)[source] Label a contour plot. Adds labels to line contours in this ContourSet (which inherits from this mixin class). Parameters levelsarray-like, optional A list of level values, that should be labeled. The list must be a subset of cs.levels. If not given, all levels are labeled. fontsizestr or float, default: rcParams["font.size"] (default: 10.0) Size in points or relative size e.g., 'smaller', 'x-large'. See Text.set_size for accepted string values. colorscolor or colors or None, default: None The label colors: If None, the color of each label matches the color of the corresponding contour. If one string color, e.g., colors = 'r' or colors = 'red', all labels will be plotted in this color. If a tuple of colors (string, float, rgb, etc), different labels will be plotted in different colors in the order specified. inlinebool, default: True If True the underlying contour is removed where the label is placed. inline_spacingfloat, default: 5 Space in pixels to leave on each side of label when placing inline. This spacing will be exact for labels at locations where the contour is straight, less so for labels on curved contours. fmtFormatter or str or callable or dict, optional How the levels are formatted: If a Formatter, it is used to format all levels at once, using its Formatter.format_ticks method. If a str, it is interpreted as a %-style format string. If a callable, it is called with one level at a time and should return the corresponding label. If a dict, it should directly map levels to labels. The default is to use a standard ScalarFormatter. manualbool or iterable, default: False If True, contour labels will be placed manually using mouse clicks. Click the first button near a contour to add a label, click the second button (or potentially both mouse buttons at once) to finish adding labels. The third button can be used to remove the last label added, but only if labels are not inline. Alternatively, the keyboard can be used to select label locations (enter to end label placement, delete or backspace act like the third mouse button, and any other key will select a label location). manual can also be an iterable object of (x, y) tuples. Contour labels will be created as if mouse is clicked at each (x, y) position. rightside_upbool, default: True If True, label rotations will always be plus or minus 90 degrees from level. use_clabeltextbool, default: False If True, ClabelText class (instead of Text) is used to create labels. ClabelText recalculates rotation angles of texts during the drawing time, therefore this can be used if aspect of the axes changes. zorderfloat or None, default: (2 + contour.get_zorder()) zorder of the contour labels. Returns labels A list of Text instances for the labels. get_label_coords(distances, XX, YY, ysize, lw)[source] [Deprecated] Return x, y, and the index of a label location. Labels are plotted at a location with the smallest deviation of the contour from a straight line unless there is another label nearby, in which case the next best place on the contour is picked up. If all such candidates are rejected, the beginning of the contour is chosen. Notes Deprecated since version 3.4. get_label_width(lev, fmt, fsize)[source] [Deprecated] Return the width of the label in points. Notes Deprecated since version 3.5. get_text(lev, fmt)[source] Get the text of the label. labels(inline, inline_spacing)[source] locate_label(linecontour, labelwidth)[source] Find good place to draw a label (relatively flat part of the contour). pop_label(index=- 1)[source] Defaults to removing last label, but any index can be supplied print_label(linecontour, labelwidth)[source] Return whether a contour is long enough to hold a label. set_label_props(label, text, color)[source] Set the label properties - color, fontsize, text. too_close(x, y, lw)[source] Return whether a label is already near this location. classmatplotlib.contour.ContourSet(ax, *args, levels=None, filled=False, linewidths=None, linestyles=None, hatches=(None,), alpha=None, origin=None, extent=None, cmap=None, colors=None, norm=None, vmin=None, vmax=None, extend='neither', antialiased=None, nchunk=0, locator=None, transform=None, **kwargs)[source] Bases: matplotlib.cm.ScalarMappable, matplotlib.contour.ContourLabeler Store a set of contour lines or filled regions. User-callable method: clabel Parameters axAxes levels[level0, level1, ..., leveln] A list of floating point numbers indicating the contour levels. allsegs[level0segs, level1segs, ...] List of all the polygon segments for all the levels. For contour lines len(allsegs) == len(levels), and for filled contour regions len(allsegs) = len(levels)-1. The lists should look like level0segs = [polygon0, polygon1, ...] polygon0 = [[x0, y0], [x1, y1], ...] allkindsNone or [level0kinds, level1kinds, ...] Optional list of all the polygon vertex kinds (code types), as described and used in Path. This is used to allow multiply- connected paths such as holes within filled polygons. If not None, len(allkinds) == len(allsegs). The lists should look like level0kinds = [polygon0kinds, ...] polygon0kinds = [vertexcode0, vertexcode1, ...] If allkinds is not None, usually all polygons for a particular contour level are grouped together so that level0segs = [polygon0] and level0kinds = [polygon0kinds]. **kwargs Keyword arguments are as described in the docstring of contour. Attributes axAxes The Axes object in which the contours are drawn. collectionssilent_list of PathCollections The Artists representing the contour. This is a list of PathCollections for both line and filled contours. levelsarray The values of the contour levels. layersarray Same as levels for line contours; half-way between levels for filled contours. See ContourSet._process_colors. Draw contour lines or filled regions, depending on whether keyword arg filled is False (default) or True. Call signature: ContourSet(ax, levels, allsegs, [allkinds], **kwargs) Parameters axAxes The Axes object to draw on. levels[level0, level1, ..., leveln] A list of floating point numbers indicating the contour levels. allsegs[level0segs, level1segs, ...] List of all the polygon segments for all the levels. For contour lines len(allsegs) == len(levels), and for filled contour regions len(allsegs) = len(levels)-1. The lists should look like level0segs = [polygon0, polygon1, ...] polygon0 = [[x0, y0], [x1, y1], ...] allkinds[level0kinds, level1kinds, ...], optional Optional list of all the polygon vertex kinds (code types), as described and used in Path. This is used to allow multiply- connected paths such as holes within filled polygons. If not None, len(allkinds) == len(allsegs). The lists should look like level0kinds = [polygon0kinds, ...] polygon0kinds = [vertexcode0, vertexcode1, ...] If allkinds is not None, usually all polygons for a particular contour level are grouped together so that level0segs = [polygon0] and level0kinds = [polygon0kinds]. **kwargs Keyword arguments are as described in the docstring of contour. changed()[source] Call this whenever the mappable is changed to notify all the callbackSM listeners to the 'changed' signal. find_nearest_contour(x, y, indices=None, pixel=True)[source] Find the point in the contour plot that is closest to (x, y). Parameters x, yfloat The reference point. indiceslist of int or None, default: None Indices of contour levels to consider. If None (the default), all levels are considered. pixelbool, default: True If True, measure distance in pixel (screen) space, which is useful for manual contour labeling; else, measure distance in axes space. Returns contourCollection The contour that is closest to (x, y). segmentint The index of the Path in contour that is closest to (x, y). indexint The index of the path segment in segment that is closest to (x, y). xmin, yminfloat The point in the contour plot that is closest to (x, y). d2float The squared distance from (xmin, ymin) to (x, y). get_alpha()[source] Return alpha to be applied to all ContourSet artists. get_transform()[source] Return the Transform instance used by this ContourSet. legend_elements(variable_name='x', str_format=<class 'str'>)[source] Return a list of artists and labels suitable for passing through to legend which represent this ContourSet. The labels have the form "0 < x <= 1" stating the data ranges which the artists represent. Parameters variable_namestr The string used inside the inequality used on the labels. str_formatfunction: float -> str Function used to format the numbers in the labels. Returns artistslist[Artist] A list of the artists. labelslist[str] A list of the labels. set_alpha(alpha)[source] Set the alpha blending value for all ContourSet artists. alpha must be between 0 (transparent) and 1 (opaque). classmatplotlib.contour.QuadContourSet(ax, *args, levels=None, filled=False, linewidths=None, linestyles=None, hatches=(None,), alpha=None, origin=None, extent=None, cmap=None, colors=None, norm=None, vmin=None, vmax=None, extend='neither', antialiased=None, nchunk=0, locator=None, transform=None, **kwargs)[source] Bases: matplotlib.contour.ContourSet Create and store a set of contour lines or filled regions. This class is typically not instantiated directly by the user but by contour and contourf. Attributes axAxes The Axes object in which the contours are drawn. collectionssilent_list of PathCollections The Artists representing the contour. This is a list of PathCollections for both line and filled contours. levelsarray The values of the contour levels. layersarray Same as levels for line contours; half-way between levels for filled contours. See ContourSet._process_colors. Draw contour lines or filled regions, depending on whether keyword arg filled is False (default) or True. Call signature: ContourSet(ax, levels, allsegs, [allkinds], **kwargs) Parameters axAxes The Axes object to draw on. levels[level0, level1, ..., leveln] A list of floating point numbers indicating the contour levels. allsegs[level0segs, level1segs, ...] List of all the polygon segments for all the levels. For contour lines len(allsegs) == len(levels), and for filled contour regions len(allsegs) = len(levels)-1. The lists should look like level0segs = [polygon0, polygon1, ...] polygon0 = [[x0, y0], [x1, y1], ...] allkinds[level0kinds, level1kinds, ...], optional Optional list of all the polygon vertex kinds (code types), as described and used in Path. This is used to allow multiply- connected paths such as holes within filled polygons. If not None, len(allkinds) == len(allsegs). The lists should look like level0kinds = [polygon0kinds, ...] polygon0kinds = [vertexcode0, vertexcode1, ...] If allkinds is not None, usually all polygons for a particular contour level are grouped together so that level0segs = [polygon0] and level0kinds = [polygon0kinds]. **kwargs Keyword arguments are as described in the docstring of contour.
matplotlib.contour_api
classmatplotlib.contour.ClabelText(x=0, y=0, text='', color=None, verticalalignment='baseline', horizontalalignment='left', multialignment=None, fontproperties=None, rotation=None, linespacing=None, rotation_mode=None, usetex=None, wrap=False, transform_rotates_text=False, *, parse_math=True, **kwargs)[source] Bases: matplotlib.text.Text Unlike the ordinary text, the get_rotation returns an updated angle in the pixel coordinate assuming that the input rotation is an angle in data coordinate (or whatever transform set). Create a Text instance at x, y with string text. Valid keyword arguments are: Property Description agg_filter a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array alpha scalar or None animated bool backgroundcolor color bbox dict with properties for patches.FancyBboxPatch clip_box unknown clip_on unknown clip_path unknown color or c color figure Figure fontfamily or family {FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'} fontproperties or font or font_properties font_manager.FontProperties or str or pathlib.Path fontsize or size float or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'} fontstretch or stretch {a numeric value in range 0-1000, 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'} fontstyle or style {'normal', 'italic', 'oblique'} fontvariant or variant {'normal', 'small-caps'} fontweight or weight {a numeric value in range 0-1000, 'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'} gid str horizontalalignment or ha {'center', 'right', 'left'} in_layout bool label object linespacing float (multiple of font size) math_fontfamily str multialignment or ma {'left', 'right', 'center'} parse_math bool path_effects AbstractPathEffect picker None or bool or float or callable position (float, float) rasterized bool rotation float or {'vertical', 'horizontal'} rotation_mode {None, 'default', 'anchor'} sketch_params (scale: float, length: float, randomness: float) snap bool or None text object transform Transform transform_rotates_text bool url str usetex bool or None verticalalignment or va {'center', 'top', 'bottom', 'baseline', 'center_baseline'} visible bool wrap bool x float y float zorder float get_rotation()[source] Return the text angle in degrees between 0 and 360. set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, backgroundcolor=<UNSET>, bbox=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, color=<UNSET>, fontfamily=<UNSET>, fontproperties=<UNSET>, fontsize=<UNSET>, fontstretch=<UNSET>, fontstyle=<UNSET>, fontvariant=<UNSET>, fontweight=<UNSET>, gid=<UNSET>, horizontalalignment=<UNSET>, in_layout=<UNSET>, label=<UNSET>, linespacing=<UNSET>, math_fontfamily=<UNSET>, multialignment=<UNSET>, parse_math=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, position=<UNSET>, rasterized=<UNSET>, rotation=<UNSET>, rotation_mode=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, text=<UNSET>, transform=<UNSET>, transform_rotates_text=<UNSET>, url=<UNSET>, usetex=<UNSET>, verticalalignment=<UNSET>, visible=<UNSET>, wrap=<UNSET>, x=<UNSET>, y=<UNSET>, zorder=<UNSET>)[source] Set multiple properties at once. Supported properties are Property Description agg_filter a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array alpha scalar or None animated bool backgroundcolor color bbox dict with properties for patches.FancyBboxPatch clip_box Bbox clip_on bool clip_path Patch or (Path, Transform) or None color or c color figure Figure fontfamily or family {FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'} fontproperties or font or font_properties font_manager.FontProperties or str or pathlib.Path fontsize or size float or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'} fontstretch or stretch {a numeric value in range 0-1000, 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'} fontstyle or style {'normal', 'italic', 'oblique'} fontvariant or variant {'normal', 'small-caps'} fontweight or weight {a numeric value in range 0-1000, 'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'} gid str horizontalalignment or ha {'center', 'right', 'left'} in_layout bool label object linespacing float (multiple of font size) math_fontfamily str multialignment or ma {'left', 'right', 'center'} parse_math bool path_effects AbstractPathEffect picker None or bool or float or callable position (float, float) rasterized bool rotation float or {'vertical', 'horizontal'} rotation_mode {None, 'default', 'anchor'} sketch_params (scale: float, length: float, randomness: float) snap bool or None text object transform Transform transform_rotates_text bool url str usetex bool or None verticalalignment or va {'center', 'top', 'bottom', 'baseline', 'center_baseline'} visible bool wrap bool x float y float zorder float
matplotlib.contour_api#matplotlib.contour.ClabelText
get_rotation()[source] Return the text angle in degrees between 0 and 360.
matplotlib.contour_api#matplotlib.contour.ClabelText.get_rotation
set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, backgroundcolor=<UNSET>, bbox=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, color=<UNSET>, fontfamily=<UNSET>, fontproperties=<UNSET>, fontsize=<UNSET>, fontstretch=<UNSET>, fontstyle=<UNSET>, fontvariant=<UNSET>, fontweight=<UNSET>, gid=<UNSET>, horizontalalignment=<UNSET>, in_layout=<UNSET>, label=<UNSET>, linespacing=<UNSET>, math_fontfamily=<UNSET>, multialignment=<UNSET>, parse_math=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, position=<UNSET>, rasterized=<UNSET>, rotation=<UNSET>, rotation_mode=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, text=<UNSET>, transform=<UNSET>, transform_rotates_text=<UNSET>, url=<UNSET>, usetex=<UNSET>, verticalalignment=<UNSET>, visible=<UNSET>, wrap=<UNSET>, x=<UNSET>, y=<UNSET>, zorder=<UNSET>)[source] Set multiple properties at once. Supported properties are Property Description agg_filter a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array alpha scalar or None animated bool backgroundcolor color bbox dict with properties for patches.FancyBboxPatch clip_box Bbox clip_on bool clip_path Patch or (Path, Transform) or None color or c color figure Figure fontfamily or family {FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'} fontproperties or font or font_properties font_manager.FontProperties or str or pathlib.Path fontsize or size float or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'} fontstretch or stretch {a numeric value in range 0-1000, 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'} fontstyle or style {'normal', 'italic', 'oblique'} fontvariant or variant {'normal', 'small-caps'} fontweight or weight {a numeric value in range 0-1000, 'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'} gid str horizontalalignment or ha {'center', 'right', 'left'} in_layout bool label object linespacing float (multiple of font size) math_fontfamily str multialignment or ma {'left', 'right', 'center'} parse_math bool path_effects AbstractPathEffect picker None or bool or float or callable position (float, float) rasterized bool rotation float or {'vertical', 'horizontal'} rotation_mode {None, 'default', 'anchor'} sketch_params (scale: float, length: float, randomness: float) snap bool or None text object transform Transform transform_rotates_text bool url str usetex bool or None verticalalignment or va {'center', 'top', 'bottom', 'baseline', 'center_baseline'} visible bool wrap bool x float y float zorder float
matplotlib.contour_api#matplotlib.contour.ClabelText.set
classmatplotlib.contour.ContourLabeler[source] Bases: object Mixin to provide labelling capability to ContourSet. add_label(x, y, rotation, lev, cvalue)[source] Add contour label using Text class. add_label_clabeltext(x, y, rotation, lev, cvalue)[source] Add contour label using ClabelText class. add_label_near(x, y, inline=True, inline_spacing=5, transform=None)[source] Add a label near the point (x, y). Parameters x, yfloat The approximate location of the label. inlinebool, default: True If True remove the segment of the contour beneath the label. inline_spacingint, default: 5 Space in pixels to leave on each side of label when placing inline. This spacing will be exact for labels at locations where the contour is straight, less so for labels on curved contours. transformTransform or False, default: self.axes.transData A transform applied to (x, y) before labeling. The default causes (x, y) to be interpreted as data coordinates. False is a synonym for IdentityTransform; i.e. (x, y) should be interpreted as display coordinates. calc_label_rot_and_inline(slc, ind, lw, lc=None, spacing=5)[source] Calculate the appropriate label rotation given the linecontour coordinates in screen units, the index of the label location and the label width. If lc is not None or empty, also break contours and compute inlining. spacing is the empty space to leave around the label, in pixels. Both tasks are done together to avoid calculating path lengths multiple times, which is relatively costly. The method used here involves computing the path length along the contour in pixel coordinates and then looking approximately (label width / 2) away from central point to determine rotation and then to break contour if desired. clabel(levels=None, *, fontsize=None, inline=True, inline_spacing=5, fmt=None, colors=None, use_clabeltext=False, manual=False, rightside_up=True, zorder=None)[source] Label a contour plot. Adds labels to line contours in this ContourSet (which inherits from this mixin class). Parameters levelsarray-like, optional A list of level values, that should be labeled. The list must be a subset of cs.levels. If not given, all levels are labeled. fontsizestr or float, default: rcParams["font.size"] (default: 10.0) Size in points or relative size e.g., 'smaller', 'x-large'. See Text.set_size for accepted string values. colorscolor or colors or None, default: None The label colors: If None, the color of each label matches the color of the corresponding contour. If one string color, e.g., colors = 'r' or colors = 'red', all labels will be plotted in this color. If a tuple of colors (string, float, rgb, etc), different labels will be plotted in different colors in the order specified. inlinebool, default: True If True the underlying contour is removed where the label is placed. inline_spacingfloat, default: 5 Space in pixels to leave on each side of label when placing inline. This spacing will be exact for labels at locations where the contour is straight, less so for labels on curved contours. fmtFormatter or str or callable or dict, optional How the levels are formatted: If a Formatter, it is used to format all levels at once, using its Formatter.format_ticks method. If a str, it is interpreted as a %-style format string. If a callable, it is called with one level at a time and should return the corresponding label. If a dict, it should directly map levels to labels. The default is to use a standard ScalarFormatter. manualbool or iterable, default: False If True, contour labels will be placed manually using mouse clicks. Click the first button near a contour to add a label, click the second button (or potentially both mouse buttons at once) to finish adding labels. The third button can be used to remove the last label added, but only if labels are not inline. Alternatively, the keyboard can be used to select label locations (enter to end label placement, delete or backspace act like the third mouse button, and any other key will select a label location). manual can also be an iterable object of (x, y) tuples. Contour labels will be created as if mouse is clicked at each (x, y) position. rightside_upbool, default: True If True, label rotations will always be plus or minus 90 degrees from level. use_clabeltextbool, default: False If True, ClabelText class (instead of Text) is used to create labels. ClabelText recalculates rotation angles of texts during the drawing time, therefore this can be used if aspect of the axes changes. zorderfloat or None, default: (2 + contour.get_zorder()) zorder of the contour labels. Returns labels A list of Text instances for the labels. get_label_coords(distances, XX, YY, ysize, lw)[source] [Deprecated] Return x, y, and the index of a label location. Labels are plotted at a location with the smallest deviation of the contour from a straight line unless there is another label nearby, in which case the next best place on the contour is picked up. If all such candidates are rejected, the beginning of the contour is chosen. Notes Deprecated since version 3.4. get_label_width(lev, fmt, fsize)[source] [Deprecated] Return the width of the label in points. Notes Deprecated since version 3.5. get_text(lev, fmt)[source] Get the text of the label. labels(inline, inline_spacing)[source] locate_label(linecontour, labelwidth)[source] Find good place to draw a label (relatively flat part of the contour). pop_label(index=- 1)[source] Defaults to removing last label, but any index can be supplied print_label(linecontour, labelwidth)[source] Return whether a contour is long enough to hold a label. set_label_props(label, text, color)[source] Set the label properties - color, fontsize, text. too_close(x, y, lw)[source] Return whether a label is already near this location.
matplotlib.contour_api#matplotlib.contour.ContourLabeler
add_label(x, y, rotation, lev, cvalue)[source] Add contour label using Text class.
matplotlib.contour_api#matplotlib.contour.ContourLabeler.add_label
add_label_clabeltext(x, y, rotation, lev, cvalue)[source] Add contour label using ClabelText class.
matplotlib.contour_api#matplotlib.contour.ContourLabeler.add_label_clabeltext
add_label_near(x, y, inline=True, inline_spacing=5, transform=None)[source] Add a label near the point (x, y). Parameters x, yfloat The approximate location of the label. inlinebool, default: True If True remove the segment of the contour beneath the label. inline_spacingint, default: 5 Space in pixels to leave on each side of label when placing inline. This spacing will be exact for labels at locations where the contour is straight, less so for labels on curved contours. transformTransform or False, default: self.axes.transData A transform applied to (x, y) before labeling. The default causes (x, y) to be interpreted as data coordinates. False is a synonym for IdentityTransform; i.e. (x, y) should be interpreted as display coordinates.
matplotlib.contour_api#matplotlib.contour.ContourLabeler.add_label_near
calc_label_rot_and_inline(slc, ind, lw, lc=None, spacing=5)[source] Calculate the appropriate label rotation given the linecontour coordinates in screen units, the index of the label location and the label width. If lc is not None or empty, also break contours and compute inlining. spacing is the empty space to leave around the label, in pixels. Both tasks are done together to avoid calculating path lengths multiple times, which is relatively costly. The method used here involves computing the path length along the contour in pixel coordinates and then looking approximately (label width / 2) away from central point to determine rotation and then to break contour if desired.
matplotlib.contour_api#matplotlib.contour.ContourLabeler.calc_label_rot_and_inline
clabel(levels=None, *, fontsize=None, inline=True, inline_spacing=5, fmt=None, colors=None, use_clabeltext=False, manual=False, rightside_up=True, zorder=None)[source] Label a contour plot. Adds labels to line contours in this ContourSet (which inherits from this mixin class). Parameters levelsarray-like, optional A list of level values, that should be labeled. The list must be a subset of cs.levels. If not given, all levels are labeled. fontsizestr or float, default: rcParams["font.size"] (default: 10.0) Size in points or relative size e.g., 'smaller', 'x-large'. See Text.set_size for accepted string values. colorscolor or colors or None, default: None The label colors: If None, the color of each label matches the color of the corresponding contour. If one string color, e.g., colors = 'r' or colors = 'red', all labels will be plotted in this color. If a tuple of colors (string, float, rgb, etc), different labels will be plotted in different colors in the order specified. inlinebool, default: True If True the underlying contour is removed where the label is placed. inline_spacingfloat, default: 5 Space in pixels to leave on each side of label when placing inline. This spacing will be exact for labels at locations where the contour is straight, less so for labels on curved contours. fmtFormatter or str or callable or dict, optional How the levels are formatted: If a Formatter, it is used to format all levels at once, using its Formatter.format_ticks method. If a str, it is interpreted as a %-style format string. If a callable, it is called with one level at a time and should return the corresponding label. If a dict, it should directly map levels to labels. The default is to use a standard ScalarFormatter. manualbool or iterable, default: False If True, contour labels will be placed manually using mouse clicks. Click the first button near a contour to add a label, click the second button (or potentially both mouse buttons at once) to finish adding labels. The third button can be used to remove the last label added, but only if labels are not inline. Alternatively, the keyboard can be used to select label locations (enter to end label placement, delete or backspace act like the third mouse button, and any other key will select a label location). manual can also be an iterable object of (x, y) tuples. Contour labels will be created as if mouse is clicked at each (x, y) position. rightside_upbool, default: True If True, label rotations will always be plus or minus 90 degrees from level. use_clabeltextbool, default: False If True, ClabelText class (instead of Text) is used to create labels. ClabelText recalculates rotation angles of texts during the drawing time, therefore this can be used if aspect of the axes changes. zorderfloat or None, default: (2 + contour.get_zorder()) zorder of the contour labels. Returns labels A list of Text instances for the labels.
matplotlib.contour_api#matplotlib.contour.ContourLabeler.clabel
get_label_coords(distances, XX, YY, ysize, lw)[source] [Deprecated] Return x, y, and the index of a label location. Labels are plotted at a location with the smallest deviation of the contour from a straight line unless there is another label nearby, in which case the next best place on the contour is picked up. If all such candidates are rejected, the beginning of the contour is chosen. Notes Deprecated since version 3.4.
matplotlib.contour_api#matplotlib.contour.ContourLabeler.get_label_coords
get_label_width(lev, fmt, fsize)[source] [Deprecated] Return the width of the label in points. Notes Deprecated since version 3.5.
matplotlib.contour_api#matplotlib.contour.ContourLabeler.get_label_width
get_text(lev, fmt)[source] Get the text of the label.
matplotlib.contour_api#matplotlib.contour.ContourLabeler.get_text
labels(inline, inline_spacing)[source]
matplotlib.contour_api#matplotlib.contour.ContourLabeler.labels
locate_label(linecontour, labelwidth)[source] Find good place to draw a label (relatively flat part of the contour).
matplotlib.contour_api#matplotlib.contour.ContourLabeler.locate_label
pop_label(index=- 1)[source] Defaults to removing last label, but any index can be supplied
matplotlib.contour_api#matplotlib.contour.ContourLabeler.pop_label
print_label(linecontour, labelwidth)[source] Return whether a contour is long enough to hold a label.
matplotlib.contour_api#matplotlib.contour.ContourLabeler.print_label
set_label_props(label, text, color)[source] Set the label properties - color, fontsize, text.
matplotlib.contour_api#matplotlib.contour.ContourLabeler.set_label_props
too_close(x, y, lw)[source] Return whether a label is already near this location.
matplotlib.contour_api#matplotlib.contour.ContourLabeler.too_close
classmatplotlib.contour.ContourSet(ax, *args, levels=None, filled=False, linewidths=None, linestyles=None, hatches=(None,), alpha=None, origin=None, extent=None, cmap=None, colors=None, norm=None, vmin=None, vmax=None, extend='neither', antialiased=None, nchunk=0, locator=None, transform=None, **kwargs)[source] Bases: matplotlib.cm.ScalarMappable, matplotlib.contour.ContourLabeler Store a set of contour lines or filled regions. User-callable method: clabel Parameters axAxes levels[level0, level1, ..., leveln] A list of floating point numbers indicating the contour levels. allsegs[level0segs, level1segs, ...] List of all the polygon segments for all the levels. For contour lines len(allsegs) == len(levels), and for filled contour regions len(allsegs) = len(levels)-1. The lists should look like level0segs = [polygon0, polygon1, ...] polygon0 = [[x0, y0], [x1, y1], ...] allkindsNone or [level0kinds, level1kinds, ...] Optional list of all the polygon vertex kinds (code types), as described and used in Path. This is used to allow multiply- connected paths such as holes within filled polygons. If not None, len(allkinds) == len(allsegs). The lists should look like level0kinds = [polygon0kinds, ...] polygon0kinds = [vertexcode0, vertexcode1, ...] If allkinds is not None, usually all polygons for a particular contour level are grouped together so that level0segs = [polygon0] and level0kinds = [polygon0kinds]. **kwargs Keyword arguments are as described in the docstring of contour. Attributes axAxes The Axes object in which the contours are drawn. collectionssilent_list of PathCollections The Artists representing the contour. This is a list of PathCollections for both line and filled contours. levelsarray The values of the contour levels. layersarray Same as levels for line contours; half-way between levels for filled contours. See ContourSet._process_colors. Draw contour lines or filled regions, depending on whether keyword arg filled is False (default) or True. Call signature: ContourSet(ax, levels, allsegs, [allkinds], **kwargs) Parameters axAxes The Axes object to draw on. levels[level0, level1, ..., leveln] A list of floating point numbers indicating the contour levels. allsegs[level0segs, level1segs, ...] List of all the polygon segments for all the levels. For contour lines len(allsegs) == len(levels), and for filled contour regions len(allsegs) = len(levels)-1. The lists should look like level0segs = [polygon0, polygon1, ...] polygon0 = [[x0, y0], [x1, y1], ...] allkinds[level0kinds, level1kinds, ...], optional Optional list of all the polygon vertex kinds (code types), as described and used in Path. This is used to allow multiply- connected paths such as holes within filled polygons. If not None, len(allkinds) == len(allsegs). The lists should look like level0kinds = [polygon0kinds, ...] polygon0kinds = [vertexcode0, vertexcode1, ...] If allkinds is not None, usually all polygons for a particular contour level are grouped together so that level0segs = [polygon0] and level0kinds = [polygon0kinds]. **kwargs Keyword arguments are as described in the docstring of contour. changed()[source] Call this whenever the mappable is changed to notify all the callbackSM listeners to the 'changed' signal. find_nearest_contour(x, y, indices=None, pixel=True)[source] Find the point in the contour plot that is closest to (x, y). Parameters x, yfloat The reference point. indiceslist of int or None, default: None Indices of contour levels to consider. If None (the default), all levels are considered. pixelbool, default: True If True, measure distance in pixel (screen) space, which is useful for manual contour labeling; else, measure distance in axes space. Returns contourCollection The contour that is closest to (x, y). segmentint The index of the Path in contour that is closest to (x, y). indexint The index of the path segment in segment that is closest to (x, y). xmin, yminfloat The point in the contour plot that is closest to (x, y). d2float The squared distance from (xmin, ymin) to (x, y). get_alpha()[source] Return alpha to be applied to all ContourSet artists. get_transform()[source] Return the Transform instance used by this ContourSet. legend_elements(variable_name='x', str_format=<class 'str'>)[source] Return a list of artists and labels suitable for passing through to legend which represent this ContourSet. The labels have the form "0 < x <= 1" stating the data ranges which the artists represent. Parameters variable_namestr The string used inside the inequality used on the labels. str_formatfunction: float -> str Function used to format the numbers in the labels. Returns artistslist[Artist] A list of the artists. labelslist[str] A list of the labels. set_alpha(alpha)[source] Set the alpha blending value for all ContourSet artists. alpha must be between 0 (transparent) and 1 (opaque).
matplotlib.contour_api#matplotlib.contour.ContourSet
changed()[source] Call this whenever the mappable is changed to notify all the callbackSM listeners to the 'changed' signal.
matplotlib.contour_api#matplotlib.contour.ContourSet.changed
find_nearest_contour(x, y, indices=None, pixel=True)[source] Find the point in the contour plot that is closest to (x, y). Parameters x, yfloat The reference point. indiceslist of int or None, default: None Indices of contour levels to consider. If None (the default), all levels are considered. pixelbool, default: True If True, measure distance in pixel (screen) space, which is useful for manual contour labeling; else, measure distance in axes space. Returns contourCollection The contour that is closest to (x, y). segmentint The index of the Path in contour that is closest to (x, y). indexint The index of the path segment in segment that is closest to (x, y). xmin, yminfloat The point in the contour plot that is closest to (x, y). d2float The squared distance from (xmin, ymin) to (x, y).
matplotlib.contour_api#matplotlib.contour.ContourSet.find_nearest_contour
get_alpha()[source] Return alpha to be applied to all ContourSet artists.
matplotlib.contour_api#matplotlib.contour.ContourSet.get_alpha
get_transform()[source] Return the Transform instance used by this ContourSet.
matplotlib.contour_api#matplotlib.contour.ContourSet.get_transform
legend_elements(variable_name='x', str_format=<class 'str'>)[source] Return a list of artists and labels suitable for passing through to legend which represent this ContourSet. The labels have the form "0 < x <= 1" stating the data ranges which the artists represent. Parameters variable_namestr The string used inside the inequality used on the labels. str_formatfunction: float -> str Function used to format the numbers in the labels. Returns artistslist[Artist] A list of the artists. labelslist[str] A list of the labels.
matplotlib.contour_api#matplotlib.contour.ContourSet.legend_elements
set_alpha(alpha)[source] Set the alpha blending value for all ContourSet artists. alpha must be between 0 (transparent) and 1 (opaque).
matplotlib.contour_api#matplotlib.contour.ContourSet.set_alpha
classmatplotlib.contour.QuadContourSet(ax, *args, levels=None, filled=False, linewidths=None, linestyles=None, hatches=(None,), alpha=None, origin=None, extent=None, cmap=None, colors=None, norm=None, vmin=None, vmax=None, extend='neither', antialiased=None, nchunk=0, locator=None, transform=None, **kwargs)[source] Bases: matplotlib.contour.ContourSet Create and store a set of contour lines or filled regions. This class is typically not instantiated directly by the user but by contour and contourf. Attributes axAxes The Axes object in which the contours are drawn. collectionssilent_list of PathCollections The Artists representing the contour. This is a list of PathCollections for both line and filled contours. levelsarray The values of the contour levels. layersarray Same as levels for line contours; half-way between levels for filled contours. See ContourSet._process_colors. Draw contour lines or filled regions, depending on whether keyword arg filled is False (default) or True. Call signature: ContourSet(ax, levels, allsegs, [allkinds], **kwargs) Parameters axAxes The Axes object to draw on. levels[level0, level1, ..., leveln] A list of floating point numbers indicating the contour levels. allsegs[level0segs, level1segs, ...] List of all the polygon segments for all the levels. For contour lines len(allsegs) == len(levels), and for filled contour regions len(allsegs) = len(levels)-1. The lists should look like level0segs = [polygon0, polygon1, ...] polygon0 = [[x0, y0], [x1, y1], ...] allkinds[level0kinds, level1kinds, ...], optional Optional list of all the polygon vertex kinds (code types), as described and used in Path. This is used to allow multiply- connected paths such as holes within filled polygons. If not None, len(allkinds) == len(allsegs). The lists should look like level0kinds = [polygon0kinds, ...] polygon0kinds = [vertexcode0, vertexcode1, ...] If allkinds is not None, usually all polygons for a particular contour level are grouped together so that level0segs = [polygon0] and level0kinds = [polygon0kinds]. **kwargs Keyword arguments are as described in the docstring of contour.
matplotlib.contour_api#matplotlib.contour.QuadContourSet
matplotlib.dates Matplotlib provides sophisticated date plotting capabilities, standing on the shoulders of python datetime and the add-on module dateutil. By default, Matplotlib uses the units machinery described in units to convert datetime.datetime, and numpy.datetime64 objects when plotted on an x- or y-axis. The user does not need to do anything for dates to be formatted, but dates often have strict formatting needs, so this module provides many axis locators and formatters. A basic example using numpy.datetime64 is: import numpy as np times = np.arange(np.datetime64('2001-01-02'), np.datetime64('2002-02-03'), np.timedelta64(75, 'm')) y = np.random.randn(len(times)) fig, ax = plt.subplots() ax.plot(times, y) See also Date tick labels Formatting date ticks using ConciseDateFormatter Date Demo Convert Matplotlib date format Matplotlib represents dates using floating point numbers specifying the number of days since a default epoch of 1970-01-01 UTC; for example, 1970-01-01, 06:00 is the floating point number 0.25. The formatters and locators require the use of datetime.datetime objects, so only dates between year 0001 and 9999 can be represented. Microsecond precision is achievable for (approximately) 70 years on either side of the epoch, and 20 microseconds for the rest of the allowable range of dates (year 0001 to 9999). The epoch can be changed at import time via dates.set_epoch or rcParams["dates.epoch"] to other dates if necessary; see Date Precision and Epochs for a discussion. Note Before Matplotlib 3.3, the epoch was 0000-12-31 which lost modern microsecond precision and also made the default axis limit of 0 an invalid datetime. In 3.3 the epoch was changed as above. To convert old ordinal floats to the new epoch, users can do: new_ordinal = old_ordinal + mdates.date2num(np.datetime64('0000-12-31')) There are a number of helper functions to convert between datetime objects and Matplotlib dates: datestr2num Convert a date string to a datenum using dateutil.parser.parse. date2num Convert datetime objects to Matplotlib dates. num2date Convert Matplotlib dates to datetime objects. num2timedelta Convert number of days to a timedelta object. drange Return a sequence of equally spaced Matplotlib dates. set_epoch Set the epoch (origin for dates) for datetime calculations. get_epoch Get the epoch used by dates. Note Like Python's datetime.datetime, Matplotlib uses the Gregorian calendar for all conversions between dates and floating point numbers. This practice is not universal, and calendar differences can cause confusing differences between what Python and Matplotlib give as the number of days since 0001-01-01 and what other software and databases yield. For example, the US Naval Observatory uses a calendar that switches from Julian to Gregorian in October, 1582. Hence, using their calculator, the number of days between 0001-01-01 and 2006-04-01 is 732403, whereas using the Gregorian calendar via the datetime module we find: In [1]: date(2006, 4, 1).toordinal() - date(1, 1, 1).toordinal() Out[1]: 732401 All the Matplotlib date converters, tickers and formatters are timezone aware. If no explicit timezone is provided, rcParams["timezone"] (default: 'UTC') is assumed. If you want to use a custom time zone, pass a datetime.tzinfo instance with the tz keyword argument to num2date, Axis.axis_date, and any custom date tickers or locators you create. A wide range of specific and general purpose date tick locators and formatters are provided in this module. See matplotlib.ticker for general information on tick locators and formatters. These are described below. The dateutil module provides additional code to handle date ticking, making it easy to place ticks on any kinds of dates. See examples below. Date tickers Most of the date tickers can locate single or multiple values. For example: # import constants for the days of the week from matplotlib.dates import MO, TU, WE, TH, FR, SA, SU # tick on mondays every week loc = WeekdayLocator(byweekday=MO, tz=tz) # tick on mondays and saturdays loc = WeekdayLocator(byweekday=(MO, SA)) In addition, most of the constructors take an interval argument: # tick on mondays every second week loc = WeekdayLocator(byweekday=MO, interval=2) The rrule locator allows completely general date ticking: # tick every 5th easter rule = rrulewrapper(YEARLY, byeaster=1, interval=5) loc = RRuleLocator(rule) The available date tickers are: MicrosecondLocator: Locate microseconds. SecondLocator: Locate seconds. MinuteLocator: Locate minutes. HourLocator: Locate hours. DayLocator: Locate specified days of the month. WeekdayLocator: Locate days of the week, e.g., MO, TU. MonthLocator: Locate months, e.g., 7 for July. YearLocator: Locate years that are multiples of base. RRuleLocator: Locate using a matplotlib.dates.rrulewrapper. rrulewrapper is a simple wrapper around dateutil's dateutil.rrule which allow almost arbitrary date tick specifications. See rrule example. AutoDateLocator: On autoscale, this class picks the best DateLocator (e.g., RRuleLocator) to set the view limits and the tick locations. If called with interval_multiples=True it will make ticks line up with sensible multiples of the tick intervals. E.g. if the interval is 4 hours, it will pick hours 0, 4, 8, etc as ticks. This behaviour is not guaranteed by default. Date formatters The available date formatters are: AutoDateFormatter: attempts to figure out the best format to use. This is most useful when used with the AutoDateLocator. ConciseDateFormatter: also attempts to figure out the best format to use, and to make the format as compact as possible while still having complete date information. This is most useful when used with the AutoDateLocator. DateFormatter: use strftime format strings. classmatplotlib.dates.AutoDateFormatter(locator, tz=None, defaultfmt='%Y-%m-%d', *, usetex=None)[source] Bases: matplotlib.ticker.Formatter A Formatter which attempts to figure out the best format to use. This is most useful when used with the AutoDateLocator. AutoDateFormatter has a .scale dictionary that maps tick scales (the interval in days between one major tick) to format strings; this dictionary defaults to self.scaled = { DAYS_PER_YEAR: rcParams['date.autoformat.year'], DAYS_PER_MONTH: rcParams['date.autoformat.month'], 1: rcParams['date.autoformat.day'], 1 / HOURS_PER_DAY: rcParams['date.autoformat.hour'], 1 / MINUTES_PER_DAY: rcParams['date.autoformat.minute'], 1 / SEC_PER_DAY: rcParams['date.autoformat.second'], 1 / MUSECONDS_PER_DAY: rcParams['date.autoformat.microsecond'], } The formatter uses the format string corresponding to the lowest key in the dictionary that is greater or equal to the current scale. Dictionary entries can be customized: locator = AutoDateLocator() formatter = AutoDateFormatter(locator) formatter.scaled[1/(24*60)] = '%M:%S' # only show min and sec Custom callables can also be used instead of format strings. The following example shows how to use a custom format function to strip trailing zeros from decimal seconds and adds the date to the first ticklabel: def my_format_function(x, pos=None): x = matplotlib.dates.num2date(x) if pos == 0: fmt = '%D %H:%M:%S.%f' else: fmt = '%H:%M:%S.%f' label = x.strftime(fmt) label = label.rstrip("0") label = label.rstrip(".") return label formatter.scaled[1/(24*60)] = my_format_function Autoformat the date labels. Parameters locatorticker.Locator Locator that this axis is using. tzstr, optional Passed to dates.date2num. defaultfmtstr The default format to use if none of the values in self.scaled are greater than the unit returned by locator._get_unit(). usetexbool, default: rcParams["text.usetex"] (default: False) To enable/disable the use of TeX's math mode for rendering the results of the formatter. If any entries in self.scaled are set as functions, then it is up to the customized function to enable or disable TeX's math mode itself. classmatplotlib.dates.AutoDateLocator(tz=None, minticks=5, maxticks=None, interval_multiples=True)[source] Bases: matplotlib.dates.DateLocator On autoscale, this class picks the best DateLocator to set the view limits and the tick locations. Attributes intervalddict Mapping of tick frequencies to multiples allowed for that ticking. The default is self.intervald = { YEARLY : [1, 2, 4, 5, 10, 20, 40, 50, 100, 200, 400, 500, 1000, 2000, 4000, 5000, 10000], MONTHLY : [1, 2, 3, 4, 6], DAILY : [1, 2, 3, 7, 14, 21], HOURLY : [1, 2, 3, 4, 6, 12], MINUTELY: [1, 5, 10, 15, 30], SECONDLY: [1, 5, 10, 15, 30], MICROSECONDLY: [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000], } where the keys are defined in dateutil.rrule. The interval is used to specify multiples that are appropriate for the frequency of ticking. For instance, every 7 days is sensible for daily ticks, but for minutes/seconds, 15 or 30 make sense. When customizing, you should only modify the values for the existing keys. You should not add or delete entries. Example for forcing ticks every 3 hours: locator = AutoDateLocator() locator.intervald[HOURLY] = [3] # only show every 3 hours Parameters tzdatetime.tzinfo Ticks timezone. minticksint The minimum number of ticks desired; controls whether ticks occur yearly, monthly, etc. maxticksint The maximum number of ticks desired; controls the interval between ticks (ticking every other, every 3, etc.). For fine-grained control, this can be a dictionary mapping individual rrule frequency constants (YEARLY, MONTHLY, etc.) to their own maximum number of ticks. This can be used to keep the number of ticks appropriate to the format chosen in AutoDateFormatter. Any frequency not specified in this dictionary is given a default value. interval_multiplesbool, default: True Whether ticks should be chosen to be multiple of the interval, locking them to 'nicer' locations. For example, this will force the ticks to be at hours 0, 6, 12, 18 when hourly ticking is done at 6 hour intervals. get_locator(dmin, dmax)[source] Pick the best locator based on a distance. nonsingular(vmin, vmax)[source] Given the proposed upper and lower extent, adjust the range if it is too close to being singular (i.e. a range of ~0). tick_values(vmin, vmax)[source] Return the values of the located ticks given vmin and vmax. Note To get tick locations with the vmin and vmax values defined automatically for the associated axis simply call the Locator instance: >>> print(type(loc)) <type 'Locator'> >>> print(loc()) [1, 2, 3, 4] classmatplotlib.dates.ConciseDateConverter(formats=None, zero_formats=None, offset_formats=None, show_offset=True, *, interval_multiples=True)[source] Bases: matplotlib.dates.DateConverter axisinfo(unit, axis)[source] Return the AxisInfo for unit. unit is a tzinfo instance or None. The axis argument is required but not used. classmatplotlib.dates.ConciseDateFormatter(locator, tz=None, formats=None, offset_formats=None, zero_formats=None, show_offset=True, *, usetex=None)[source] Bases: matplotlib.ticker.Formatter A Formatter which attempts to figure out the best format to use for the date, and to make it as compact as possible, but still be complete. This is most useful when used with the AutoDateLocator: >>> locator = AutoDateLocator() >>> formatter = ConciseDateFormatter(locator) Parameters locatorticker.Locator Locator that this axis is using. tzstr, optional Passed to dates.date2num. formatslist of 6 strings, optional Format strings for 6 levels of tick labelling: mostly years, months, days, hours, minutes, and seconds. Strings use the same format codes as strftime. Default is ['%Y', '%b', '%d', '%H:%M', '%H:%M', '%S.%f'] zero_formatslist of 6 strings, optional Format strings for tick labels that are "zeros" for a given tick level. For instance, if most ticks are months, ticks around 1 Jan 2005 will be labeled "Dec", "2005", "Feb". The default is ['', '%Y', '%b', '%b-%d', '%H:%M', '%H:%M'] offset_formatslist of 6 strings, optional Format strings for the 6 levels that is applied to the "offset" string found on the right side of an x-axis, or top of a y-axis. Combined with the tick labels this should completely specify the date. The default is: ['', '%Y', '%Y-%b', '%Y-%b-%d', '%Y-%b-%d', '%Y-%b-%d %H:%M'] show_offsetbool, default: True Whether to show the offset or not. usetexbool, default: rcParams["text.usetex"] (default: False) To enable/disable the use of TeX's math mode for rendering the results of the formatter. Examples See Formatting date ticks using ConciseDateFormatter (Source code, png, pdf) Autoformat the date labels. The default format is used to form an initial string, and then redundant elements are removed. format_data_short(value)[source] Return a short string version of the tick value. Defaults to the position-independent long value. format_ticks(values)[source] Return the tick labels for all the ticks at once. get_offset()[source] classmatplotlib.dates.DateConverter(*, interval_multiples=True)[source] Bases: matplotlib.units.ConversionInterface Converter for datetime.date and datetime.datetime data, or for date/time data represented as it would be converted by date2num. The 'unit' tag for such data is None or a tzinfo instance. axisinfo(unit, axis)[source] Return the AxisInfo for unit. unit is a tzinfo instance or None. The axis argument is required but not used. staticconvert(value, unit, axis)[source] If value is not already a number or sequence of numbers, convert it with date2num. The unit and axis arguments are not used. staticdefault_units(x, axis)[source] Return the tzinfo instance of x or of its first element, or None classmatplotlib.dates.DateFormatter(fmt, tz=None, *, usetex=None)[source] Bases: matplotlib.ticker.Formatter Format a tick (in days since the epoch) with a strftime format string. Parameters fmtstr strftime format string tzdatetime.tzinfo, default: rcParams["timezone"] (default: 'UTC') Ticks timezone. usetexbool, default: rcParams["text.usetex"] (default: False) To enable/disable the use of TeX's math mode for rendering the results of the formatter. set_tzinfo(tz)[source] classmatplotlib.dates.DateLocator(tz=None)[source] Bases: matplotlib.ticker.Locator Determines the tick locations when plotting dates. This class is subclassed by other Locators and is not meant to be used on its own. Parameters tzdatetime.tzinfo datalim_to_dt()[source] Convert axis data interval to datetime objects. hms0d={'byhour': 0, 'byminute': 0, 'bysecond': 0} nonsingular(vmin, vmax)[source] Given the proposed upper and lower extent, adjust the range if it is too close to being singular (i.e. a range of ~0). set_tzinfo(tz)[source] Set time zone info. viewlim_to_dt()[source] Convert the view interval to datetime objects. classmatplotlib.dates.DayLocator(bymonthday=None, interval=1, tz=None)[source] Bases: matplotlib.dates.RRuleLocator Make ticks on occurrences of each day of the month. For example, 1, 15, 30. Mark every day in bymonthday; bymonthday can be an int or sequence. Default is to tick every day of the month: bymonthday=range(1, 32). classmatplotlib.dates.HourLocator(byhour=None, interval=1, tz=None)[source] Bases: matplotlib.dates.RRuleLocator Make ticks on occurrences of each hour. Mark every hour in byhour; byhour can be an int or sequence. Default is to tick every hour: byhour=range(24) interval is the interval between each iteration. For example, if interval=2, mark every second occurrence. classmatplotlib.dates.MicrosecondLocator(interval=1, tz=None)[source] Bases: matplotlib.dates.DateLocator Make ticks on regular intervals of one or more microsecond(s). Note By default, Matplotlib uses a floating point representation of time in days since the epoch, so plotting data with microsecond time resolution does not work well for dates that are far (about 70 years) from the epoch (check with get_epoch). If you want sub-microsecond resolution time plots, it is strongly recommended to use floating point seconds, not datetime-like time representation. If you really must use datetime.datetime() or similar and still need microsecond precision, change the time origin via dates.set_epoch to something closer to the dates being plotted. See Date Precision and Epochs. interval is the interval between each iteration. For example, if interval=2, mark every second microsecond. set_axis(axis)[source] set_data_interval(vmin, vmax)[source] [Deprecated] Notes Deprecated since version 3.5: set_view_interval(vmin, vmax)[source] [Deprecated] Notes Deprecated since version 3.5: tick_values(vmin, vmax)[source] Return the values of the located ticks given vmin and vmax. Note To get tick locations with the vmin and vmax values defined automatically for the associated axis simply call the Locator instance: >>> print(type(loc)) <type 'Locator'> >>> print(loc()) [1, 2, 3, 4] classmatplotlib.dates.MinuteLocator(byminute=None, interval=1, tz=None)[source] Bases: matplotlib.dates.RRuleLocator Make ticks on occurrences of each minute. Mark every minute in byminute; byminute can be an int or sequence. Default is to tick every minute: byminute=range(60) interval is the interval between each iteration. For example, if interval=2, mark every second occurrence. classmatplotlib.dates.MonthLocator(bymonth=None, bymonthday=1, interval=1, tz=None)[source] Bases: matplotlib.dates.RRuleLocator Make ticks on occurrences of each month, e.g., 1, 3, 12. Mark every month in bymonth; bymonth can be an int or sequence. Default is range(1, 13), i.e. every month. interval is the interval between each iteration. For example, if interval=2, mark every second occurrence. classmatplotlib.dates.RRuleLocator(o, tz=None)[source] Bases: matplotlib.dates.DateLocator Parameters tzdatetime.tzinfo staticget_unit_generic(freq)[source] tick_values(vmin, vmax)[source] Return the values of the located ticks given vmin and vmax. Note To get tick locations with the vmin and vmax values defined automatically for the associated axis simply call the Locator instance: >>> print(type(loc)) <type 'Locator'> >>> print(loc()) [1, 2, 3, 4] classmatplotlib.dates.SecondLocator(bysecond=None, interval=1, tz=None)[source] Bases: matplotlib.dates.RRuleLocator Make ticks on occurrences of each second. Mark every second in bysecond; bysecond can be an int or sequence. Default is to tick every second: bysecond = range(60) interval is the interval between each iteration. For example, if interval=2, mark every second occurrence. classmatplotlib.dates.WeekdayLocator(byweekday=1, interval=1, tz=None)[source] Bases: matplotlib.dates.RRuleLocator Make ticks on occurrences of each weekday. Mark every weekday in byweekday; byweekday can be a number or sequence. Elements of byweekday must be one of MO, TU, WE, TH, FR, SA, SU, the constants from dateutil.rrule, which have been imported into the matplotlib.dates namespace. interval specifies the number of weeks to skip. For example, interval=2 plots every second week. classmatplotlib.dates.YearLocator(base=1, month=1, day=1, tz=None)[source] Bases: matplotlib.dates.RRuleLocator Make ticks on a given day of each year that is a multiple of base. Examples: # Tick every year on Jan 1st locator = YearLocator() # Tick every 5 years on July 4th locator = YearLocator(5, month=7, day=4) Mark years that are multiple of base on a given month and day (default jan 1). matplotlib.dates.date2num(d)[source] Convert datetime objects to Matplotlib dates. Parameters ddatetime.datetime or numpy.datetime64 or sequences of these Returns float or sequence of floats Number of days since the epoch. See get_epoch for the epoch, which can be changed by rcParams["date.epoch"] (default: '1970-01-01T00:00:00') or set_epoch. If the epoch is "1970-01-01T00:00:00" (default) then noon Jan 1 1970 ("1970-01-01T12:00:00") returns 0.5. Notes The Gregorian calendar is assumed; this is not universal practice. For details see the module docstring. matplotlib.dates.datestr2num(d, default=None)[source] Convert a date string to a datenum using dateutil.parser.parse. Parameters dstr or sequence of str The dates to convert. defaultdatetime.datetime, optional The default date to use when fields are missing in d. matplotlib.dates.drange(dstart, dend, delta)[source] Return a sequence of equally spaced Matplotlib dates. The dates start at dstart and reach up to, but not including dend. They are spaced by delta. Parameters dstart, denddatetime The date limits. deltadatetime.timedelta Spacing of the dates. Returns numpy.array A list floats representing Matplotlib dates. matplotlib.dates.epoch2num(e)[source] [Deprecated] Convert UNIX time to days since Matplotlib epoch. Parameters elist of floats Time in seconds since 1970-01-01. Returns numpy.array Time in days since Matplotlib epoch (see get_epoch()). Notes Deprecated since version 3.5. matplotlib.dates.get_epoch()[source] Get the epoch used by dates. Returns epochstr String for the epoch (parsable by numpy.datetime64). matplotlib.dates.num2date(x, tz=None)[source] Convert Matplotlib dates to datetime objects. Parameters xfloat or sequence of floats Number of days (fraction part represents hours, minutes, seconds) since the epoch. See get_epoch for the epoch, which can be changed by rcParams["date.epoch"] (default: '1970-01-01T00:00:00') or set_epoch. tzstr, default: rcParams["timezone"] (default: 'UTC') Timezone of x. Returns datetime or sequence of datetime Dates are returned in timezone tz. If x is a sequence, a sequence of datetime objects will be returned. Notes The addition of one here is a historical artifact. Also, note that the Gregorian calendar is assumed; this is not universal practice. For details, see the module docstring. matplotlib.dates.num2epoch(d)[source] [Deprecated] Convert days since Matplotlib epoch to UNIX time. Parameters dlist of floats Time in days since Matplotlib epoch (see get_epoch()). Returns numpy.array Time in seconds since 1970-01-01. Notes Deprecated since version 3.5. matplotlib.dates.num2timedelta(x)[source] Convert number of days to a timedelta object. If x is a sequence, a sequence of timedelta objects will be returned. Parameters xfloat, sequence of floats Number of days. The fraction part represents hours, minutes, seconds. Returns datetime.timedelta or list[datetime.timedelta] classmatplotlib.dates.relativedelta(dt1=None, dt2=None, years=0, months=0, days=0, leapdays=0, weeks=0, hours=0, minutes=0, seconds=0, microseconds=0, year=None, month=None, day=None, weekday=None, yearday=None, nlyearday=None, hour=None, minute=None, second=None, microsecond=None) Bases: object The relativedelta type is designed to be applied to an existing datetime and can replace specific components of that datetime, or represents an interval of time. It is based on the specification of the excellent work done by M.-A. Lemburg in his mx.DateTime extension. However, notice that this type does NOT implement the same algorithm as his work. Do NOT expect it to behave like mx.DateTime's counterpart. There are two different ways to build a relativedelta instance. The first one is passing it two date/datetime classes: relativedelta(datetime1, datetime2) The second one is passing it any number of the following keyword arguments: relativedelta(arg1=x,arg2=y,arg3=z...) year, month, day, hour, minute, second, microsecond: Absolute information (argument is singular); adding or subtracting a relativedelta with absolute information does not perform an arithmetic operation, but rather REPLACES the corresponding value in the original datetime with the value(s) in relativedelta. years, months, weeks, days, hours, minutes, seconds, microseconds: Relative information, may be negative (argument is plural); adding or subtracting a relativedelta with relative information performs the corresponding arithmetic operation on the original datetime value with the information in the relativedelta. weekday: One of the weekday instances (MO, TU, etc) available in the relativedelta module. These instances may receive a parameter N, specifying the Nth weekday, which could be positive or negative (like MO(+1) or MO(-2)). Not specifying it is the same as specifying +1. You can also use an integer, where 0=MO. This argument is always relative e.g. if the calculated date is already Monday, using MO(1) or MO(-1) won't change the day. To effectively make it absolute, use it in combination with the day argument (e.g. day=1, MO(1) for first Monday of the month). leapdays: Will add given days to the date found, if year is a leap year, and the date found is post 28 of february. yearday, nlyearday: Set the yearday or the non-leap year day (jump leap days). These are converted to day/month/leapdays information. There are relative and absolute forms of the keyword arguments. The plural is relative, and the singular is absolute. For each argument in the order below, the absolute form is applied first (by setting each attribute to that value) and then the relative form (by adding the value to the attribute). The order of attributes considered when this relativedelta is added to a datetime is: Year Month Day Hours Minutes Seconds Microseconds Finally, weekday is applied, using the rule described above. For example >>> from datetime import datetime >>> from dateutil.relativedelta import relativedelta, MO >>> dt = datetime(2018, 4, 9, 13, 37, 0) >>> delta = relativedelta(hours=25, day=1, weekday=MO(1)) >>> dt + delta datetime.datetime(2018, 4, 2, 14, 37) First, the day is set to 1 (the first of the month), then 25 hours are added, to get to the 2nd day and 14th hour, finally the weekday is applied, but since the 2nd is already a Monday there is no effect. normalized() Return a version of this object represented entirely using integer values for the relative attributes. >>> relativedelta(days=1.5, hours=2).normalized() relativedelta(days=+1, hours=+14) Returns Returns a dateutil.relativedelta.relativedelta object. propertyweeks classmatplotlib.dates.rrule(freq, dtstart=None, interval=1, wkst=None, count=None, until=None, bysetpos=None, bymonth=None, bymonthday=None, byyearday=None, byeaster=None, byweekno=None, byweekday=None, byhour=None, byminute=None, bysecond=None, cache=False) Bases: dateutil.rrule.rrulebase That's the base of the rrule operation. It accepts all the keywords defined in the RFC as its constructor parameters (except byday, which was renamed to byweekday) and more. The constructor prototype is: rrule(freq) Where freq must be one of YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, or SECONDLY. Note Per RFC section 3.3.10, recurrence instances falling on invalid dates and times are ignored rather than coerced: Recurrence rules may generate recurrence instances with an invalid date (e.g., February 30) or nonexistent local time (e.g., 1:30 AM on a day where the local time is moved forward by an hour at 1:00 AM). Such recurrence instances MUST be ignored and MUST NOT be counted as part of the recurrence set. This can lead to possibly surprising behavior when, for example, the start date occurs at the end of the month: >>> from dateutil.rrule import rrule, MONTHLY >>> from datetime import datetime >>> start_date = datetime(2014, 12, 31) >>> list(rrule(freq=MONTHLY, count=4, dtstart=start_date)) ... [datetime.datetime(2014, 12, 31, 0, 0), datetime.datetime(2015, 1, 31, 0, 0), datetime.datetime(2015, 3, 31, 0, 0), datetime.datetime(2015, 5, 31, 0, 0)] Additionally, it supports the following keyword arguments: Parameters dtstart -- The recurrence start. Besides being the base for the recurrence, missing parameters in the final recurrence instances will also be extracted from this date. If not given, datetime.now() will be used instead. interval -- The interval between each freq iteration. For example, when using YEARLY, an interval of 2 means once every two years, but with HOURLY, it means once every two hours. The default interval is 1. wkst -- The week start day. Must be one of the MO, TU, WE constants, or an integer, specifying the first day of the week. This will affect recurrences based on weekly periods. The default week start is got from calendar.firstweekday(), and may be modified by calendar.setfirstweekday(). count -- If given, this determines how many occurrences will be generated. Note As of version 2.5.0, the use of the keyword until in conjunction with count is deprecated, to make sure dateutil is fully compliant with RFC-5545 Sec. 3.3.10. Therefore, until and count must not occur in the same call to rrule. until -- If given, this must be a datetime instance specifying the upper-bound limit of the recurrence. The last recurrence in the rule is the greatest datetime that is less than or equal to the value specified in the until parameter. Note As of version 2.5.0, the use of the keyword until in conjunction with count is deprecated, to make sure dateutil is fully compliant with RFC-5545 Sec. 3.3.10. Therefore, until and count must not occur in the same call to rrule. bysetpos -- If given, it must be either an integer, or a sequence of integers, positive or negative. Each given integer will specify an occurrence number, corresponding to the nth occurrence of the rule inside the frequency period. For example, a bysetpos of -1 if combined with a MONTHLY frequency, and a byweekday of (MO, TU, WE, TH, FR), will result in the last work day of every month. bymonth -- If given, it must be either an integer, or a sequence of integers, meaning the months to apply the recurrence to. bymonthday -- If given, it must be either an integer, or a sequence of integers, meaning the month days to apply the recurrence to. byyearday -- If given, it must be either an integer, or a sequence of integers, meaning the year days to apply the recurrence to. byeaster -- If given, it must be either an integer, or a sequence of integers, positive or negative. Each integer will define an offset from the Easter Sunday. Passing the offset 0 to byeaster will yield the Easter Sunday itself. This is an extension to the RFC specification. byweekno -- If given, it must be either an integer, or a sequence of integers, meaning the week numbers to apply the recurrence to. Week numbers have the meaning described in ISO8601, that is, the first week of the year is that containing at least four days of the new year. byweekday -- If given, it must be either an integer (0 == MO), a sequence of integers, one of the weekday constants (MO, TU, etc), or a sequence of these constants. When given, these variables will define the weekdays where the recurrence will be applied. It's also possible to use an argument n for the weekday instances, which will mean the nth occurrence of this weekday in the period. For example, with MONTHLY, or with YEARLY and BYMONTH, using FR(+1) in byweekday will specify the first friday of the month where the recurrence happens. Notice that in the RFC documentation, this is specified as BYDAY, but was renamed to avoid the ambiguity of that keyword. byhour -- If given, it must be either an integer, or a sequence of integers, meaning the hours to apply the recurrence to. byminute -- If given, it must be either an integer, or a sequence of integers, meaning the minutes to apply the recurrence to. bysecond -- If given, it must be either an integer, or a sequence of integers, meaning the seconds to apply the recurrence to. cache -- If given, it must be a boolean value specifying to enable or disable caching of results. If you will use the same rrule instance multiple times, enabling caching will improve the performance considerably. replace(**kwargs) Return new rrule with same attributes except for those attributes given new values by whichever keyword arguments are specified. matplotlib.dates.set_epoch(epoch)[source] Set the epoch (origin for dates) for datetime calculations. The default epoch is rcParams["dates.epoch"] (by default 1970-01-01T00:00). If microsecond accuracy is desired, the date being plotted needs to be within approximately 70 years of the epoch. Matplotlib internally represents dates as days since the epoch, so floating point dynamic range needs to be within a factor of 2^52. set_epoch must be called before any dates are converted (i.e. near the import section) or a RuntimeError will be raised. See also Date Precision and Epochs. Parameters epochstr valid UTC date parsable by numpy.datetime64 (do not include timezone).
matplotlib.dates_api
classmatplotlib.dates.AutoDateFormatter(locator, tz=None, defaultfmt='%Y-%m-%d', *, usetex=None)[source] Bases: matplotlib.ticker.Formatter A Formatter which attempts to figure out the best format to use. This is most useful when used with the AutoDateLocator. AutoDateFormatter has a .scale dictionary that maps tick scales (the interval in days between one major tick) to format strings; this dictionary defaults to self.scaled = { DAYS_PER_YEAR: rcParams['date.autoformat.year'], DAYS_PER_MONTH: rcParams['date.autoformat.month'], 1: rcParams['date.autoformat.day'], 1 / HOURS_PER_DAY: rcParams['date.autoformat.hour'], 1 / MINUTES_PER_DAY: rcParams['date.autoformat.minute'], 1 / SEC_PER_DAY: rcParams['date.autoformat.second'], 1 / MUSECONDS_PER_DAY: rcParams['date.autoformat.microsecond'], } The formatter uses the format string corresponding to the lowest key in the dictionary that is greater or equal to the current scale. Dictionary entries can be customized: locator = AutoDateLocator() formatter = AutoDateFormatter(locator) formatter.scaled[1/(24*60)] = '%M:%S' # only show min and sec Custom callables can also be used instead of format strings. The following example shows how to use a custom format function to strip trailing zeros from decimal seconds and adds the date to the first ticklabel: def my_format_function(x, pos=None): x = matplotlib.dates.num2date(x) if pos == 0: fmt = '%D %H:%M:%S.%f' else: fmt = '%H:%M:%S.%f' label = x.strftime(fmt) label = label.rstrip("0") label = label.rstrip(".") return label formatter.scaled[1/(24*60)] = my_format_function Autoformat the date labels. Parameters locatorticker.Locator Locator that this axis is using. tzstr, optional Passed to dates.date2num. defaultfmtstr The default format to use if none of the values in self.scaled are greater than the unit returned by locator._get_unit(). usetexbool, default: rcParams["text.usetex"] (default: False) To enable/disable the use of TeX's math mode for rendering the results of the formatter. If any entries in self.scaled are set as functions, then it is up to the customized function to enable or disable TeX's math mode itself.
matplotlib.dates_api#matplotlib.dates.AutoDateFormatter
classmatplotlib.dates.AutoDateLocator(tz=None, minticks=5, maxticks=None, interval_multiples=True)[source] Bases: matplotlib.dates.DateLocator On autoscale, this class picks the best DateLocator to set the view limits and the tick locations. Attributes intervalddict Mapping of tick frequencies to multiples allowed for that ticking. The default is self.intervald = { YEARLY : [1, 2, 4, 5, 10, 20, 40, 50, 100, 200, 400, 500, 1000, 2000, 4000, 5000, 10000], MONTHLY : [1, 2, 3, 4, 6], DAILY : [1, 2, 3, 7, 14, 21], HOURLY : [1, 2, 3, 4, 6, 12], MINUTELY: [1, 5, 10, 15, 30], SECONDLY: [1, 5, 10, 15, 30], MICROSECONDLY: [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000], } where the keys are defined in dateutil.rrule. The interval is used to specify multiples that are appropriate for the frequency of ticking. For instance, every 7 days is sensible for daily ticks, but for minutes/seconds, 15 or 30 make sense. When customizing, you should only modify the values for the existing keys. You should not add or delete entries. Example for forcing ticks every 3 hours: locator = AutoDateLocator() locator.intervald[HOURLY] = [3] # only show every 3 hours Parameters tzdatetime.tzinfo Ticks timezone. minticksint The minimum number of ticks desired; controls whether ticks occur yearly, monthly, etc. maxticksint The maximum number of ticks desired; controls the interval between ticks (ticking every other, every 3, etc.). For fine-grained control, this can be a dictionary mapping individual rrule frequency constants (YEARLY, MONTHLY, etc.) to their own maximum number of ticks. This can be used to keep the number of ticks appropriate to the format chosen in AutoDateFormatter. Any frequency not specified in this dictionary is given a default value. interval_multiplesbool, default: True Whether ticks should be chosen to be multiple of the interval, locking them to 'nicer' locations. For example, this will force the ticks to be at hours 0, 6, 12, 18 when hourly ticking is done at 6 hour intervals. get_locator(dmin, dmax)[source] Pick the best locator based on a distance. nonsingular(vmin, vmax)[source] Given the proposed upper and lower extent, adjust the range if it is too close to being singular (i.e. a range of ~0). tick_values(vmin, vmax)[source] Return the values of the located ticks given vmin and vmax. Note To get tick locations with the vmin and vmax values defined automatically for the associated axis simply call the Locator instance: >>> print(type(loc)) <type 'Locator'> >>> print(loc()) [1, 2, 3, 4]
matplotlib.dates_api#matplotlib.dates.AutoDateLocator
get_locator(dmin, dmax)[source] Pick the best locator based on a distance.
matplotlib.dates_api#matplotlib.dates.AutoDateLocator.get_locator
nonsingular(vmin, vmax)[source] Given the proposed upper and lower extent, adjust the range if it is too close to being singular (i.e. a range of ~0).
matplotlib.dates_api#matplotlib.dates.AutoDateLocator.nonsingular
tick_values(vmin, vmax)[source] Return the values of the located ticks given vmin and vmax. Note To get tick locations with the vmin and vmax values defined automatically for the associated axis simply call the Locator instance: >>> print(type(loc)) <type 'Locator'> >>> print(loc()) [1, 2, 3, 4]
matplotlib.dates_api#matplotlib.dates.AutoDateLocator.tick_values
classmatplotlib.dates.ConciseDateConverter(formats=None, zero_formats=None, offset_formats=None, show_offset=True, *, interval_multiples=True)[source] Bases: matplotlib.dates.DateConverter axisinfo(unit, axis)[source] Return the AxisInfo for unit. unit is a tzinfo instance or None. The axis argument is required but not used.
matplotlib.dates_api#matplotlib.dates.ConciseDateConverter
axisinfo(unit, axis)[source] Return the AxisInfo for unit. unit is a tzinfo instance or None. The axis argument is required but not used.
matplotlib.dates_api#matplotlib.dates.ConciseDateConverter.axisinfo
classmatplotlib.dates.ConciseDateFormatter(locator, tz=None, formats=None, offset_formats=None, zero_formats=None, show_offset=True, *, usetex=None)[source] Bases: matplotlib.ticker.Formatter A Formatter which attempts to figure out the best format to use for the date, and to make it as compact as possible, but still be complete. This is most useful when used with the AutoDateLocator: >>> locator = AutoDateLocator() >>> formatter = ConciseDateFormatter(locator) Parameters locatorticker.Locator Locator that this axis is using. tzstr, optional Passed to dates.date2num. formatslist of 6 strings, optional Format strings for 6 levels of tick labelling: mostly years, months, days, hours, minutes, and seconds. Strings use the same format codes as strftime. Default is ['%Y', '%b', '%d', '%H:%M', '%H:%M', '%S.%f'] zero_formatslist of 6 strings, optional Format strings for tick labels that are "zeros" for a given tick level. For instance, if most ticks are months, ticks around 1 Jan 2005 will be labeled "Dec", "2005", "Feb". The default is ['', '%Y', '%b', '%b-%d', '%H:%M', '%H:%M'] offset_formatslist of 6 strings, optional Format strings for the 6 levels that is applied to the "offset" string found on the right side of an x-axis, or top of a y-axis. Combined with the tick labels this should completely specify the date. The default is: ['', '%Y', '%Y-%b', '%Y-%b-%d', '%Y-%b-%d', '%Y-%b-%d %H:%M'] show_offsetbool, default: True Whether to show the offset or not. usetexbool, default: rcParams["text.usetex"] (default: False) To enable/disable the use of TeX's math mode for rendering the results of the formatter. Examples See Formatting date ticks using ConciseDateFormatter (Source code, png, pdf) Autoformat the date labels. The default format is used to form an initial string, and then redundant elements are removed. format_data_short(value)[source] Return a short string version of the tick value. Defaults to the position-independent long value. format_ticks(values)[source] Return the tick labels for all the ticks at once. get_offset()[source]
matplotlib.dates_api#matplotlib.dates.ConciseDateFormatter
format_data_short(value)[source] Return a short string version of the tick value. Defaults to the position-independent long value.
matplotlib.dates_api#matplotlib.dates.ConciseDateFormatter.format_data_short
format_ticks(values)[source] Return the tick labels for all the ticks at once.
matplotlib.dates_api#matplotlib.dates.ConciseDateFormatter.format_ticks
get_offset()[source]
matplotlib.dates_api#matplotlib.dates.ConciseDateFormatter.get_offset
matplotlib.dates.date2num(d)[source] Convert datetime objects to Matplotlib dates. Parameters ddatetime.datetime or numpy.datetime64 or sequences of these Returns float or sequence of floats Number of days since the epoch. See get_epoch for the epoch, which can be changed by rcParams["date.epoch"] (default: '1970-01-01T00:00:00') or set_epoch. If the epoch is "1970-01-01T00:00:00" (default) then noon Jan 1 1970 ("1970-01-01T12:00:00") returns 0.5. Notes The Gregorian calendar is assumed; this is not universal practice. For details see the module docstring.
matplotlib.dates_api#matplotlib.dates.date2num
classmatplotlib.dates.DateConverter(*, interval_multiples=True)[source] Bases: matplotlib.units.ConversionInterface Converter for datetime.date and datetime.datetime data, or for date/time data represented as it would be converted by date2num. The 'unit' tag for such data is None or a tzinfo instance. axisinfo(unit, axis)[source] Return the AxisInfo for unit. unit is a tzinfo instance or None. The axis argument is required but not used. staticconvert(value, unit, axis)[source] If value is not already a number or sequence of numbers, convert it with date2num. The unit and axis arguments are not used. staticdefault_units(x, axis)[source] Return the tzinfo instance of x or of its first element, or None
matplotlib.dates_api#matplotlib.dates.DateConverter
axisinfo(unit, axis)[source] Return the AxisInfo for unit. unit is a tzinfo instance or None. The axis argument is required but not used.
matplotlib.dates_api#matplotlib.dates.DateConverter.axisinfo
staticconvert(value, unit, axis)[source] If value is not already a number or sequence of numbers, convert it with date2num. The unit and axis arguments are not used.
matplotlib.dates_api#matplotlib.dates.DateConverter.convert
staticdefault_units(x, axis)[source] Return the tzinfo instance of x or of its first element, or None
matplotlib.dates_api#matplotlib.dates.DateConverter.default_units
classmatplotlib.dates.DateFormatter(fmt, tz=None, *, usetex=None)[source] Bases: matplotlib.ticker.Formatter Format a tick (in days since the epoch) with a strftime format string. Parameters fmtstr strftime format string tzdatetime.tzinfo, default: rcParams["timezone"] (default: 'UTC') Ticks timezone. usetexbool, default: rcParams["text.usetex"] (default: False) To enable/disable the use of TeX's math mode for rendering the results of the formatter. set_tzinfo(tz)[source]
matplotlib.dates_api#matplotlib.dates.DateFormatter
set_tzinfo(tz)[source]
matplotlib.dates_api#matplotlib.dates.DateFormatter.set_tzinfo
classmatplotlib.dates.DateLocator(tz=None)[source] Bases: matplotlib.ticker.Locator Determines the tick locations when plotting dates. This class is subclassed by other Locators and is not meant to be used on its own. Parameters tzdatetime.tzinfo datalim_to_dt()[source] Convert axis data interval to datetime objects. hms0d={'byhour': 0, 'byminute': 0, 'bysecond': 0} nonsingular(vmin, vmax)[source] Given the proposed upper and lower extent, adjust the range if it is too close to being singular (i.e. a range of ~0). set_tzinfo(tz)[source] Set time zone info. viewlim_to_dt()[source] Convert the view interval to datetime objects.
matplotlib.dates_api#matplotlib.dates.DateLocator
datalim_to_dt()[source] Convert axis data interval to datetime objects.
matplotlib.dates_api#matplotlib.dates.DateLocator.datalim_to_dt
hms0d={'byhour': 0, 'byminute': 0, 'bysecond': 0}
matplotlib.dates_api#matplotlib.dates.DateLocator.hms0d
nonsingular(vmin, vmax)[source] Given the proposed upper and lower extent, adjust the range if it is too close to being singular (i.e. a range of ~0).
matplotlib.dates_api#matplotlib.dates.DateLocator.nonsingular
set_tzinfo(tz)[source] Set time zone info.
matplotlib.dates_api#matplotlib.dates.DateLocator.set_tzinfo
viewlim_to_dt()[source] Convert the view interval to datetime objects.
matplotlib.dates_api#matplotlib.dates.DateLocator.viewlim_to_dt
matplotlib.dates.datestr2num(d, default=None)[source] Convert a date string to a datenum using dateutil.parser.parse. Parameters dstr or sequence of str The dates to convert. defaultdatetime.datetime, optional The default date to use when fields are missing in d.
matplotlib.dates_api#matplotlib.dates.datestr2num
classmatplotlib.dates.DayLocator(bymonthday=None, interval=1, tz=None)[source] Bases: matplotlib.dates.RRuleLocator Make ticks on occurrences of each day of the month. For example, 1, 15, 30. Mark every day in bymonthday; bymonthday can be an int or sequence. Default is to tick every day of the month: bymonthday=range(1, 32).
matplotlib.dates_api#matplotlib.dates.DayLocator
matplotlib.dates.drange(dstart, dend, delta)[source] Return a sequence of equally spaced Matplotlib dates. The dates start at dstart and reach up to, but not including dend. They are spaced by delta. Parameters dstart, denddatetime The date limits. deltadatetime.timedelta Spacing of the dates. Returns numpy.array A list floats representing Matplotlib dates.
matplotlib.dates_api#matplotlib.dates.drange
matplotlib.dates.epoch2num(e)[source] [Deprecated] Convert UNIX time to days since Matplotlib epoch. Parameters elist of floats Time in seconds since 1970-01-01. Returns numpy.array Time in days since Matplotlib epoch (see get_epoch()). Notes Deprecated since version 3.5.
matplotlib.dates_api#matplotlib.dates.epoch2num
matplotlib.dates.get_epoch()[source] Get the epoch used by dates. Returns epochstr String for the epoch (parsable by numpy.datetime64).
matplotlib.dates_api#matplotlib.dates.get_epoch
classmatplotlib.dates.HourLocator(byhour=None, interval=1, tz=None)[source] Bases: matplotlib.dates.RRuleLocator Make ticks on occurrences of each hour. Mark every hour in byhour; byhour can be an int or sequence. Default is to tick every hour: byhour=range(24) interval is the interval between each iteration. For example, if interval=2, mark every second occurrence.
matplotlib.dates_api#matplotlib.dates.HourLocator
classmatplotlib.dates.MicrosecondLocator(interval=1, tz=None)[source] Bases: matplotlib.dates.DateLocator Make ticks on regular intervals of one or more microsecond(s). Note By default, Matplotlib uses a floating point representation of time in days since the epoch, so plotting data with microsecond time resolution does not work well for dates that are far (about 70 years) from the epoch (check with get_epoch). If you want sub-microsecond resolution time plots, it is strongly recommended to use floating point seconds, not datetime-like time representation. If you really must use datetime.datetime() or similar and still need microsecond precision, change the time origin via dates.set_epoch to something closer to the dates being plotted. See Date Precision and Epochs. interval is the interval between each iteration. For example, if interval=2, mark every second microsecond. set_axis(axis)[source] set_data_interval(vmin, vmax)[source] [Deprecated] Notes Deprecated since version 3.5: set_view_interval(vmin, vmax)[source] [Deprecated] Notes Deprecated since version 3.5: tick_values(vmin, vmax)[source] Return the values of the located ticks given vmin and vmax. Note To get tick locations with the vmin and vmax values defined automatically for the associated axis simply call the Locator instance: >>> print(type(loc)) <type 'Locator'> >>> print(loc()) [1, 2, 3, 4]
matplotlib.dates_api#matplotlib.dates.MicrosecondLocator
set_axis(axis)[source]
matplotlib.dates_api#matplotlib.dates.MicrosecondLocator.set_axis
set_data_interval(vmin, vmax)[source] [Deprecated] Notes Deprecated since version 3.5:
matplotlib.dates_api#matplotlib.dates.MicrosecondLocator.set_data_interval
set_view_interval(vmin, vmax)[source] [Deprecated] Notes Deprecated since version 3.5:
matplotlib.dates_api#matplotlib.dates.MicrosecondLocator.set_view_interval
tick_values(vmin, vmax)[source] Return the values of the located ticks given vmin and vmax. Note To get tick locations with the vmin and vmax values defined automatically for the associated axis simply call the Locator instance: >>> print(type(loc)) <type 'Locator'> >>> print(loc()) [1, 2, 3, 4]
matplotlib.dates_api#matplotlib.dates.MicrosecondLocator.tick_values
classmatplotlib.dates.MinuteLocator(byminute=None, interval=1, tz=None)[source] Bases: matplotlib.dates.RRuleLocator Make ticks on occurrences of each minute. Mark every minute in byminute; byminute can be an int or sequence. Default is to tick every minute: byminute=range(60) interval is the interval between each iteration. For example, if interval=2, mark every second occurrence.
matplotlib.dates_api#matplotlib.dates.MinuteLocator
classmatplotlib.dates.MonthLocator(bymonth=None, bymonthday=1, interval=1, tz=None)[source] Bases: matplotlib.dates.RRuleLocator Make ticks on occurrences of each month, e.g., 1, 3, 12. Mark every month in bymonth; bymonth can be an int or sequence. Default is range(1, 13), i.e. every month. interval is the interval between each iteration. For example, if interval=2, mark every second occurrence.
matplotlib.dates_api#matplotlib.dates.MonthLocator
matplotlib.dates.num2date(x, tz=None)[source] Convert Matplotlib dates to datetime objects. Parameters xfloat or sequence of floats Number of days (fraction part represents hours, minutes, seconds) since the epoch. See get_epoch for the epoch, which can be changed by rcParams["date.epoch"] (default: '1970-01-01T00:00:00') or set_epoch. tzstr, default: rcParams["timezone"] (default: 'UTC') Timezone of x. Returns datetime or sequence of datetime Dates are returned in timezone tz. If x is a sequence, a sequence of datetime objects will be returned. Notes The addition of one here is a historical artifact. Also, note that the Gregorian calendar is assumed; this is not universal practice. For details, see the module docstring.
matplotlib.dates_api#matplotlib.dates.num2date
matplotlib.dates.num2epoch(d)[source] [Deprecated] Convert days since Matplotlib epoch to UNIX time. Parameters dlist of floats Time in days since Matplotlib epoch (see get_epoch()). Returns numpy.array Time in seconds since 1970-01-01. Notes Deprecated since version 3.5.
matplotlib.dates_api#matplotlib.dates.num2epoch
matplotlib.dates.num2timedelta(x)[source] Convert number of days to a timedelta object. If x is a sequence, a sequence of timedelta objects will be returned. Parameters xfloat, sequence of floats Number of days. The fraction part represents hours, minutes, seconds. Returns datetime.timedelta or list[datetime.timedelta]
matplotlib.dates_api#matplotlib.dates.num2timedelta
classmatplotlib.dates.relativedelta(dt1=None, dt2=None, years=0, months=0, days=0, leapdays=0, weeks=0, hours=0, minutes=0, seconds=0, microseconds=0, year=None, month=None, day=None, weekday=None, yearday=None, nlyearday=None, hour=None, minute=None, second=None, microsecond=None) Bases: object The relativedelta type is designed to be applied to an existing datetime and can replace specific components of that datetime, or represents an interval of time. It is based on the specification of the excellent work done by M.-A. Lemburg in his mx.DateTime extension. However, notice that this type does NOT implement the same algorithm as his work. Do NOT expect it to behave like mx.DateTime's counterpart. There are two different ways to build a relativedelta instance. The first one is passing it two date/datetime classes: relativedelta(datetime1, datetime2) The second one is passing it any number of the following keyword arguments: relativedelta(arg1=x,arg2=y,arg3=z...) year, month, day, hour, minute, second, microsecond: Absolute information (argument is singular); adding or subtracting a relativedelta with absolute information does not perform an arithmetic operation, but rather REPLACES the corresponding value in the original datetime with the value(s) in relativedelta. years, months, weeks, days, hours, minutes, seconds, microseconds: Relative information, may be negative (argument is plural); adding or subtracting a relativedelta with relative information performs the corresponding arithmetic operation on the original datetime value with the information in the relativedelta. weekday: One of the weekday instances (MO, TU, etc) available in the relativedelta module. These instances may receive a parameter N, specifying the Nth weekday, which could be positive or negative (like MO(+1) or MO(-2)). Not specifying it is the same as specifying +1. You can also use an integer, where 0=MO. This argument is always relative e.g. if the calculated date is already Monday, using MO(1) or MO(-1) won't change the day. To effectively make it absolute, use it in combination with the day argument (e.g. day=1, MO(1) for first Monday of the month). leapdays: Will add given days to the date found, if year is a leap year, and the date found is post 28 of february. yearday, nlyearday: Set the yearday or the non-leap year day (jump leap days). These are converted to day/month/leapdays information. There are relative and absolute forms of the keyword arguments. The plural is relative, and the singular is absolute. For each argument in the order below, the absolute form is applied first (by setting each attribute to that value) and then the relative form (by adding the value to the attribute). The order of attributes considered when this relativedelta is added to a datetime is: Year Month Day Hours Minutes Seconds Microseconds Finally, weekday is applied, using the rule described above. For example >>> from datetime import datetime >>> from dateutil.relativedelta import relativedelta, MO >>> dt = datetime(2018, 4, 9, 13, 37, 0) >>> delta = relativedelta(hours=25, day=1, weekday=MO(1)) >>> dt + delta datetime.datetime(2018, 4, 2, 14, 37) First, the day is set to 1 (the first of the month), then 25 hours are added, to get to the 2nd day and 14th hour, finally the weekday is applied, but since the 2nd is already a Monday there is no effect. normalized() Return a version of this object represented entirely using integer values for the relative attributes. >>> relativedelta(days=1.5, hours=2).normalized() relativedelta(days=+1, hours=+14) Returns Returns a dateutil.relativedelta.relativedelta object. propertyweeks
matplotlib.dates_api#matplotlib.dates.relativedelta
normalized() Return a version of this object represented entirely using integer values for the relative attributes. >>> relativedelta(days=1.5, hours=2).normalized() relativedelta(days=+1, hours=+14) Returns Returns a dateutil.relativedelta.relativedelta object.
matplotlib.dates_api#matplotlib.dates.relativedelta.normalized
classmatplotlib.dates.rrule(freq, dtstart=None, interval=1, wkst=None, count=None, until=None, bysetpos=None, bymonth=None, bymonthday=None, byyearday=None, byeaster=None, byweekno=None, byweekday=None, byhour=None, byminute=None, bysecond=None, cache=False) Bases: dateutil.rrule.rrulebase That's the base of the rrule operation. It accepts all the keywords defined in the RFC as its constructor parameters (except byday, which was renamed to byweekday) and more. The constructor prototype is: rrule(freq) Where freq must be one of YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, or SECONDLY. Note Per RFC section 3.3.10, recurrence instances falling on invalid dates and times are ignored rather than coerced: Recurrence rules may generate recurrence instances with an invalid date (e.g., February 30) or nonexistent local time (e.g., 1:30 AM on a day where the local time is moved forward by an hour at 1:00 AM). Such recurrence instances MUST be ignored and MUST NOT be counted as part of the recurrence set. This can lead to possibly surprising behavior when, for example, the start date occurs at the end of the month: >>> from dateutil.rrule import rrule, MONTHLY >>> from datetime import datetime >>> start_date = datetime(2014, 12, 31) >>> list(rrule(freq=MONTHLY, count=4, dtstart=start_date)) ... [datetime.datetime(2014, 12, 31, 0, 0), datetime.datetime(2015, 1, 31, 0, 0), datetime.datetime(2015, 3, 31, 0, 0), datetime.datetime(2015, 5, 31, 0, 0)] Additionally, it supports the following keyword arguments: Parameters dtstart -- The recurrence start. Besides being the base for the recurrence, missing parameters in the final recurrence instances will also be extracted from this date. If not given, datetime.now() will be used instead. interval -- The interval between each freq iteration. For example, when using YEARLY, an interval of 2 means once every two years, but with HOURLY, it means once every two hours. The default interval is 1. wkst -- The week start day. Must be one of the MO, TU, WE constants, or an integer, specifying the first day of the week. This will affect recurrences based on weekly periods. The default week start is got from calendar.firstweekday(), and may be modified by calendar.setfirstweekday(). count -- If given, this determines how many occurrences will be generated. Note As of version 2.5.0, the use of the keyword until in conjunction with count is deprecated, to make sure dateutil is fully compliant with RFC-5545 Sec. 3.3.10. Therefore, until and count must not occur in the same call to rrule. until -- If given, this must be a datetime instance specifying the upper-bound limit of the recurrence. The last recurrence in the rule is the greatest datetime that is less than or equal to the value specified in the until parameter. Note As of version 2.5.0, the use of the keyword until in conjunction with count is deprecated, to make sure dateutil is fully compliant with RFC-5545 Sec. 3.3.10. Therefore, until and count must not occur in the same call to rrule. bysetpos -- If given, it must be either an integer, or a sequence of integers, positive or negative. Each given integer will specify an occurrence number, corresponding to the nth occurrence of the rule inside the frequency period. For example, a bysetpos of -1 if combined with a MONTHLY frequency, and a byweekday of (MO, TU, WE, TH, FR), will result in the last work day of every month. bymonth -- If given, it must be either an integer, or a sequence of integers, meaning the months to apply the recurrence to. bymonthday -- If given, it must be either an integer, or a sequence of integers, meaning the month days to apply the recurrence to. byyearday -- If given, it must be either an integer, or a sequence of integers, meaning the year days to apply the recurrence to. byeaster -- If given, it must be either an integer, or a sequence of integers, positive or negative. Each integer will define an offset from the Easter Sunday. Passing the offset 0 to byeaster will yield the Easter Sunday itself. This is an extension to the RFC specification. byweekno -- If given, it must be either an integer, or a sequence of integers, meaning the week numbers to apply the recurrence to. Week numbers have the meaning described in ISO8601, that is, the first week of the year is that containing at least four days of the new year. byweekday -- If given, it must be either an integer (0 == MO), a sequence of integers, one of the weekday constants (MO, TU, etc), or a sequence of these constants. When given, these variables will define the weekdays where the recurrence will be applied. It's also possible to use an argument n for the weekday instances, which will mean the nth occurrence of this weekday in the period. For example, with MONTHLY, or with YEARLY and BYMONTH, using FR(+1) in byweekday will specify the first friday of the month where the recurrence happens. Notice that in the RFC documentation, this is specified as BYDAY, but was renamed to avoid the ambiguity of that keyword. byhour -- If given, it must be either an integer, or a sequence of integers, meaning the hours to apply the recurrence to. byminute -- If given, it must be either an integer, or a sequence of integers, meaning the minutes to apply the recurrence to. bysecond -- If given, it must be either an integer, or a sequence of integers, meaning the seconds to apply the recurrence to. cache -- If given, it must be a boolean value specifying to enable or disable caching of results. If you will use the same rrule instance multiple times, enabling caching will improve the performance considerably. replace(**kwargs) Return new rrule with same attributes except for those attributes given new values by whichever keyword arguments are specified.
matplotlib.dates_api#matplotlib.dates.rrule
replace(**kwargs) Return new rrule with same attributes except for those attributes given new values by whichever keyword arguments are specified.
matplotlib.dates_api#matplotlib.dates.rrule.replace
classmatplotlib.dates.RRuleLocator(o, tz=None)[source] Bases: matplotlib.dates.DateLocator Parameters tzdatetime.tzinfo staticget_unit_generic(freq)[source] tick_values(vmin, vmax)[source] Return the values of the located ticks given vmin and vmax. Note To get tick locations with the vmin and vmax values defined automatically for the associated axis simply call the Locator instance: >>> print(type(loc)) <type 'Locator'> >>> print(loc()) [1, 2, 3, 4]
matplotlib.dates_api#matplotlib.dates.RRuleLocator
staticget_unit_generic(freq)[source]
matplotlib.dates_api#matplotlib.dates.RRuleLocator.get_unit_generic
tick_values(vmin, vmax)[source] Return the values of the located ticks given vmin and vmax. Note To get tick locations with the vmin and vmax values defined automatically for the associated axis simply call the Locator instance: >>> print(type(loc)) <type 'Locator'> >>> print(loc()) [1, 2, 3, 4]
matplotlib.dates_api#matplotlib.dates.RRuleLocator.tick_values
classmatplotlib.dates.SecondLocator(bysecond=None, interval=1, tz=None)[source] Bases: matplotlib.dates.RRuleLocator Make ticks on occurrences of each second. Mark every second in bysecond; bysecond can be an int or sequence. Default is to tick every second: bysecond = range(60) interval is the interval between each iteration. For example, if interval=2, mark every second occurrence.
matplotlib.dates_api#matplotlib.dates.SecondLocator
matplotlib.dates.set_epoch(epoch)[source] Set the epoch (origin for dates) for datetime calculations. The default epoch is rcParams["dates.epoch"] (by default 1970-01-01T00:00). If microsecond accuracy is desired, the date being plotted needs to be within approximately 70 years of the epoch. Matplotlib internally represents dates as days since the epoch, so floating point dynamic range needs to be within a factor of 2^52. set_epoch must be called before any dates are converted (i.e. near the import section) or a RuntimeError will be raised. See also Date Precision and Epochs. Parameters epochstr valid UTC date parsable by numpy.datetime64 (do not include timezone).
matplotlib.dates_api#matplotlib.dates.set_epoch
classmatplotlib.dates.WeekdayLocator(byweekday=1, interval=1, tz=None)[source] Bases: matplotlib.dates.RRuleLocator Make ticks on occurrences of each weekday. Mark every weekday in byweekday; byweekday can be a number or sequence. Elements of byweekday must be one of MO, TU, WE, TH, FR, SA, SU, the constants from dateutil.rrule, which have been imported into the matplotlib.dates namespace. interval specifies the number of weeks to skip. For example, interval=2 plots every second week.
matplotlib.dates_api#matplotlib.dates.WeekdayLocator
classmatplotlib.dates.YearLocator(base=1, month=1, day=1, tz=None)[source] Bases: matplotlib.dates.RRuleLocator Make ticks on a given day of each year that is a multiple of base. Examples: # Tick every year on Jan 1st locator = YearLocator() # Tick every 5 years on July 4th locator = YearLocator(5, month=7, day=4) Mark years that are multiple of base on a given month and day (default jan 1).
matplotlib.dates_api#matplotlib.dates.YearLocator