Wednesday, July 3, 2024
HomeLanguagesPythonMatplotlib.axes.Axes.get_facecolor() in Python

Matplotlib.axes.Axes.get_facecolor() in Python

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:

Ted Musemwa
As a software developer Iā€™m interested in the intersection of computational thinking and design thinking when solving human problems. As a professional I am guided by the principles of experiential learning; experience, reflect, conceptualise and experiment.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments