Open In App

Matplotlib.axes.Axes.set_facecolor() in Python

Last Updated : 19 Apr, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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.set_facecolor() Function

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

Syntax: Axes.set_facecolor(self, color)

Parameters: This method accept only one parameters.
color: This parameter accepts the color for the facecolor of the axes.

Returns:This method does not returns any value.

Below examples illustrate the matplotlib.axes.Axes.set_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)
   
ax.set_facecolor('# eafff5')
ax.set_title('matplotlib.axes.Axes.get_facecolor() \
Example\n', fontsize = 12, fontweight ='bold')
plt.show()


Output:

Example 2:




# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
     
t = np.linspace(0.0, 2.0, 201)
s = np.sin(2 * np.pi * t)
  
fig, ax = plt.subplots()
ax.set_facecolor('# E56B51')
ax.set_xlabel('x-axis')
ax.set_ylabel('y-axis')
ax.plot(t, s, )
ax.set_title('matplotlib.axes.Axes.get_facecolor()\
 Example\n', fontsize = 12, fontweight ='bold')
plt.show()


Output:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads