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.broken_barh() Function
The Axes.broken_barh() function in axes module of matplotlib library is used to plot a horizontal sequence of rectangles.
Syntax:
Axes.broken_barh(self, xranges, yrange, *, data=None, **kwargs)Parameters: This method accept the following parameters that are described below:
- y: This parameter is the sequence of y coordinates of the bar.
- xranges: This parameter is the sequence of tuples (xmin, xwidth).It is the x-positions and extends of the rectangles.
- yrange: This parameter is the sequence of tuples (ymin, yheight).It is the y-positions and extends for all the rectangles.
Returns: This returns the following:
- BrokenBarHCollection:This returns the container with all the broken_barh.
Below examples illustrate the matplotlib.axes.Axes.broken_barh() function in matplotlib.axes:
Example #1:
# Implementation of matplotlib function import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.broken_barh([( 110 , 30 ), ( 150 , 10 )], ( 10 , 9 ), facecolors = 'tab:green' ) ax.set_xlabel( 'x' ) ax.set_ylabel( 'y' ) ax.grid( True ) ax.set_title('matplotlib.axes.Axes.\ broken_barh Example') plt.show() |
Output:
Example #2:
# Implementation of matplotlib function import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.broken_barh([( 110 , 30 ), ( 150 , 10 )], ( 10 , 9 ), facecolors = 'tab:green' ) ax.broken_barh([( 100 , 20 ), ( 130 , 10 )], ( 20 , 9 ), facecolors = ( 'tab:green' )) ax.set_ylim( 5 , 35 ) ax.set_xlim( 50 , 200 ) ax.set_xlabel( 'Learning Rate' ) ax.set_yticks([ 15 , 25 ]) ax.set_yticklabels([ 'Geeks1' , 'Geeks2' ]) ax.grid( True ) ax.annotate( 'Broken' , ( 125 , 25 ), xytext = ( 0.8 , 0.9 ), textcoords = 'axes fraction' , arrowprops = dict (facecolor = 'black' , shrink = 0.05 ), fontsize = 16 , horizontalalignment = 'right' , verticalalignment = 'top' ) ax.set_title( 'matplotlib.axes.Axes.broken_barh Example' ) plt.show() |
Output: