Matplotlib.axes.Axes.set_frame_on() 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.set_frame_on() Function
The Axes.set_frame_on() function in axes module of matplotlib library is used to set whether the axes rectangle patch is drawn or not.
Syntax: Axes.set_axis_on(self)
Parameters: This method accept only one parameters.
b: This parameter contains a boolean value and it is used for drawing the axes rectangle patch.
Returns:This method does not returns anything.
Note: If True is used, it does not effect any thing.
Below examples illustrate the matplotlib.axes.Axes.set_frame_on() function in matplotlib.axes:
Example 1:
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_frame_on( False )
ax.set_title( 'matplotlib.axes.Axes.set_frame_on() Example' )
plt.show()
|
Output:
Example 2:
import numpy as np
import matplotlib.pyplot as plt
x = np.arange( 16 )
y = np.sin(x / 3 )
fig, ax = plt.subplots()
ax.step(x, y + 2 , label = 'pre (default)' )
ax.plot(x, y + 2 , 'o--' , color = 'black' , alpha = 0.3 )
ax.step(x, y + 1 , where = 'mid' , label = 'mid' )
ax.plot(x, y + 1 , 'o--' , color = 'black' , alpha = 0.3 )
ax.step(x, y, where = 'post' , label = 'post' )
ax.plot(x, y, 'o--' , color = 'black' , alpha = 0.3 )
ax.grid(axis = 'x' , color = '0.95' )
ax.legend(title = 'Parameter where:' )
ax.set_frame_on( False )
ax.set_title( 'matplotlib.axes.Axes.set_frame_on() Example' )
plt.show()
|
Output:
Share your thoughts in the comments
Please Login to comment...