<divid="unreleased-message"> You are reading an old version of the documentation (v3.4.0). For the latest version see <ahref="https://matplotlib.org/stable/gallery/misc/set_and_get.html">https://matplotlib.org/stable/gallery/misc/set_and_get.html</a></div>
<pclass="last">Click <aclass="reference internal" href="#sphx-glr-download-gallery-misc-set-and-get-py"><spanclass="std std-ref">here</span></a> to download the full example code</p>
<spanid="sphx-glr-gallery-misc-set-and-get-py"></span><h1>Set and get properties<aclass="headerlink" href="#set-and-get-properties" title="Permalink to this headline">¶</a></h1>
<p>The pyplot interface allows you to use <codeclass="docutils literal notranslate"><spanclass="pre">setp</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">getp</span></code> to
set and get object properties respectively, as well as to do
introspection on the object.</p>
<divclass="section" id="setting-with-setp">
<h2>Setting with <codeclass="docutils literal notranslate"><spanclass="pre">setp</span></code><aclass="headerlink" href="#setting-with-setp" title="Permalink to this headline">¶</a></h2>
<p>To set the linestyle of a line to be dashed, you use <codeclass="docutils literal notranslate"><spanclass="pre">setp</span></code>:</p>
<h2>Getting with <codeclass="docutils literal notranslate"><spanclass="pre">getp</span></code><aclass="headerlink" href="#getting-with-getp" title="Permalink to this headline">¶</a></h2>
<p><codeclass="docutils literal notranslate"><spanclass="pre">getp</span></code> returns the value of a given attribute. You can use it to query
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
contains: unknown
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'}
path_effects: `.AbstractPathEffect`
picker: None or bool or float or callable
position: (float, float)
rasterized: bool
rotation: float or {'vertical', 'horizontal'}
<ahref="../../api/_as_gen/matplotlib.pyplot.setp.html#matplotlib.pyplot.setp" title="matplotlib.pyplot.setp" class="sphx-glr-backref-module-matplotlib-pyplot sphx-glr-backref-type-py-function"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">setp</span></a><spanclass="p">(</span><ahref="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><spanclass="n">lines</span></a><spanclass="p">,</span><spanclass="n">linestyle</span><spanclass="o">=</span><spanclass="s1">'--'</span><spanclass="p">)</span><spanclass="c1"># set both to dashed</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.setp.html#matplotlib.pyplot.setp" title="matplotlib.pyplot.setp" class="sphx-glr-backref-module-matplotlib-pyplot sphx-glr-backref-type-py-function"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">setp</span></a><spanclass="p">(</span><ahref="../../api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D" title="matplotlib.lines.Line2D" class="sphx-glr-backref-module-matplotlib-lines sphx-glr-backref-type-py-class sphx-glr-backref-instance"><spanclass="n">l1</span></a><spanclass="p">,</span><spanclass="n">linewidth</span><spanclass="o">=</span><spanclass="mi">2</span><spanclass="p">,</span><spanclass="n">color</span><spanclass="o">=</span><spanclass="s1">'r'</span><spanclass="p">)</span><spanclass="c1"># line1 is thick and red</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.setp.html#matplotlib.pyplot.setp" title="matplotlib.pyplot.setp" class="sphx-glr-backref-module-matplotlib-pyplot sphx-glr-backref-type-py-function"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">setp</span></a><spanclass="p">(</span><ahref="../../api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D" title="matplotlib.lines.Line2D" class="sphx-glr-backref-module-matplotlib-lines sphx-glr-backref-type-py-class sphx-glr-backref-instance"><spanclass="n">l2</span></a><spanclass="p">,</span><spanclass="n">linewidth</span><spanclass="o">=</span><spanclass="mi">1</span><spanclass="p">,</span><spanclass="n">color</span><spanclass="o">=</span><spanclass="s1">'g'</span><spanclass="p">)</span><spanclass="c1"># line2 is thinner and green</span>