### Navigation

- index
- modules |
- home|
- examples|
- tutorials|
- pyplot|
- docs »

# Set And Get

The pyplot interface allows you to use setp and getp to set and get object properties, as well as to do introspection on the object

## set

To set the linestyle of a line to be dashed, you can do:

    >>> line, = plt.plot([1,2,3])
    >>> plt.setp(line, linestyle='--')

If you want to know the valid types of arguments, you can provide the name of the property you want to set without a value:

    >>> plt.setp(line, 'linestyle')
        linestyle: [ '-' | '--' | '-.' | ':' | 'steps' | 'None' ]

If you want to see all the properties that can be set, and their possible values, you can do:

    >>> plt.setp(line)

set operates on a single instance or a list of instances. If you are in query mode introspecting the possible values, only the first instance in the sequence is used. When actually setting values, all the instances will be set. e.g., suppose you have a list of two lines, the following will make both lines thicker and red:

    >>> x = np.arange(0,1.0,0.01)
    >>> y1 = np.sin(2*np.pi*x)
    >>> y2 = np.sin(4*np.pi*x)
    >>> lines = plt.plot(x, y1, x, y2)
    >>> plt.setp(lines, linewidth=2, color='r')

## get

get returns the value of a given attribute. You can use get to query the value of a single attribute:

    >>> plt.getp(line, 'linewidth')
        0.5

or all the attribute/value pairs:

    >>> plt.getp(line)
        aa = True
        alpha = 1.0
        antialiased = True
        c = b
        clip_on = True
        color = b
        ... long listing skipped ...

## Aliases

To reduce keystrokes in interactive mode, a number of properties have short aliases, e.g., ‘lw’ for ‘linewidth’ and ‘mec’ for ‘markeredgecolor’. When calling set or get in introspection mode, these properties will be listed as ‘fullname or aliasname’.

Out:

    Line setters
      agg_filter: unknown
      alpha: float (0.0 transparent through 1.0 opaque)
      animated: [True | False]
      antialiased or aa: [True | False]
      axes: an :class:`~matplotlib.axes.Axes` instance
      clip_box: a :class:`matplotlib.transforms.Bbox` instance
      clip_on: [True | False]
      clip_path: [ (:class:`~matplotlib.path.Path`, :class:`~matplotlib.transforms.Transform`) | :class:`~matplotlib.patches.Patch` | None ]
      color or c: any matplotlib color
      contains: a callable function
      dash_capstyle: ['butt' | 'round' | 'projecting']
      dash_joinstyle: ['miter' | 'round' | 'bevel']
      dashes: sequence of on/off ink in points
      drawstyle: ['default' | 'steps' | 'steps-pre' | 'steps-mid' | 'steps-post']
      figure: a :class:`matplotlib.figure.Figure` instance
      fillstyle: ['full' | 'left' | 'right' | 'bottom' | 'top' | 'none']
      gid: an id string
      label: string or anything printable with '%s' conversion.
      linestyle or ls: ['solid' | 'dashed', 'dashdot', 'dotted' | (offset, on-off-dash-seq) | ``'-'`` | ``'--'`` | ``'-.'`` | ``':'`` | ``'None'`` | ``' '`` | ``''``]
      linewidth or lw: float value in points
      marker: :mod:`A valid marker style <matplotlib.markers>`
      markeredgecolor or mec: any matplotlib color
      markeredgewidth or mew: float value in points
      markerfacecolor or mfc: any matplotlib color
      markerfacecoloralt or mfcalt: any matplotlib color
      markersize or ms: float
      markevery: [None | int | length-2 tuple of int | slice | list/array of int | float | length-2 tuple of float]
      path_effects: unknown
      picker: float distance in points or callable pick function ``fn(artist, event)``
      pickradius: float distance in points
      rasterized: [True | False | None]
      sketch_params: unknown
      snap: unknown
      solid_capstyle: ['butt' | 'round' |  'projecting']
      solid_joinstyle: ['miter' | 'round' | 'bevel']
      transform: a :class:`matplotlib.transforms.Transform` instance
      url: a url string
      visible: [True | False]
      xdata: 1D array
      ydata: 1D array
      zorder: any number
    Line getters
        agg_filter = None
        alpha = None
        animated = False
        antialiased or aa = True
        axes = Axes(0.125,0.11;0.775x0.77)
        children = []
        clip_box = TransformedBbox(Bbox([[0.0, 0.0], [1.0, 1.0]]), Co...
        clip_on = True
        clip_path = None
        color or c = r
        contains = None
        dash_capstyle = butt
        dash_joinstyle = round
        data = (array([ 0.  ,  0.01,  0.02,  0.03,  0.04,  0.05, ...
        drawstyle = default
        figure = Figure(640x480)
        fillstyle = full
        gid = None
        label = _line0
        linestyle or ls = --
        linewidth or lw = 2.0
        marker = None
        markeredgecolor or mec = r
        markeredgewidth or mew = 1.0
        markerfacecolor or mfc = r
        markerfacecoloralt or mfcalt = none
        markersize or ms = 6.0
        markevery = None
        path = Path(array([[  0.00000000e+00,   0.00000000e+00], ...
        path_effects = []
        picker = None
        pickradius = 5
        rasterized = None
        sketch_params = None
        snap = None
        solid_capstyle = projecting
        solid_joinstyle = round
        transform = CompositeGenericTransform(TransformWrapper(Blended...
        transformed_clip_path_and_affine = (None, None)
        url = None
        visible = True
        xdata = [ 0.    0.01  0.02  0.03  0.04  0.05]...
        xydata = [[ 0.          0.        ]  [ 0.01        0.062790...
        ydata = [ 0.          0.06279052  0.12533323  0.18738131  ...
        zorder = 2
    Rectangle setters
      agg_filter: unknown
      alpha: float or None
      animated: [True | False]
      antialiased or aa: [True | False]  or None for default
      axes: an :class:`~matplotlib.axes.Axes` instance
      capstyle: ['butt' | 'round' | 'projecting']
      clip_box: a :class:`matplotlib.transforms.Bbox` instance
      clip_on: [True | False]
      clip_path: [ (:class:`~matplotlib.path.Path`, :class:`~matplotlib.transforms.Transform`) | :class:`~matplotlib.patches.Patch` | None ]
      color: matplotlib color spec
      contains: a callable function
      edgecolor or ec: mpl color spec, None, 'none', or 'auto'
      facecolor or fc: mpl color spec, or None for default, or 'none' for no color
      figure: a :class:`matplotlib.figure.Figure` instance
      fill: [True | False]
      gid: an id string
      hatch: ['/' | '\\' | '|' | '-' | '+' | 'x' | 'o' | 'O' | '.' | '*']
      height: float
      joinstyle: ['miter' | 'round' | 'bevel']
      label: string or anything printable with '%s' conversion.
      linestyle or ls: ['solid' | 'dashed', 'dashdot', 'dotted' | (offset, on-off-dash-seq) | ``'-'`` | ``'--'`` | ``'-.'`` | ``':'`` | ``'None'`` | ``' '`` | ``''``]
      linewidth or lw: float or None for default
      path_effects: unknown
      picker: [None|float|boolean|callable]
      rasterized: [True | False | None]
      sketch_params: unknown
      snap: unknown
      transform: :class:`~matplotlib.transforms.Transform` instance
      url: a url string
      visible: [True | False]
      width: float
      x: float
      xy: 2-item sequence
      y: float
      zorder: any number
    Rectangle getters
        aa = True
        agg_filter = None
        alpha = None
        animated = False
        antialiased or aa = True
        axes = None
        bbox = Bbox(x0=0.0, y0=0.0, x1=1.0, y1=1.0)
        capstyle = butt
        children = []
        clip_box = None
        clip_on = True
        clip_path = None
        contains = None
        data_transform = BboxTransformTo(TransformedBbox(Bbox([[0.125, 0.10...
        ec = (0.0, 0.0, 0.0, 0.0)
        edgecolor or ec = (0.0, 0.0, 0.0, 0.0)
        extents = Bbox(x0=80.0, y0=52.8, x1=576.0, y1=422.4)
        facecolor or fc = (1.0, 1.0, 1.0, 1)
        fc = (1.0, 1.0, 1.0, 1)
        figure = Figure(640x480)
        fill = True
        gid = None
        hatch = None
        height = 1.0
        joinstyle = miter
        label =
        linestyle or ls = solid
        linewidth or lw = 0.0
        ls = solid
        lw = 0.0
        patch_transform = CompositeGenericTransform(BboxTransformTo(Bbox([[0...
        path = Path(array([[ 0.,  0.],        [ 1.,  0.],        ...
        path_effects = []
        picker = None
        rasterized = None
        sketch_params = None
        snap = None
        transform = CompositeGenericTransform(CompositeGenericTransfor...
        transformed_clip_path_and_affine = (None, None)
        url = None
        verts = [[  80.    52.8]  [ 576.    52.8]  [ 576.   422.4]...
        visible = True
        width = 1.0
        window_extent = Bbox(x0=80.0, y0=52.8, x1=576.0, y1=422.4)
        x = 0.0
        xy = (0.0, 0.0)
        y = 0.0
        zorder = 1
    Text setters
      agg_filter: unknown
      alpha: float (0.0 transparent through 1.0 opaque)
      animated: [True | False]
      axes: an :class:`~matplotlib.axes.Axes` instance
      backgroundcolor: any matplotlib color
      bbox: FancyBboxPatch prop dict
      clip_box: a :class:`matplotlib.transforms.Bbox` instance
      clip_on: [True | False]
      clip_path: [ (:class:`~matplotlib.path.Path`, :class:`~matplotlib.transforms.Transform`) | :class:`~matplotlib.patches.Patch` | None ]
      color: any matplotlib color
      contains: a callable function
      family or fontfamily or fontname or name: [FONTNAME | 'serif' | 'sans-serif' | 'cursive' | 'fantasy' | 'monospace' ]
      figure: a :class:`matplotlib.figure.Figure` instance
      fontproperties or font_properties: a :class:`matplotlib.font_manager.FontProperties` instance
      gid: an id string
      horizontalalignment or ha: [ 'center' | 'right' | 'left' ]
      label: string or anything printable with '%s' conversion.
      linespacing: float (multiple of font size)
      multialignment: ['left' | 'right' | 'center' ]
      path_effects: unknown
      picker: [None|float|boolean|callable]
      position: (x,y)
      rasterized: [True | False | None]
      rotation: [ angle in degrees | 'vertical' | 'horizontal' ]
      rotation_mode: unknown
      size or fontsize: [size in points | 'xx-small' | 'x-small' | 'small' | 'medium' | 'large' | 'x-large' | 'xx-large' ]
      sketch_params: unknown
      snap: unknown
      stretch or fontstretch: [a numeric value in range 0-1000 | 'ultra-condensed' | 'extra-condensed' | 'condensed' | 'semi-condensed' | 'normal' | 'semi-expanded' | 'expanded' | 'extra-expanded' | 'ultra-expanded' ]
      style or fontstyle: [ 'normal' | 'italic' | 'oblique']
      text: string or anything printable with '%s' conversion.
      transform: :class:`~matplotlib.transforms.Transform` instance
      url: a url string
      usetex: unknown
      variant or fontvariant: [ 'normal' | 'small-caps' ]
      verticalalignment or ma or va: [ 'center' | 'top' | 'bottom' | 'baseline' ]
      visible: [True | False]
      weight or fontweight: [a numeric value in range 0-1000 | 'ultralight' | 'light' | 'normal' | 'regular' | 'book' | 'medium' | 'roman' | 'semibold' | 'demibold' | 'demi' | 'bold' | 'heavy' | 'extra bold' | 'black' ]
      wrap: unknown
      x: float
      y: float
      zorder: any number
    Text getters
        agg_filter = None
        alpha = None
        animated = False
        axes = Axes(0.125,0.11;0.775x0.77)
        bbox_patch = None
        children = []
        clip_box = None
        clip_on = True
        clip_path = None
        color = k
        contains = None
        family or fontfamily or fontname or name = ['sans-serif']
        figure = Figure(640x480)
        fontproperties or font_properties = :family=sans-serif:style=normal:variant=normal:wei...
        gid = None
        horizontalalignment or ha = center
        label =
        name or fontname = DejaVu Sans
        path_effects = []
        picker = None
        position = (0.5, 1.0)
        prop_tup = (0.5, 1.0, 'Hi mom', 'k', 'baseline', 'center', 87...
        rasterized = None
        rotation = 0.0
        rotation_mode = None
        size or fontsize = 12.0
        sketch_params = None
        snap = None
        stretch or fontstretch = normal
        style or fontstyle = normal
        text = Hi mom
        transform = CompositeGenericTransform(BboxTransformTo(Transfor...
        transformed_clip_path_and_affine = (None, None)
        unitless_position = (0.5, 1.0)
        url = None
        usetex = False
        variant or fontvariant = normal
        verticalalignment or ma or va = baseline
        visible = True
        weight or fontweight = normal
        wrap = False
        zorder = 3

    from __future__ import print_function

    import matplotlib.pyplot as plt
    import numpy as np

    x = np.arange(0, 1.0, 0.01)
    y1 = np.sin(2*np.pi*x)
    y2 = np.sin(4*np.pi*x)
    lines = plt.plot(x, y1, x, y2)
    l1, l2 = lines
    plt.setp(lines, linestyle='--')       # set both to dashed
    plt.setp(l1, linewidth=2, color='r')  # line1 is thick and red
    plt.setp(l2, linewidth=1, color='g')  # line2 is thinner and green

    print('Line setters')
    plt.setp(l1)
    print('Line getters')
    plt.getp(l1)

    print('Rectangle setters')
    plt.setp(plt.gca().patch)
    print('Rectangle getters')
    plt.getp(plt.gca().patch)

    t = plt.title('Hi mom')
    print('Text setters')
    plt.setp(t)
    print('Text getters')
    plt.getp(t)

    plt.show()

Total running time of the script: ( 0 minutes 0.042 seconds)

Generated by Sphinx-Gallery