doc_content
stringlengths
1
386k
doc_id
stringlengths
5
188
get_fontstyle()[source] Return the font style as a string. See also font_manager.FontProperties.get_style
matplotlib.text_api#matplotlib.text.Text.get_fontstyle
get_fontvariant()[source] Return the font variant as a string. See also font_manager.FontProperties.get_variant
matplotlib.text_api#matplotlib.text.Text.get_fontvariant
get_fontweight()[source] Return the font weight as a string or a number. See also font_manager.FontProperties.get_weight
matplotlib.text_api#matplotlib.text.Text.get_fontweight
get_ha()[source] Alias for get_horizontalalignment.
matplotlib.text_api#matplotlib.text.Text.get_ha
get_horizontalalignment()[source] Return the horizontal alignment as a string. Will be one of 'left', 'center' or 'right'.
matplotlib.text_api#matplotlib.text.Text.get_horizontalalignment
get_math_fontfamily()[source] Return the font family name for math text rendered by Matplotlib. The default value is rcParams["mathtext.fontset"] (default: 'dejavusans'). See also set_math_fontfamily
matplotlib.text_api#matplotlib.text.Text.get_math_fontfamily
get_name()[source] Alias for get_fontname.
matplotlib.text_api#matplotlib.text.Text.get_name
get_parse_math()[source] Return whether mathtext parsing is considered for this Text.
matplotlib.text_api#matplotlib.text.Text.get_parse_math
get_position()[source] Return the (x, y) position of the text.
matplotlib.text_api#matplotlib.text.Text.get_position
get_prop_tup(renderer=None)[source] [Deprecated] Return a hashable tuple of properties. Not intended to be human readable, but useful for backends who want to cache derived information about text (e.g., layouts) and need to know if the text has changed. Notes Deprecated since version 3.5.
matplotlib.text_api#matplotlib.text.Text.get_prop_tup
get_rotation()[source] Return the text angle in degrees between 0 and 360.
matplotlib.text_api#matplotlib.text.Text.get_rotation
get_rotation_mode()[source] Return the text rotation mode.
matplotlib.text_api#matplotlib.text.Text.get_rotation_mode
get_size()[source] Alias for get_fontsize.
matplotlib.text_api#matplotlib.text.Text.get_size
get_stretch()[source] Return the font stretch as a string or a number. See also font_manager.FontProperties.get_stretch
matplotlib.text_api#matplotlib.text.Text.get_stretch
get_style()[source] Alias for get_fontstyle.
matplotlib.text_api#matplotlib.text.Text.get_style
get_text()[source] Return the text string.
matplotlib.text_api#matplotlib.text.Text.get_text
get_transform_rotates_text()[source] Return whether rotations of the transform affect the text direction.
matplotlib.text_api#matplotlib.text.Text.get_transform_rotates_text
get_unitless_position()[source] Return the (x, y) unitless position of the text.
matplotlib.text_api#matplotlib.text.Text.get_unitless_position
get_usetex()[source] Return whether this Text object uses TeX for rendering.
matplotlib.text_api#matplotlib.text.Text.get_usetex
get_va()[source] Alias for get_verticalalignment.
matplotlib.text_api#matplotlib.text.Text.get_va
get_variant()[source] Alias for get_fontvariant.
matplotlib.text_api#matplotlib.text.Text.get_variant
get_verticalalignment()[source] Return the vertical alignment as a string. Will be one of 'top', 'center', 'bottom', 'baseline' or 'center_baseline'.
matplotlib.text_api#matplotlib.text.Text.get_verticalalignment
get_weight()[source] Alias for get_fontweight.
matplotlib.text_api#matplotlib.text.Text.get_weight
get_window_extent(renderer=None, dpi=None)[source] Return the Bbox bounding the text, in display units. In addition to being used internally, this is useful for specifying clickable regions in a png file on a web page. Parameters rendererRenderer, optional A renderer is needed to compute the bounding box. If the artist has already been drawn, the renderer is cached; thus, it is only necessary to pass this argument when calling get_window_extent before the first draw. In practice, it is usually easier to trigger a draw first (e.g. by saving the figure). dpifloat, optional The dpi value for computing the bbox, defaults to self.figure.dpi (not the renderer dpi); should be set e.g. if to match regions with a figure saved with a custom dpi value.
matplotlib.text_api#matplotlib.text.Text.get_window_extent
get_wrap()[source] Return whether the text can be wrapped.
matplotlib.text_api#matplotlib.text.Text.get_wrap
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 unknown clip_on unknown clip_path unknown color color figure Figure fontfamily {FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'} fontproperties font_manager.FontProperties or str or pathlib.Path fontsize float or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'} fontstretch {a numeric value in range 0-1000, 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'} fontstyle {'normal', 'italic', 'oblique'} fontvariant {'normal', 'small-caps'} fontweight {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 {'center', 'right', 'left'} in_layout bool label object linespacing float (multiple of font size) math_fontfamily str multialignment {'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 {'center', 'top', 'bottom', 'baseline', 'center_baseline'} visible bool wrap bool x float y float zorder float
matplotlib.text_api#matplotlib.text.Text.set
set_backgroundcolor(color)[source] Set the background color of the text by updating the bbox. Parameters colorcolor See also set_bbox To change the position of the bounding box
matplotlib.text_api#matplotlib.text.Text.set_backgroundcolor
set_bbox(rectprops)[source] Draw a bounding box around self. Parameters rectpropsdict with properties for patches.FancyBboxPatch The default boxstyle is 'square'. The mutation scale of the patches.FancyBboxPatch is set to the fontsize. Examples t.set_bbox(dict(facecolor='red', alpha=0.5))
matplotlib.text_api#matplotlib.text.Text.set_bbox
set_c(color)[source] Alias for set_color.
matplotlib.text_api#matplotlib.text.Text.set_c
set_clip_box(clipbox)[source] Set the artist's clip Bbox. Parameters clipboxBbox
matplotlib.text_api#matplotlib.text.Text.set_clip_box
set_clip_on(b)[source] Set whether the artist uses clipping. When False artists will be visible outside of the axes which can lead to unexpected results. Parameters bbool
matplotlib.text_api#matplotlib.text.Text.set_clip_on
set_clip_path(path, transform=None)[source] Set the artist's clip path. Parameters pathPatch or Path or TransformedPath or None The clip path. If given a Path, transform must be provided as well. If None, a previously set clip path is removed. transformTransform, optional Only used if path is a Path, in which case the given Path is converted to a TransformedPath using transform. Notes For efficiency, if path is a Rectangle this method will set the clipping box to the corresponding rectangle and set the clipping path to None. For technical reasons (support of set), a tuple (path, transform) is also accepted as a single positional parameter.
matplotlib.text_api#matplotlib.text.Text.set_clip_path
set_color(color)[source] Set the foreground color of the text Parameters colorcolor
matplotlib.text_api#matplotlib.text.Text.set_color
set_family(fontname)[source] Alias for set_fontfamily.
matplotlib.text_api#matplotlib.text.Text.set_family
set_font(fp)[source] Alias for set_fontproperties.
matplotlib.text_api#matplotlib.text.Text.set_font
set_font_properties(fp)[source] Alias for set_fontproperties.
matplotlib.text_api#matplotlib.text.Text.set_font_properties
set_fontfamily(fontname)[source] Set the font family. May be either a single string, or a list of strings in decreasing priority. Each string may be either a real font name or a generic font class name. If the latter, the specific font names will be looked up in the corresponding rcParams. If a Text instance is constructed with fontfamily=None, then the font is set to rcParams["font.family"] (default: ['sans-serif']), and the same is done when set_fontfamily() is called on an existing Text instance. Parameters fontname{FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'} See also font_manager.FontProperties.set_family
matplotlib.text_api#matplotlib.text.Text.set_fontfamily
set_fontname(fontname)[source] Alias for set_family. One-way alias only: the getter differs. Parameters fontname{FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'} See also font_manager.FontProperties.set_family
matplotlib.text_api#matplotlib.text.Text.set_fontname
set_fontproperties(fp)[source] Set the font properties that control the text. Parameters fpfont_manager.FontProperties or str or pathlib.Path If a str, it is interpreted as a fontconfig pattern parsed by FontProperties. If a pathlib.Path, it is interpreted as the absolute path to a font file.
matplotlib.text_api#matplotlib.text.Text.set_fontproperties
set_fontsize(fontsize)[source] Set the font size. Parameters fontsizefloat or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'} If float, the fontsize in points. The string values denote sizes relative to the default font size. See also font_manager.FontProperties.set_size
matplotlib.text_api#matplotlib.text.Text.set_fontsize
set_fontstretch(stretch)[source] Set the font stretch (horizontal condensation or expansion). Parameters stretch{a numeric value in range 0-1000, 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'} See also font_manager.FontProperties.set_stretch
matplotlib.text_api#matplotlib.text.Text.set_fontstretch
set_fontstyle(fontstyle)[source] Set the font style. Parameters fontstyle{'normal', 'italic', 'oblique'} See also font_manager.FontProperties.set_style
matplotlib.text_api#matplotlib.text.Text.set_fontstyle
set_fontvariant(variant)[source] Set the font variant. Parameters variant{'normal', 'small-caps'} See also font_manager.FontProperties.set_variant
matplotlib.text_api#matplotlib.text.Text.set_fontvariant
set_fontweight(weight)[source] Set the font weight. Parameters weight{a numeric value in range 0-1000, 'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'} See also font_manager.FontProperties.set_weight
matplotlib.text_api#matplotlib.text.Text.set_fontweight
set_ha(align)[source] Alias for set_horizontalalignment.
matplotlib.text_api#matplotlib.text.Text.set_ha
set_horizontalalignment(align)[source] Set the horizontal alignment to one of Parameters align{'center', 'right', 'left'}
matplotlib.text_api#matplotlib.text.Text.set_horizontalalignment
set_linespacing(spacing)[source] Set the line spacing as a multiple of the font size. The default line spacing is 1.2. Parameters spacingfloat (multiple of font size)
matplotlib.text_api#matplotlib.text.Text.set_linespacing
set_ma(align)[source] Alias for set_multialignment.
matplotlib.text_api#matplotlib.text.Text.set_ma
set_math_fontfamily(fontfamily)[source] Set the font family for math text rendered by Matplotlib. This does only affect Matplotlib's own math renderer. It has no effect when rendering with TeX (usetex=True). Parameters fontfamilystr The name of the font family. Available font families are defined in the matplotlibrc.template file. See also get_math_fontfamily
matplotlib.text_api#matplotlib.text.Text.set_math_fontfamily
set_multialignment(align)[source] Set the text alignment for multiline texts. The layout of the bounding box of all the lines is determined by the horizontalalignment and verticalalignment properties. This property controls the alignment of the text lines within that box. Parameters align{'left', 'right', 'center'}
matplotlib.text_api#matplotlib.text.Text.set_multialignment
set_name(fontname)[source] Alias for set_fontname.
matplotlib.text_api#matplotlib.text.Text.set_name
set_parse_math(parse_math)[source] Override switch to disable any mathtext parsing for this Text. Parameters parse_mathbool If False, this Text will never use mathtext. If True, mathtext will be used if there is an even number of unescaped dollar signs.
matplotlib.text_api#matplotlib.text.Text.set_parse_math
set_position(xy)[source] Set the (x, y) position of the text. Parameters xy(float, float)
matplotlib.text_api#matplotlib.text.Text.set_position
set_rotation(s)[source] Set the rotation of the text. Parameters sfloat or {'vertical', 'horizontal'} The rotation angle in degrees in mathematically positive direction (counterclockwise). 'horizontal' equals 0, 'vertical' equals 90.
matplotlib.text_api#matplotlib.text.Text.set_rotation
set_rotation_mode(m)[source] Set text rotation mode. Parameters m{None, 'default', 'anchor'} If None or "default", the text will be first rotated, then aligned according to their horizontal and vertical alignments. If "anchor", then alignment occurs before rotation.
matplotlib.text_api#matplotlib.text.Text.set_rotation_mode
set_size(fontsize)[source] Alias for set_fontsize.
matplotlib.text_api#matplotlib.text.Text.set_size
set_stretch(stretch)[source] Alias for set_fontstretch.
matplotlib.text_api#matplotlib.text.Text.set_stretch
set_style(fontstyle)[source] Alias for set_fontstyle.
matplotlib.text_api#matplotlib.text.Text.set_style
set_text(s)[source] Set the text string s. It may contain newlines (\n) or math in LaTeX syntax. Parameters sobject Any object gets converted to its str representation, except for None which is converted to an empty string.
matplotlib.text_api#matplotlib.text.Text.set_text
set_transform_rotates_text(t)[source] Whether rotations of the transform affect the text direction. Parameters tbool
matplotlib.text_api#matplotlib.text.Text.set_transform_rotates_text
set_usetex(usetex)[source] Parameters usetexbool or None Whether to render using TeX, None means to use rcParams["text.usetex"] (default: False).
matplotlib.text_api#matplotlib.text.Text.set_usetex
set_va(align)[source] Alias for set_verticalalignment.
matplotlib.text_api#matplotlib.text.Text.set_va
set_variant(variant)[source] Alias for set_fontvariant.
matplotlib.text_api#matplotlib.text.Text.set_variant
set_verticalalignment(align)[source] Set the vertical alignment. Parameters align{'center', 'top', 'bottom', 'baseline', 'center_baseline'}
matplotlib.text_api#matplotlib.text.Text.set_verticalalignment
set_weight(weight)[source] Alias for set_fontweight.
matplotlib.text_api#matplotlib.text.Text.set_weight
set_wrap(wrap)[source] Set whether the text can be wrapped. Parameters wrapbool Notes Wrapping does not work together with savefig(..., bbox_inches='tight') (which is also used internally by %matplotlib inline in IPython/Jupyter). The 'tight' setting rescales the canvas to accommodate all content and happens before wrapping.
matplotlib.text_api#matplotlib.text.Text.set_wrap
set_x(x)[source] Set the x position of the text. Parameters xfloat
matplotlib.text_api#matplotlib.text.Text.set_x
set_y(y)[source] Set the y position of the text. Parameters yfloat
matplotlib.text_api#matplotlib.text.Text.set_y
update(kwargs)[source] Update this artist's properties from the dict props. Parameters propsdict
matplotlib.text_api#matplotlib.text.Text.update
update_bbox_position_size(renderer)[source] Update the location and the size of the bbox. This method should be used when the position and size of the bbox needs to be updated before actually drawing the bbox.
matplotlib.text_api#matplotlib.text.Text.update_bbox_position_size
update_from(other)[source] Copy properties from other to self.
matplotlib.text_api#matplotlib.text.Text.update_from
zorder=3
matplotlib.text_api#matplotlib.text.Text.zorder
matplotlib.textpath classmatplotlib.textpath.TextPath(xy, s, size=None, prop=None, _interpolation_steps=1, usetex=False)[source] Bases: matplotlib.path.Path Create a path from the text. Create a path from the text. Note that it simply is a path, not an artist. You need to use the PathPatch (or other artists) to draw this path onto the canvas. Parameters xytuple or array of two float values Position of the text. For no offset, use xy=(0, 0). sstr The text to convert to a path. sizefloat, optional Font size in points. Defaults to the size specified via the font properties prop. propmatplotlib.font_manager.FontProperties, optional Font property. If not provided, will use a default FontProperties with parameters from the rcParams. _interpolation_stepsint, optional (Currently ignored) usetexbool, default: False Whether to use tex rendering. Examples The following creates a path from the string "ABC" with Helvetica font face; and another path from the latex fraction 1/2: from matplotlib.textpath import TextPath from matplotlib.font_manager import FontProperties fp = FontProperties(family="Helvetica", style="italic") path1 = TextPath((12, 12), "ABC", size=12, prop=fp) path2 = TextPath((0, 0), r"$\frac{1}{2}$", size=12, usetex=True) Also see Using a text as a Path. propertycodes Return the codes get_size()[source] Get the text size. set_size(size)[source] Set the text size. propertyvertices Return the cached path after updating it if necessary. classmatplotlib.textpath.TextToPath[source] Bases: object A class that converts strings to paths. DPI=72 FONT_SCALE=100.0 get_glyphs_mathtext(prop, s, glyph_map=None, return_new_glyphs_only=False)[source] Parse mathtext string s and convert it to a (vertices, codes) pair. get_glyphs_tex(prop, s, glyph_map=None, return_new_glyphs_only=False)[source] Convert the string s to vertices and codes using usetex mode. get_glyphs_with_font(font, s, glyph_map=None, return_new_glyphs_only=False)[source] Convert string s to vertices and codes using the provided ttf font. get_texmanager()[source] Return the cached TexManager instance. get_text_path(prop, s, ismath=False)[source] Convert text s to path (a tuple of vertices and codes for matplotlib.path.Path). Parameters propFontProperties The font properties for the text. sstr The text to be converted. ismath{False, True, "TeX"} If True, use mathtext parser. If "TeX", use tex for rendering. Returns vertslist A list of numpy arrays containing the x and y coordinates of the vertices. codeslist A list of path codes. Examples Create a list of vertices and codes from a text, and create a Path from those: from matplotlib.path import Path from matplotlib.textpath import TextToPath from matplotlib.font_manager import FontProperties fp = FontProperties(family="Humor Sans", style="italic") verts, codes = TextToPath().get_text_path(fp, "ABC") path = Path(verts, codes, closed=False) Also see TextPath for a more direct way to create a path from a text. get_text_width_height_descent(s, prop, ismath)[source]
matplotlib.textpath_api
classmatplotlib.textpath.TextPath(xy, s, size=None, prop=None, _interpolation_steps=1, usetex=False)[source] Bases: matplotlib.path.Path Create a path from the text. Create a path from the text. Note that it simply is a path, not an artist. You need to use the PathPatch (or other artists) to draw this path onto the canvas. Parameters xytuple or array of two float values Position of the text. For no offset, use xy=(0, 0). sstr The text to convert to a path. sizefloat, optional Font size in points. Defaults to the size specified via the font properties prop. propmatplotlib.font_manager.FontProperties, optional Font property. If not provided, will use a default FontProperties with parameters from the rcParams. _interpolation_stepsint, optional (Currently ignored) usetexbool, default: False Whether to use tex rendering. Examples The following creates a path from the string "ABC" with Helvetica font face; and another path from the latex fraction 1/2: from matplotlib.textpath import TextPath from matplotlib.font_manager import FontProperties fp = FontProperties(family="Helvetica", style="italic") path1 = TextPath((12, 12), "ABC", size=12, prop=fp) path2 = TextPath((0, 0), r"$\frac{1}{2}$", size=12, usetex=True) Also see Using a text as a Path. propertycodes Return the codes get_size()[source] Get the text size. set_size(size)[source] Set the text size. propertyvertices Return the cached path after updating it if necessary.
matplotlib.textpath_api#matplotlib.textpath.TextPath
get_size()[source] Get the text size.
matplotlib.textpath_api#matplotlib.textpath.TextPath.get_size
set_size(size)[source] Set the text size.
matplotlib.textpath_api#matplotlib.textpath.TextPath.set_size
classmatplotlib.textpath.TextToPath[source] Bases: object A class that converts strings to paths. DPI=72 FONT_SCALE=100.0 get_glyphs_mathtext(prop, s, glyph_map=None, return_new_glyphs_only=False)[source] Parse mathtext string s and convert it to a (vertices, codes) pair. get_glyphs_tex(prop, s, glyph_map=None, return_new_glyphs_only=False)[source] Convert the string s to vertices and codes using usetex mode. get_glyphs_with_font(font, s, glyph_map=None, return_new_glyphs_only=False)[source] Convert string s to vertices and codes using the provided ttf font. get_texmanager()[source] Return the cached TexManager instance. get_text_path(prop, s, ismath=False)[source] Convert text s to path (a tuple of vertices and codes for matplotlib.path.Path). Parameters propFontProperties The font properties for the text. sstr The text to be converted. ismath{False, True, "TeX"} If True, use mathtext parser. If "TeX", use tex for rendering. Returns vertslist A list of numpy arrays containing the x and y coordinates of the vertices. codeslist A list of path codes. Examples Create a list of vertices and codes from a text, and create a Path from those: from matplotlib.path import Path from matplotlib.textpath import TextToPath from matplotlib.font_manager import FontProperties fp = FontProperties(family="Humor Sans", style="italic") verts, codes = TextToPath().get_text_path(fp, "ABC") path = Path(verts, codes, closed=False) Also see TextPath for a more direct way to create a path from a text. get_text_width_height_descent(s, prop, ismath)[source]
matplotlib.textpath_api#matplotlib.textpath.TextToPath
DPI=72
matplotlib.textpath_api#matplotlib.textpath.TextToPath.DPI
FONT_SCALE=100.0
matplotlib.textpath_api#matplotlib.textpath.TextToPath.FONT_SCALE
get_glyphs_mathtext(prop, s, glyph_map=None, return_new_glyphs_only=False)[source] Parse mathtext string s and convert it to a (vertices, codes) pair.
matplotlib.textpath_api#matplotlib.textpath.TextToPath.get_glyphs_mathtext
get_glyphs_tex(prop, s, glyph_map=None, return_new_glyphs_only=False)[source] Convert the string s to vertices and codes using usetex mode.
matplotlib.textpath_api#matplotlib.textpath.TextToPath.get_glyphs_tex
get_glyphs_with_font(font, s, glyph_map=None, return_new_glyphs_only=False)[source] Convert string s to vertices and codes using the provided ttf font.
matplotlib.textpath_api#matplotlib.textpath.TextToPath.get_glyphs_with_font
get_texmanager()[source] Return the cached TexManager instance.
matplotlib.textpath_api#matplotlib.textpath.TextToPath.get_texmanager
get_text_path(prop, s, ismath=False)[source] Convert text s to path (a tuple of vertices and codes for matplotlib.path.Path). Parameters propFontProperties The font properties for the text. sstr The text to be converted. ismath{False, True, "TeX"} If True, use mathtext parser. If "TeX", use tex for rendering. Returns vertslist A list of numpy arrays containing the x and y coordinates of the vertices. codeslist A list of path codes. Examples Create a list of vertices and codes from a text, and create a Path from those: from matplotlib.path import Path from matplotlib.textpath import TextToPath from matplotlib.font_manager import FontProperties fp = FontProperties(family="Humor Sans", style="italic") verts, codes = TextToPath().get_text_path(fp, "ABC") path = Path(verts, codes, closed=False) Also see TextPath for a more direct way to create a path from a text.
matplotlib.textpath_api#matplotlib.textpath.TextToPath.get_text_path
get_text_width_height_descent(s, prop, ismath)[source]
matplotlib.textpath_api#matplotlib.textpath.TextToPath.get_text_width_height_descent
matplotlib.ticker Tick locating and formatting This module contains classes for configuring tick locating and formatting. Generic tick locators and formatters are provided, as well as domain specific custom ones. Although the locators know nothing about major or minor ticks, they are used by the Axis class to support major and minor tick locating and formatting. Tick locating The Locator class is the base class for all tick locators. The locators handle autoscaling of the view limits based on the data limits, and the choosing of tick locations. A useful semi-automatic tick locator is MultipleLocator. It is initialized with a base, e.g., 10, and it picks axis limits and ticks that are multiples of that base. The Locator subclasses defined here are: AutoLocator MaxNLocator with simple defaults. This is the default tick locator for most plotting. MaxNLocator Finds up to a max number of intervals with ticks at nice locations. LinearLocator Space ticks evenly from min to max. LogLocator Space ticks logarithmically from min to max. MultipleLocator Ticks and range are a multiple of base; either integer or float. FixedLocator Tick locations are fixed. IndexLocator Locator for index plots (e.g., where x = range(len(y))). NullLocator No ticks. SymmetricalLogLocator Locator for use with with the symlog norm; works like LogLocator for the part outside of the threshold and adds 0 if inside the limits. LogitLocator Locator for logit scaling. AutoMinorLocator Locator for minor ticks when the axis is linear and the major ticks are uniformly spaced. Subdivides the major tick interval into a specified number of minor intervals, defaulting to 4 or 5 depending on the major interval. There are a number of locators specialized for date locations - see the dates module. You can define your own locator by deriving from Locator. You must override the __call__ method, which returns a sequence of locations, and you will probably want to override the autoscale method to set the view limits from the data limits. If you want to override the default locator, use one of the above or a custom locator and pass it to the x or y axis instance. The relevant methods are: ax.xaxis.set_major_locator(xmajor_locator) ax.xaxis.set_minor_locator(xminor_locator) ax.yaxis.set_major_locator(ymajor_locator) ax.yaxis.set_minor_locator(yminor_locator) The default minor locator is NullLocator, i.e., no minor ticks on by default. Note Locator instances should not be used with more than one Axis or Axes. So instead of: locator = MultipleLocator(5) ax.xaxis.set_major_locator(locator) ax2.xaxis.set_major_locator(locator) do the following instead: ax.xaxis.set_major_locator(MultipleLocator(5)) ax2.xaxis.set_major_locator(MultipleLocator(5)) Tick formatting Tick formatting is controlled by classes derived from Formatter. The formatter operates on a single tick value and returns a string to the axis. NullFormatter No labels on the ticks. FixedFormatter Set the strings manually for the labels. FuncFormatter User defined function sets the labels. StrMethodFormatter Use string format method. FormatStrFormatter Use an old-style sprintf format string. ScalarFormatter Default formatter for scalars: autopick the format string. LogFormatter Formatter for log axes. LogFormatterExponent Format values for log axis using exponent = log_base(value). LogFormatterMathtext Format values for log axis using exponent = log_base(value) using Math text. LogFormatterSciNotation Format values for log axis using scientific notation. LogitFormatter Probability formatter. EngFormatter Format labels in engineering notation. PercentFormatter Format labels as a percentage. You can derive your own formatter from the Formatter base class by simply overriding the __call__ method. The formatter class has access to the axis view and data limits. To control the major and minor tick label formats, use one of the following methods: ax.xaxis.set_major_formatter(xmajor_formatter) ax.xaxis.set_minor_formatter(xminor_formatter) ax.yaxis.set_major_formatter(ymajor_formatter) ax.yaxis.set_minor_formatter(yminor_formatter) In addition to a Formatter instance, set_major_formatter and set_minor_formatter also accept a str or function. str input will be internally replaced with an autogenerated StrMethodFormatter with the input str. For function input, a FuncFormatter with the input function will be generated and used. See Major and minor ticks for an example of setting major and minor ticks. See the matplotlib.dates module for more information and examples of using date locators and formatters. classmatplotlib.ticker.AutoLocator[source] Bases: matplotlib.ticker.MaxNLocator Dynamically find major tick positions. This is actually a subclass of MaxNLocator, with parameters nbins = 'auto' and steps = [1, 2, 2.5, 5, 10]. To know the values of the non-public parameters, please have a look to the defaults of MaxNLocator. classmatplotlib.ticker.AutoMinorLocator(n=None)[source] Bases: matplotlib.ticker.Locator Dynamically find minor tick positions based on the positions of major ticks. The scale must be linear with major ticks evenly spaced. n is the number of subdivisions of the interval between major ticks; e.g., n=2 will place a single minor tick midway between major ticks. If n is omitted or None, it will be set to 5 or 4. 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.ticker.EngFormatter(unit='', places=None, sep=' ', *, usetex=None, useMathText=None)[source] Bases: matplotlib.ticker.Formatter Format axis values using engineering prefixes to represent powers of 1000, plus a specified unit, e.g., 10 MHz instead of 1e7. Parameters unitstr, default: "" Unit symbol to use, suitable for use with single-letter representations of powers of 1000. For example, 'Hz' or 'm'. placesint, default: None Precision with which to display the number, specified in digits after the decimal point (there will be between one and three digits before the decimal point). If it is None, the formatting falls back to the floating point format '%g', which displays up to 6 significant digits, i.e. the equivalent value for places varies between 0 and 5 (inclusive). sepstr, default: " " Separator used between the value and the prefix/unit. For example, one get '3.14 mV' if sep is " " (default) and '3.14mV' if sep is "". Besides the default behavior, some other useful options may be: sep="" to append directly the prefix/unit to the value; sep="\N{THIN SPACE}" (U+2009); sep="\N{NARROW NO-BREAK SPACE}" (U+202F); sep="\N{NO-BREAK SPACE}" (U+00A0). usetexbool, default: rcParams["text.usetex"] (default: False) To enable/disable the use of TeX's math mode for rendering the numbers in the formatter. useMathTextbool, default: rcParams["axes.formatter.use_mathtext"] (default: False) To enable/disable the use mathtext for rendering the numbers in the formatter. ENG_PREFIXES={-24: 'y', -21: 'z', -18: 'a', -15: 'f', -12: 'p', -9: 'n', -6: 'µ', -3: 'm', 0: '', 3: 'k', 6: 'M', 9: 'G', 12: 'T', 15: 'P', 18: 'E', 21: 'Z', 24: 'Y'} format_eng(num)[source] Format a number in engineering notation, appending a letter representing the power of 1000 of the original number. Some examples: >>> format_eng(0) # for self.places = 0 '0' >>> format_eng(1000000) # for self.places = 1 '1.0 M' >>> format_eng("-1e-6") # for self.places = 2 '-1.00 µ' get_useMathText()[source] get_usetex()[source] set_useMathText(val)[source] set_usetex(val)[source] propertyuseMathText propertyusetex classmatplotlib.ticker.FixedFormatter(seq)[source] Bases: matplotlib.ticker.Formatter Return fixed strings for tick labels based only on position, not value. Note FixedFormatter should only be used together with FixedLocator. Otherwise, the labels may end up in unexpected positions. Set the sequence seq of strings that will be used for labels. get_offset()[source] set_offset_string(ofs)[source] classmatplotlib.ticker.FixedLocator(locs, nbins=None)[source] Bases: matplotlib.ticker.Locator Tick locations are fixed. If nbins is not None, the array of possible positions will be subsampled to keep the number of ticks <= nbins +1. The subsampling will be done so as to include the smallest absolute value; for example, if zero is included in the array of possibilities, then it is guaranteed to be one of the chosen ticks. set_params(nbins=None)[source] Set parameters within this locator. tick_values(vmin, vmax)[source] Return the locations of the ticks. Note Because the values are fixed, vmin and vmax are not used in this method. classmatplotlib.ticker.FormatStrFormatter(fmt)[source] Bases: matplotlib.ticker.Formatter Use an old-style ('%' operator) format string to format the tick. The format string should have a single variable format (%) in it. It will be applied to the value (not the position) of the tick. Negative numeric values will use a dash not a unicode minus, use mathtext to get a unicode minus by wrappping the format specifier with $ (e.g. "$%g$"). classmatplotlib.ticker.Formatter[source] Bases: matplotlib.ticker.TickHelper Create a string based on a tick value and location. staticfix_minus(s)[source] Some classes may want to replace a hyphen for minus with the proper unicode symbol (U+2212) for typographical correctness. This is a helper method to perform such a replacement when it is enabled via rcParams["axes.unicode_minus"] (default: True). format_data(value)[source] Return the full string representation of the value with the position unspecified. 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] locs=[] set_locs(locs)[source] Set the locations of the ticks. This method is called before computing the tick labels because some formatters need to know all tick locations to do so. classmatplotlib.ticker.FuncFormatter(func)[source] Bases: matplotlib.ticker.Formatter Use a user-defined function for formatting. The function should take in two inputs (a tick value x and a position pos), and return a string containing the corresponding tick label. get_offset()[source] set_offset_string(ofs)[source] classmatplotlib.ticker.IndexLocator(base, offset)[source] Bases: matplotlib.ticker.Locator Place a tick on every multiple of some base number of points plotted, e.g., on every 5th point. It is assumed that you are doing index plotting; i.e., the axis is 0, len(data). This is mainly useful for x ticks. Place ticks every base data point, starting at offset. set_params(base=None, offset=None)[source] Set parameters within this locator 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.ticker.LinearLocator(numticks=None, presets=None)[source] Bases: matplotlib.ticker.Locator Determine the tick locations The first time this function is called it will try to set the number of ticks to make a nice tick partitioning. Thereafter the number of ticks will be fixed so that interactive navigation will be nice Use presets to set locs based on lom. A dict mapping vmin, vmax->locs propertynumticks set_params(numticks=None, presets=None)[source] Set parameters within this locator. 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] view_limits(vmin, vmax)[source] Try to choose the view limits intelligently. classmatplotlib.ticker.Locator[source] Bases: matplotlib.ticker.TickHelper Determine the tick locations; Note that the same locator should not be used across multiple Axis because the locator stores references to the Axis data and view limits. MAXTICKS=1000 nonsingular(v0, v1)[source] Adjust a range as needed to avoid singularities. This method gets called during autoscaling, with (v0, v1) set to the data limits on the axes if the axes contains any data, or (-inf, +inf) if not. If v0 == v1 (possibly up to some floating point slop), this method returns an expanded interval around this value. If (v0, v1) == (-inf, +inf), this method returns appropriate default view limits. Otherwise, (v0, v1) is returned without modification. raise_if_exceeds(locs)[source] Log at WARNING level if locs is longer than Locator.MAXTICKS. This is intended to be called immediately before returning locs from __call__ to inform users in case their Locator returns a huge number of ticks, causing Matplotlib to run out of memory. The "strange" name of this method dates back to when it would raise an exception instead of emitting a log. set_params(**kwargs)[source] Do nothing, and raise a warning. Any locator class not supporting the set_params() function will call this. 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] view_limits(vmin, vmax)[source] Select a scale for the range from vmin to vmax. Subclasses should override this method to change locator behaviour. classmatplotlib.ticker.LogFormatter(base=10.0, labelOnlyBase=False, minor_thresholds=None, linthresh=None)[source] Bases: matplotlib.ticker.Formatter Base class for formatting ticks on a log or symlog scale. It may be instantiated directly, or subclassed. Parameters basefloat, default: 10. Base of the logarithm used in all calculations. labelOnlyBasebool, default: False If True, label ticks only at integer powers of base. This is normally True for major ticks and False for minor ticks. minor_thresholds(subset, all), default: (1, 0.4) If labelOnlyBase is False, these two numbers control the labeling of ticks that are not at integer powers of base; normally these are the minor ticks. The controlling parameter is the log of the axis data range. In the typical case where base is 10 it is the number of decades spanned by the axis, so we can call it 'numdec'. If numdec <= all, all minor ticks will be labeled. If all < numdec <= subset, then only a subset of minor ticks will be labeled, so as to avoid crowding. If numdec > subset then no minor ticks will be labeled. linthreshNone or float, default: None If a symmetric log scale is in use, its linthresh parameter must be supplied here. Notes The set_locs method must be called to enable the subsetting logic controlled by the minor_thresholds parameter. In some cases such as the colorbar, there is no distinction between major and minor ticks; the tick locations might be set manually, or by a locator that puts ticks at integer powers of base and at intermediate locations. For this situation, disable the minor_thresholds logic by using minor_thresholds=(np.inf, np.inf), so that all ticks will be labeled. To disable labeling of minor ticks when 'labelOnlyBase' is False, use minor_thresholds=(0, 0). This is the default for the "classic" style. Examples To label a subset of minor ticks when the view limits span up to 2 decades, and all of the ticks when zoomed in to 0.5 decades or less, use minor_thresholds=(2, 0.5). To label all minor ticks when the view limits span up to 1.5 decades, use minor_thresholds=(1.5, 1.5). base(base)[source] Change the base for labeling. Warning Should always match the base used for LogLocator format_data(value)[source] Return the full string representation of the value with the position unspecified. format_data_short(value)[source] Return a short string version of the tick value. Defaults to the position-independent long value. label_minor(labelOnlyBase)[source] Switch minor tick labeling on or off. Parameters labelOnlyBasebool If True, label ticks only at integer powers of base. set_locs(locs=None)[source] Use axis view limits to control which ticks are labeled. The locs parameter is ignored in the present algorithm. classmatplotlib.ticker.LogFormatterExponent(base=10.0, labelOnlyBase=False, minor_thresholds=None, linthresh=None)[source] Bases: matplotlib.ticker.LogFormatter Format values for log axis using exponent = log_base(value). classmatplotlib.ticker.LogFormatterMathtext(base=10.0, labelOnlyBase=False, minor_thresholds=None, linthresh=None)[source] Bases: matplotlib.ticker.LogFormatter Format values for log axis using exponent = log_base(value). classmatplotlib.ticker.LogFormatterSciNotation(base=10.0, labelOnlyBase=False, minor_thresholds=None, linthresh=None)[source] Bases: matplotlib.ticker.LogFormatterMathtext Format values following scientific notation in a logarithmic axis. classmatplotlib.ticker.LogLocator(base=10.0, subs=(1.0,), numdecs=4, numticks=None)[source] Bases: matplotlib.ticker.Locator Determine the tick locations for log axes Place ticks on the locations : subs[j] * base**i Parameters basefloat, default: 10.0 The base of the log used, so ticks are placed at base**n. subsNone or str or sequence of float, default: (1.0,) Gives the multiples of integer powers of the base at which to place ticks. The default places ticks only at integer powers of the base. The permitted string values are 'auto' and 'all', both of which use an algorithm based on the axis view limits to determine whether and how to put ticks between integer powers of the base. With 'auto', ticks are placed only between integer powers; with 'all', the integer powers are included. A value of None is equivalent to 'auto'. numticksNone or int, default: None The maximum number of ticks to allow on a given axis. The default of None will try to choose intelligently as long as this Locator has already been assigned to an axis using get_tick_space, but otherwise falls back to 9. base(base)[source] Set the log base (major tick every base**i, i integer). nonsingular(vmin, vmax)[source] Adjust a range as needed to avoid singularities. This method gets called during autoscaling, with (v0, v1) set to the data limits on the axes if the axes contains any data, or (-inf, +inf) if not. If v0 == v1 (possibly up to some floating point slop), this method returns an expanded interval around this value. If (v0, v1) == (-inf, +inf), this method returns appropriate default view limits. Otherwise, (v0, v1) is returned without modification. set_params(base=None, subs=None, numdecs=None, numticks=None)[source] Set parameters within this locator. subs(subs)[source] Set the minor ticks for the log scaling every base**i*subs[j]. 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] view_limits(vmin, vmax)[source] Try to choose the view limits intelligently. classmatplotlib.ticker.LogitFormatter(*, use_overline=False, one_half='\x0crac{1}{2}', minor=False, minor_threshold=25, minor_number=6)[source] Bases: matplotlib.ticker.Formatter Probability formatter (using Math text). Parameters use_overlinebool, default: False If x > 1/2, with x = 1-v, indicate if x should be displayed as $overline{v}$. The default is to display $1-v$. one_halfstr, default: r"frac{1}{2}" The string used to represent 1/2. minorbool, default: False Indicate if the formatter is formatting minor ticks or not. Basically minor ticks are not labelled, except when only few ticks are provided, ticks with most space with neighbor ticks are labelled. See other parameters to change the default behavior. minor_thresholdint, default: 25 Maximum number of locs for labelling some minor ticks. This parameter have no effect if minor is False. minor_numberint, default: 6 Number of ticks which are labelled when the number of ticks is below the threshold. format_data_short(value)[source] Return a short string version of the tick value. Defaults to the position-independent long value. set_locs(locs)[source] Set the locations of the ticks. This method is called before computing the tick labels because some formatters need to know all tick locations to do so. set_minor_number(minor_number)[source] Set the number of minor ticks to label when some minor ticks are labelled. Parameters minor_numberint Number of ticks which are labelled when the number of ticks is below the threshold. set_minor_threshold(minor_threshold)[source] Set the threshold for labelling minors ticks. Parameters minor_thresholdint Maximum number of locations for labelling some minor ticks. This parameter have no effect if minor is False. set_one_half(one_half)[source] Set the way one half is displayed. one_halfstr, default: r"frac{1}{2}" The string used to represent 1/2. use_overline(use_overline)[source] Switch display mode with overline for labelling p>1/2. Parameters use_overlinebool, default: False If x > 1/2, with x = 1-v, indicate if x should be displayed as $overline{v}$. The default is to display $1-v$. classmatplotlib.ticker.LogitLocator(minor=False, *, nbins='auto')[source] Bases: matplotlib.ticker.MaxNLocator Determine the tick locations for logit axes Place ticks on the logit locations Parameters nbinsint or 'auto', optional Number of ticks. Only used if minor is False. minorbool, default: False Indicate if this locator is for minor ticks or not. propertyminor nonsingular(vmin, vmax)[source] Adjust a range as needed to avoid singularities. This method gets called during autoscaling, with (v0, v1) set to the data limits on the axes if the axes contains any data, or (-inf, +inf) if not. If v0 == v1 (possibly up to some floating point slop), this method returns an expanded interval around this value. If (v0, v1) == (-inf, +inf), this method returns appropriate default view limits. Otherwise, (v0, v1) is returned without modification. set_params(minor=None, **kwargs)[source] Set parameters within this locator. 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.ticker.MaxNLocator(nbins=None, **kwargs)[source] Bases: matplotlib.ticker.Locator Find nice tick locations with no more than N being within the view limits. Locations beyond the limits are added to support autoscaling. Parameters nbinsint or 'auto', default: 10 Maximum number of intervals; one less than max number of ticks. If the string 'auto', the number of bins will be automatically determined based on the length of the axis. stepsarray-like, optional Sequence of nice numbers starting with 1 and ending with 10; e.g., [1, 2, 4, 5, 10], where the values are acceptable tick multiples. i.e. for the example, 20, 40, 60 would be an acceptable set of ticks, as would 0.4, 0.6, 0.8, because they are multiples of 2. However, 30, 60, 90 would not be allowed because 3 does not appear in the list of steps. integerbool, default: False If True, ticks will take only integer values, provided at least min_n_ticks integers are found within the view limits. symmetricbool, default: False If True, autoscaling will result in a range symmetric about zero. prune{'lower', 'upper', 'both', None}, default: None Remove edge ticks -- useful for stacked or ganged plots where the upper tick of one axes overlaps with the lower tick of the axes above it, primarily when rcParams["axes.autolimit_mode"] (default: 'data') is 'round_numbers'. If prune=='lower', the smallest tick will be removed. If prune == 'upper', the largest tick will be removed. If prune == 'both', the largest and smallest ticks will be removed. If prune is None, no ticks will be removed. min_n_ticksint, default: 2 Relax nbins and integer constraints if necessary to obtain this minimum number of ticks. default_params={'integer': False, 'min_n_ticks': 2, 'nbins': 10, 'prune': None, 'steps': None, 'symmetric': False} set_params(**kwargs)[source] Set parameters for this locator. Parameters nbinsint or 'auto', optional see MaxNLocator stepsarray-like, optional see MaxNLocator integerbool, optional see MaxNLocator symmetricbool, optional see MaxNLocator prune{'lower', 'upper', 'both', None}, optional see MaxNLocator min_n_ticksint, optional see MaxNLocator 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] view_limits(dmin, dmax)[source] Select a scale for the range from vmin to vmax. Subclasses should override this method to change locator behaviour. classmatplotlib.ticker.MultipleLocator(base=1.0)[source] Bases: matplotlib.ticker.Locator Set a tick on each integer multiple of a base within the view interval. set_params(base)[source] Set parameters within this locator. 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] view_limits(dmin, dmax)[source] Set the view limits to the nearest multiples of base that contain the data. classmatplotlib.ticker.NullFormatter[source] Bases: matplotlib.ticker.Formatter Always return the empty string. classmatplotlib.ticker.NullLocator[source] Bases: matplotlib.ticker.Locator No ticks tick_values(vmin, vmax)[source] Return the locations of the ticks. Note Because the values are Null, vmin and vmax are not used in this method. classmatplotlib.ticker.PercentFormatter(xmax=100, decimals=None, symbol='%', is_latex=False)[source] Bases: matplotlib.ticker.Formatter Format numbers as a percentage. Parameters xmaxfloat Determines how the number is converted into a percentage. xmax is the data value that corresponds to 100%. Percentages are computed as x / xmax * 100. So if the data is already scaled to be percentages, xmax will be 100. Another common situation is where xmax is 1.0. decimalsNone or int The number of decimal places to place after the point. If None (the default), the number will be computed automatically. symbolstr or None A string that will be appended to the label. It may be None or empty to indicate that no symbol should be used. LaTeX special characters are escaped in symbol whenever latex mode is enabled, unless is_latex is True. is_latexbool If False, reserved LaTeX characters in symbol will be escaped. convert_to_pct(x)[source] format_pct(x, display_range)[source] Format the number as a percentage number with the correct number of decimals and adds the percent symbol, if any. If self.decimals is None, the number of digits after the decimal point is set based on the display_range of the axis as follows: display_range decimals sample >50 0 x = 34.5 => 35% >5 1 x = 34.5 => 34.5% >0.5 2 x = 34.5 => 34.50% ... ... ... This method will not be very good for tiny axis ranges or extremely large ones. It assumes that the values on the chart are percentages displayed on a reasonable scale. propertysymbol The configured percent symbol as a string. If LaTeX is enabled via rcParams["text.usetex"] (default: False), the special characters {'#', '$', '%', '&', '~', '_', '^', '\', '{', '}'} are automatically escaped in the string. classmatplotlib.ticker.ScalarFormatter(useOffset=None, useMathText=None, useLocale=None)[source] Bases: matplotlib.ticker.Formatter Format tick values as a number. Parameters useOffsetbool or float, default: rcParams["axes.formatter.useoffset"] (default: True) Whether to use offset notation. See set_useOffset. useMathTextbool, default: rcParams["axes.formatter.use_mathtext"] (default: False) Whether to use fancy math formatting. See set_useMathText. useLocalebool, default: rcParams["axes.formatter.use_locale"] (default: False). Whether to use locale settings for decimal sign and positive sign. See set_useLocale. Notes In addition to the parameters above, the formatting of scientific vs. floating point representation can be configured via set_scientific and set_powerlimits). Offset notation and scientific notation Offset notation and scientific notation look quite similar at first sight. Both split some information from the formatted tick values and display it at the end of the axis. The scientific notation splits up the order of magnitude, i.e. a multiplicative scaling factor, e.g. 1e6. The offset notation separates an additive constant, e.g. +1e6. The offset notation label is always prefixed with a + or - sign and is thus distinguishable from the order of magnitude label. The following plot with x limits 1_000_000 to 1_000_010 illustrates the different formatting. Note the labels at the right edge of the x axis. (Source code, png, pdf) format_data(value)[source] Return the full string representation of the value with the position unspecified. format_data_short(value)[source] Return a short string version of the tick value. Defaults to the position-independent long value. get_offset()[source] Return scientific notation, plus offset. get_useLocale()[source] Return whether locale settings are used for formatting. See also ScalarFormatter.set_useLocale get_useMathText()[source] Return whether to use fancy math formatting. See also ScalarFormatter.set_useMathText get_useOffset()[source] Return whether automatic mode for offset notation is active. This returns True if set_useOffset(True); it returns False if an explicit offset was set, e.g. set_useOffset(1000). See also ScalarFormatter.set_useOffset set_locs(locs)[source] Set the locations of the ticks. This method is called before computing the tick labels because some formatters need to know all tick locations to do so. set_powerlimits(lims)[source] Set size thresholds for scientific notation. Parameters lims(int, int) A tuple (min_exp, max_exp) containing the powers of 10 that determine the switchover threshold. For a number representable as \(a \times 10^\mathrm{exp}\) with \(1 <= |a| < 10\), scientific notation will be used if exp <= min_exp or exp >= max_exp. The default limits are controlled by rcParams["axes.formatter.limits"] (default: [-5, 6]). In particular numbers with exp equal to the thresholds are written in scientific notation. Typically, min_exp will be negative and max_exp will be positive. For example, formatter.set_powerlimits((-3, 4)) will provide the following formatting: \(1 \times 10^{-3}, 9.9 \times 10^{-3}, 0.01,\) \(9999, 1 \times 10^4\). See also ScalarFormatter.set_scientific set_scientific(b)[source] Turn scientific notation on or off. See also ScalarFormatter.set_powerlimits set_useLocale(val)[source] Set whether to use locale settings for decimal sign and positive sign. Parameters valbool or None None resets to rcParams["axes.formatter.use_locale"] (default: False). set_useMathText(val)[source] Set whether to use fancy math formatting. If active, scientific notation is formatted as \(1.2 \times 10^3\). Parameters valbool or None None resets to rcParams["axes.formatter.use_mathtext"] (default: False). set_useOffset(val)[source] Set whether to use offset notation. When formatting a set numbers whose value is large compared to their range, the formatter can separate an additive constant. This can shorten the formatted numbers so that they are less likely to overlap when drawn on an axis. Parameters valbool or float If False, do not use offset notation. If True (=automatic mode), use offset notation if it can make the residual numbers significantly shorter. The exact behavior is controlled by rcParams["axes.formatter.offset_threshold"] (default: 4). If a number, force an offset of the given value. Examples With active offset notation, the values 100_000, 100_002, 100_004, 100_006, 100_008 will be formatted as 0, 2, 4, 6, 8 plus an offset +1e5, which is written to the edge of the axis. propertyuseLocale Return whether locale settings are used for formatting. See also ScalarFormatter.set_useLocale propertyuseMathText Return whether to use fancy math formatting. See also ScalarFormatter.set_useMathText propertyuseOffset Return whether automatic mode for offset notation is active. This returns True if set_useOffset(True); it returns False if an explicit offset was set, e.g. set_useOffset(1000). See also ScalarFormatter.set_useOffset classmatplotlib.ticker.StrMethodFormatter(fmt)[source] Bases: matplotlib.ticker.Formatter Use a new-style format string (as used by str.format) to format the tick. The field used for the tick value must be labeled x and the field used for the tick position must be labeled pos. classmatplotlib.ticker.SymmetricalLogLocator(transform=None, subs=None, linthresh=None, base=None)[source] Bases: matplotlib.ticker.Locator Determine the tick locations for symmetric log axes. Parameters transformSymmetricalLogTransform, optional If set, defines the base and linthresh of the symlog transform. base, linthreshfloat, optional The base and linthresh of the symlog transform, as documented for SymmetricalLogScale. These parameters are only used if transform is not set. subssequence of float, default: [1] The multiples of integer powers of the base where ticks are placed, i.e., ticks are placed at [sub * base**i for i in ... for sub in subs]. Notes Either transform, or both base and linthresh, must be given. set_params(subs=None, numticks=None)[source] Set parameters within this locator. 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] view_limits(vmin, vmax)[source] Try to choose the view limits intelligently. classmatplotlib.ticker.TickHelper[source] Bases: object axis=None create_dummy_axis(**kwargs)[source] set_axis(axis)[source] set_bounds(vmin, vmax)[source] [Deprecated] Notes Deprecated since version 3.5: 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:
matplotlib.ticker_api
classmatplotlib.ticker.AutoLocator[source] Bases: matplotlib.ticker.MaxNLocator Dynamically find major tick positions. This is actually a subclass of MaxNLocator, with parameters nbins = 'auto' and steps = [1, 2, 2.5, 5, 10]. To know the values of the non-public parameters, please have a look to the defaults of MaxNLocator.
matplotlib.ticker_api#matplotlib.ticker.AutoLocator
classmatplotlib.ticker.AutoMinorLocator(n=None)[source] Bases: matplotlib.ticker.Locator Dynamically find minor tick positions based on the positions of major ticks. The scale must be linear with major ticks evenly spaced. n is the number of subdivisions of the interval between major ticks; e.g., n=2 will place a single minor tick midway between major ticks. If n is omitted or None, it will be set to 5 or 4. 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.ticker_api#matplotlib.ticker.AutoMinorLocator
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.ticker_api#matplotlib.ticker.AutoMinorLocator.tick_values
classmatplotlib.ticker.EngFormatter(unit='', places=None, sep=' ', *, usetex=None, useMathText=None)[source] Bases: matplotlib.ticker.Formatter Format axis values using engineering prefixes to represent powers of 1000, plus a specified unit, e.g., 10 MHz instead of 1e7. Parameters unitstr, default: "" Unit symbol to use, suitable for use with single-letter representations of powers of 1000. For example, 'Hz' or 'm'. placesint, default: None Precision with which to display the number, specified in digits after the decimal point (there will be between one and three digits before the decimal point). If it is None, the formatting falls back to the floating point format '%g', which displays up to 6 significant digits, i.e. the equivalent value for places varies between 0 and 5 (inclusive). sepstr, default: " " Separator used between the value and the prefix/unit. For example, one get '3.14 mV' if sep is " " (default) and '3.14mV' if sep is "". Besides the default behavior, some other useful options may be: sep="" to append directly the prefix/unit to the value; sep="\N{THIN SPACE}" (U+2009); sep="\N{NARROW NO-BREAK SPACE}" (U+202F); sep="\N{NO-BREAK SPACE}" (U+00A0). usetexbool, default: rcParams["text.usetex"] (default: False) To enable/disable the use of TeX's math mode for rendering the numbers in the formatter. useMathTextbool, default: rcParams["axes.formatter.use_mathtext"] (default: False) To enable/disable the use mathtext for rendering the numbers in the formatter. ENG_PREFIXES={-24: 'y', -21: 'z', -18: 'a', -15: 'f', -12: 'p', -9: 'n', -6: 'µ', -3: 'm', 0: '', 3: 'k', 6: 'M', 9: 'G', 12: 'T', 15: 'P', 18: 'E', 21: 'Z', 24: 'Y'} format_eng(num)[source] Format a number in engineering notation, appending a letter representing the power of 1000 of the original number. Some examples: >>> format_eng(0) # for self.places = 0 '0' >>> format_eng(1000000) # for self.places = 1 '1.0 M' >>> format_eng("-1e-6") # for self.places = 2 '-1.00 µ' get_useMathText()[source] get_usetex()[source] set_useMathText(val)[source] set_usetex(val)[source] propertyuseMathText propertyusetex
matplotlib.ticker_api#matplotlib.ticker.EngFormatter
ENG_PREFIXES={-24: 'y', -21: 'z', -18: 'a', -15: 'f', -12: 'p', -9: 'n', -6: 'µ', -3: 'm', 0: '', 3: 'k', 6: 'M', 9: 'G', 12: 'T', 15: 'P', 18: 'E', 21: 'Z', 24: 'Y'}
matplotlib.ticker_api#matplotlib.ticker.EngFormatter.ENG_PREFIXES
format_eng(num)[source] Format a number in engineering notation, appending a letter representing the power of 1000 of the original number. Some examples: >>> format_eng(0) # for self.places = 0 '0' >>> format_eng(1000000) # for self.places = 1 '1.0 M' >>> format_eng("-1e-6") # for self.places = 2 '-1.00 µ'
matplotlib.ticker_api#matplotlib.ticker.EngFormatter.format_eng
get_useMathText()[source]
matplotlib.ticker_api#matplotlib.ticker.EngFormatter.get_useMathText
get_usetex()[source]
matplotlib.ticker_api#matplotlib.ticker.EngFormatter.get_usetex
set_useMathText(val)[source]
matplotlib.ticker_api#matplotlib.ticker.EngFormatter.set_useMathText
set_usetex(val)[source]
matplotlib.ticker_api#matplotlib.ticker.EngFormatter.set_usetex
classmatplotlib.ticker.FixedFormatter(seq)[source] Bases: matplotlib.ticker.Formatter Return fixed strings for tick labels based only on position, not value. Note FixedFormatter should only be used together with FixedLocator. Otherwise, the labels may end up in unexpected positions. Set the sequence seq of strings that will be used for labels. get_offset()[source] set_offset_string(ofs)[source]
matplotlib.ticker_api#matplotlib.ticker.FixedFormatter
get_offset()[source]
matplotlib.ticker_api#matplotlib.ticker.FixedFormatter.get_offset
set_offset_string(ofs)[source]
matplotlib.ticker_api#matplotlib.ticker.FixedFormatter.set_offset_string
classmatplotlib.ticker.FixedLocator(locs, nbins=None)[source] Bases: matplotlib.ticker.Locator Tick locations are fixed. If nbins is not None, the array of possible positions will be subsampled to keep the number of ticks <= nbins +1. The subsampling will be done so as to include the smallest absolute value; for example, if zero is included in the array of possibilities, then it is guaranteed to be one of the chosen ticks. set_params(nbins=None)[source] Set parameters within this locator. tick_values(vmin, vmax)[source] Return the locations of the ticks. Note Because the values are fixed, vmin and vmax are not used in this method.
matplotlib.ticker_api#matplotlib.ticker.FixedLocator