Related Articles

# Matplotlib.axes.Axes.get_facecolor() in Python

• Last Updated : 19 Apr, 2020

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute.

## matplotlib.axes.Axes.get_facecolor() Function

The Axes.get_facecolor() function in axes module of matplotlib library is used to get the facecolor of the Axes..

Syntax: Axes.get_facecolor(self)

Parameters: This method does not accept any parameters.

Returns:This method returns value of the facecolor of the Axes.

Below examples illustrate the matplotlib.axes.Axes.get_facecolor() function in matplotlib.axes:

Example 1:

 `# Implementation of matplotlib function``import` `numpy as np``import` `matplotlib.pyplot as plt``   ` `x ``=` `np.arange(``-``5``, ``5``, ``0.01``)``y1 ``=` `-``3` `*` `x``*``x ``+` `10` `*` `x ``+` `10``y2 ``=` `3` `*` `x``*``x ``+` `x``   ` `fig, ax ``=` `plt.subplots()``ax.plot(x, y1, x, y2, color ``=``'black'``)``ax.fill_between(x, y1, y2, where ``=` `y2 >y1,``                ``facecolor ``=``'green'``, alpha ``=` `0.8``)``ax.fill_between(x, y1, y2, where ``=` `y2 <``=` `y1,' ``               ``facecolor ``=``'black'``, alpha ``=` `0.8``)`` ` `x ``=` `ax.get_facecolor()``ax.text(``-``2``, ``80``, ``"Value of facecolor : "` `+``str``(x),``        ``style ``=``'italic'``, fontsize ``=` `10``, ``        ``color ``=``"green"``)``ax.set_title('matplotlib.axes.Axes.get_facecolor()\`` ``Example\n``', fontsize = 12, fontweight ='``bold')``plt.show()`

Output:

Example 2:

 `# Implementation of matplotlib function``import` `matplotlib.pyplot as plt``import` `numpy as np``  ` `data ``=` `((``30``, ``1000``), (``10``, ``28``), (``100``, ``30``),``        ``(``500``, ``800``), (``50``, ``10``))``  ` `dim ``=` `len``(data[``0``])``w ``=` `0.6``dimw ``=` `w ``/` `dim``  ` `fig, ax ``=` `plt.subplots()``x ``=` `np.arange(``len``(data))``for` `i ``in` `range``(``len``(data[``0``])):``    ``y ``=` `[d[i] ``for` `d ``in` `data]``    ``b ``=` `ax.bar(x ``+` `i ``*` `dimw, y, dimw, bottom ``=` `0.001``)``  ` `ax.set_xticks(x ``+` `dimw ``/` `2``)``ax.set_xticklabels(``map``(``str``, x))``ax.set_yscale(``'log'``)`` ` `x ``=` `ax.get_facecolor()``ax.text(``1``, ``2.3``*``(``10``*``*``3``), ``"Value of facecolor : "` `+``str``(x), ``        ``style ``=``'italic'``, fontsize ``=` `10``, ``        ``color ``=``"green"``)``ax.set_title('matplotlib.axes.Axes.get_facecolor()\`` ``Example\n``', fontsize = 12, fontweight ='``bold')``plt.show()`

Output:

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up