Mat Plot Lib
Mat Plot Lib
January 7, 2024
Contents
1 Parts of a Figure 1
2 Sample codes 5
2.5 Scatter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.6 Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.7 Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.8 Fill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.10 Subplots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3 Patches 9
4 Backend 9
7 Axes 12
1 Parts of a Figure
1
Ho Chi Minh City International University Matplotlib Mini Guide
Industrial Systems Engineering Department Lecturer: Phan Nguyen Ky Phuc
• The top of the tree-like structure of matplotlib objects is the figure object.
• A figure can be seen as the container which contains one or more plots.
Figure
The whole figure. The figure keeps track of all the child Axes, a smattering of ’special’ artists (titles, figure
legends, etc), and the canvas. A figure can contain any number of Axes, but will typically have at least
one.The easiest way to create a new figure is with pyplot:
1 f i g = p l t . f i g u r e ( ) # an empty f i g u r e with no Axes
2 f i g , ax = p l t . s u b p l o t s ( ) # a f i g u r e with a s i n g l e Axes
3 f i g , a x s = p l t . s u b p l o t s ( 2 , 2 ) # a f i g u r e with a 2 x2 g r i d o f Axes
It’s convenient to create the axes together with the figure, but you can also add axes later on, allowing for
more complex axes layouts.
Axes
This is what you think of as ’a plot’, it is the region of the image with the data space. A given figure can
contain many Axes, but a given Axes object can only be in one Figure. The Axes contains two (or three in
the case of 3D) Axis objects (be aware of the difference between Axes and Axis) which take care of the data
limits. Each Axes can set:
• ax.set_ylim(), ax.set_xlim(),ax.set_xscale(’linear’),ax.set_yscale(’log’)
• ax.text(), ax.annotation()
• ax.add_patch(),
• ax.clear()
The Axes class and its member functions are the primary entry point to working with the OO interface.
Axis
Axis take care of setting the graph limits and generating the ticks (the marks on the axis) and ticklabels
(strings labeling the ticks). The location of the ticks is determined by a Locator object and the ticklabel
strings are formatted by a Formatter. The combination of the correct Locator and Formatter gives very fine
control over the tick locations and labels.
Artist
Basically everything you can see on the figure is an artist (even the Figure, Axes, and Axis objects). This
includes Text objects, Line2D objects, collections objects, Patch objects ... (you get the idea). When the
figure is rendered, all of the artists are drawn to the canvas. MostArtists are tied to an Axes; such an Artist
cannot be shared by multiple Axes, or moved from one to another.
1 x = np . l i n s p a c e ( 0 , 2 , 1 0 0 )
2 # Note t h a t even i n t h e OO−s t y l e , we u s e ‘ . p y p l o t . f i g u r e ‘ t o c r e a t e t h e f i g u r e .
3 f i g , ax = p l t . s u b p l o t s ( ) # C r e a t e a f i g u r e and an a x e s .
4 ax . p l o t ( x , x , l a b e l= ’ l i n e a r ’ ) # P l o t some data on t h e a x e s .
5 ax . p l o t ( x , x ∗ ∗ 2 , l a b e l= ’ q u a d r a t i c ’ ) # P l o t more data on t h e a x e s . . .
6 ax . p l o t ( x , x ∗ ∗ 3 , l a b e l= ’ c u b i c ’ ) # . . . and some more .
7 ax . s e t _ x l a b e l ( ’ x l a b e l ’ ) # Add an x−l a b e l t o t h e a x e s .
8 ax . s e t _ y l a b e l ( ’ y l a b e l ’ ) # Add a y−l a b e l t o t h e a x e s .
9 ax . s e t _ t i t l e ( " S im pl e P l o t " ) # Add a t i t l e t o t h e a x e s .
10 ax . l e g e n d ( ) # Add a l e g e n d .
Typically one finds oneself making the same plots over and over again, but with different data sets, which
leads to needing to write specialized functions to do the plotting. The recommended function signature is
something like:
1 d e f my_plotter ( ax , data1 , data2 , param_dict ) :
2 """
3 A h e l p e r f u n c t i o n t o make a graph
4 Parameters
5 −−−−−−−−−−
6 ax : Axes
7 The a x e s t o draw t o
8 data1 : a r r a y
9 The x data
10 data2 : a r r a y
11 The y data
12 param_dict : d i c t
13 D i c t i o n a r y o f kwargs t o p a s s t o ax . p l o t
14 Returns
15 −−−−−−−
16 out : l i s t
17 l i s t o f a r t i s t s added
18 """
19 out = ax . p l o t ( data1 , data2 , ∗∗ param_dict )
20 r e t u r n out
1 f i g , ( ax1 , ax2 ) = p l t . s u b p l o t s ( 1 , 2 )
2 my_plotter ( ax1 , data1 , data2 , { ’ marker ’ : ’ x ’ })
3 my_plotter ( ax2 , data3 , data4 , { ’ marker ’ : ’ o ’ })
Legends
The default legend behavior for axes attempts to find the location that covers the fewest data points
(loc=’best’). This can be a very expensive computation if there are lots of data points. In this case,
you may want to provide a specific location.
Using the fast style
The fast style can be used to automatically set simplification and chunking parameters to reasonable settings
to speed up plotting large amounts of data. It can be used simply by running:
1 im po rt m a t p l o t l i b . s t y l e a s m p l s t y l e
2 mplstyle . use ( ’ f a s t ’ )
It is very light weight, so it plays nicely with other styles, just make sure the fast style is applied last so that
other styles do not overwrite the settings:
1 m p l s t y l e . u s e ( [ ’ dark_background ’ , ’ g g p l o t ’ , ’ f a s t ’ ] )
2 Sample codes
4 f i g , ax=p l t . s u b p l o t s ( )
5 ax . bar ( x , y , c o l o r= ’ c ’ )
6 p l t . show ( )
1 from m a t p l o t l i b im po rt p y p l o t a s p l t
2 x= ( ’G1 ’ , ’G2 ’ , ’G3 ’ , ’G4 ’ , ’G5 ’ )
3 y1 = [ 1 , 3 , 4 , 2 , 7 ]
4 y2 = [ 1 , 2 , 2 , 1 , 1 ]
5 f i g , ax=p l t . s u b p l o t s ( )
6 ax . bar ( x , y1 , c o l o r= ’ c ’ , l a b e l= ’Men ’ )
7 ax . bar ( x , y2 , c o l o r= ’ y ’ , bottom=y1 , l a b e l= ’Women ’ )
8 ax . l e g e n d ( )
9 p l t . show ( )
1 from m a t p l o t l i b im po rt pyplot as p l t
2 x= ( ’G1 ’ , ’G2 ’ , ’G3 ’ , ’G4 ’ , ’G5 ’ )
3 y1 = [ 1 , 3 , 4 , 2 , 7 ]
4 y2 = [ 1 , 2 , 2 , 1 , 1 ]
5 f i g , ax=p l t . s u b p l o t s ( )
6 ax . barh ( x , y1 , c o l o r= ’ c ’ , l a b e l= ’Men ’ )
7 ax . barh ( x , y2 , c o l o r= ’ y ’ , l e f t =y1 , l a b e l= ’Women ’ )
8 ax . i n v e r t _ y a x i s ( )
9 ax . l e g e n d ( )
10 p l t . show ( )
2.5 Scatter
1 from m a t p l o t l i b im po rt p y p l o t a s p l t
2 from m a t p l o t l i b im po rt p y p l o t a s p l t
3 x= ( ’G1 ’ , ’G2 ’ , ’G3 ’ , ’G4 ’ , ’G5 ’ )
4 y1 = [ 1 , 3 , 4 , 2 , 7 ]
5 y2 = [ 1 , 2 , 2 , 1 , 1 ]
6 f i g , ax=p l t . s u b p l o t s ( )
7 ax . s c a t t e r ( x , y1 , c o l o r= ’ r ’ , marker= ’ x ’ , l a b e l= ’Women ’ )
8 ax . l e g e n d ( )
9 p l t . show ( )
2.6 Plot
1 from m a t p l o t l i b im po rt p y p l o t a s p l t
2 x= ( ’G1 ’ , ’G2 ’ , ’G3 ’ , ’G4 ’ , ’G5 ’ )
3 y1 = [ 1 , 3 , 4 , 2 , 7 ]
4 y2 = [ 1 , 2 , 2 , 1 , 1 ]
5 f i g , ax=p l t . s u b p l o t s ( )
6 ax . p l o t ( x , y1 , ’ r−< ’ , x , y2 , ’ b−−o ’ )
7 ax . l e g e n d ( )
8 p l t . show ( )
2.7 Table
1 from m a t p l o t l i b im po rt p y p l o t a s p l t
2 x= ( ’G1 ’ , ’G2 ’ , ’G3 ’ , ’G4 ’ , ’G5 ’ )
3 y1 = [ 1 , 3 , 4 , 2 , 7 ]
4 y2 = [ 1 , 2 , 2 , 1 , 1 ]
5 f i g , ax=p l t . s u b p l o t s ( )
6
2.8 Fill
1 from m a t p l o t l i b im po rt p y p l o t a s p l t
2 x= ( 1 , 2 , 7 , 0 , )
3 y1 = [ 1 , 3 , 4 , 0 ]
4 f i g , ax=p l t . s u b p l o t s ( )
5 ax . f i l l ( x , y1 , ’ r ’ )
6 p l t . show ( )
1 from m a t p l o t l i b im po rt p y p l o t a s p l t
2 x= ( 1 , 2 , 7 , 0 , )
3 y1 = [ 1 , 3 , 4 , 0 ]
4 f i g , ax=p l t . s u b p l o t s ( )
5 ax . s e t _ x l i m ( ( 0 , 5 ) )
6 ax . s e t _ y l i m ( ( 0 , 5 ) )
7 ax . t e x t ( 1 , 1 , ’ Good Weather ’ )
8 ax . a n n o t a t e ( ’ a n n o t a t e ’ , xy =(2 , 1 ) , x y t e x t =(3 , 4 ) , a r r o w p r o p s=d i c t ( f a c e c o l o r= ’ b ’ , s h r i n k =0 .0 5)
)
9 p l t . show ( )
2.10 Subplots
1 im po rt m a t p l o t l i b . p y p l o t a s p l t
2 im po rt numpy a s np
3 np . random . s e e d ( 1 9 6 8 0 8 0 1 )
4 data = np . random . randn ( 2 , 1 0 0 )
5 f i g , a x s = p l t . s u b p l o t s ( 2 , 2 , f i g s i z e =(5 , 5 ) )
6 a x s [ 0 , 0 ] . h i s t ( data [ 0 ] )
7 a x s [ 1 , 0 ] . s c a t t e r ( data [ 0 ] , data [ 1 ] )
8 a x s [ 0 , 1 ] . p l o t ( data [ 0 ] , data [ 1 ] )
9 a x s [ 1 , 1 ] . h i s t 2 d ( data [ 0 ] , data [ 1 ] )
10 p l t . show ( )
1 from m a t p l o t l i b im po rt p y p l o t a s p l t
2 p l t . s t y l e . u s e ( ’ dark_background ’ )
3 [ ’ S o l a r i z e _ L i g h t 2 ’ , ’ _ c l a s s i c _ t e s t _ p a t c h ’ , ’bmh ’ , ’ c l a s s i c ’ , ’ dark_background ’ , ’ f a s t ’ ,
4 , ’ f i v e t h i r t y e i g h t ’ , ’ g g p l o t ’ , ’ g r a y s c a l e ’ , ’ s e a b o r n ’ , ’ s e a b o r n −b r i g h t ’ , ’ s e a b o r n −c o l o r b l i n d ’
,
3 Patches
Figure 2: Matplotlib.patches
Example Code
1 from m a t p l o t l i b im po rt p y p l o t a s p l t
2 im po rt numpy a s np
3 im po rt m a t p l o t l i b . p a t c h e s a s p a t c h e s
4 f i g , ax=p l t . s u b p l o t s ( )
5 ax . s e t ( x l i m = [ 0 , 1 0 ] , y l i m = [ 0 , 1 0 ] )
6 r e c=p a t c h e s . R e c t a n g l e ( ( 0 , 0 ) , 4 , 5 , c o l o r= ’ r e d ’ )
7 c i r=p a t c h e s . C i r c l e ( ( 6 , 2 ) , 1 , c o l o r= ’ b l u e ’ )
8 ax . s e t _ a s p e c t ( ’ e q u a l ’ )
9 ax . add_patch ( r e c )
10 ax . add_patch ( c i r )
4 Backend
1 from m a t p l o t l i b . backends . backend_qt5agg imp ort FigureCanvasQTAgg a s FigureCanvas
2 from m a t p l o t l i b . backends . backend_qt5agg imp ort NavigationToolbar2QT a s N a v i g a t i o n T o o l b a r
3 im po rt m a t p l o t l i b . p y p l o t a s p l t
4 im po rt m a t p l o t l i b . p a t c h e s a s p a t c h e s
1 im po rt numpy a s np
2 im po rt m a t p l o t l i b . p y p l o t a s p l t
3
4 X = np . l i n s p a c e (−2 ∗ np . pi , 2 ∗ np . pi , 7 0 , e n d p o i n t=True )
5 F1 = np . s i n ( 2 ∗ X)
6 F2 = ( 2 ∗X∗∗5 + 4∗X∗∗4 − 4 . 8 ∗X∗∗3 + 1 . 2 ∗X∗∗2 + X + 1 ) ∗np . exp(−X∗ ∗ 2 )
7
8 f i g , ax = p l t . s u b p l o t s ( )
9
18 # moving l e f t s p i n e t o t h e r i g h t t o p o s i t i o n x == 0 :
19 ax . y a x i s . s e t _ t i c k s _ p o s i t i o n ( ’ l e f t ’ )
20 ax . s p i n e s [ ’ l e f t ’ ] . s e t _ p o s i t i o n ( ( ’ data ’ , 0 ) )
21
22 ax . p l o t (X, F1 , X, F2 )
23
24 p l t . show ( )
1 im po rt m a t p l o t l i b . p y p l o t a s p l t
2 f i g , ax = p l t . s u b p l o t s ( )
3 # set xticks locations :
4 ax . s e t _ x t i c k s ( [ 7 , 1 3 , 1 9 , 3 3 , 4 2 ] )
5 # set xticks labels :
6 ax . s e t _ x t i c k l a b e l s ( [ ’ B e r l i n ’ , ’ London ’ , ’ Hamburg ’ , ’ Toronto ’ ] )
1 im po rt numpy a s np
2 im po rt m a t p l o t l i b . p y p l o t a s p l t
3
4 X = np . l i n s p a c e (−2 ∗ np . pi , 2 ∗ np . pi , 7 0 , e n d p o i n t=True )
5 X = np . l i n s p a c e (−2 ∗ np . pi , 2 ∗ np . pi , 7 0 , e n d p o i n t=True )
6 F1 = np . s i n (X∗ ∗ 2 )
7 F2 = X ∗ np . s i n (X)
8
9 f i g , ax = p l t . s u b p l o t s ( )
10
21 ax . s e t _ x t i c k s ( [ − 6 . 2 8 , −3.14 , 3 . 1 4 , 6 . 2 8 ] )
22 ax . s e t _ y t i c k s ( [ − 3 , −1, 0 , +1 , 3 ] )
23 ax . p l o t (X, F1 )
24 ax . p l o t (X, F2 )
25
26 p l t . show ( )
7 f i g , ax = p l t . s u b p l o t s ( )
8 ax . p l o t (X, F1 , l a b e l= ’ F1 ’ )
9 ax . p l o t (X, F2 , l a b e l= ’ F2 ’ )
10 ax . l e g e n d ( l o c= ’ b e s t ’ )
11 loc_minimum = ( 0 , 0 )
12 glo_minimum = ( 5 , −5)
13 ax . a n n o t a t e ( " l o c a l minimum" , loc_minimum )
14 ax . a n n o t a t e ( " g l o b a l minimum" , glo_minimum )
15 p l t . show ( )
1 ax . a n n o t a t e ( " i n f l e c t i o n p o i n t " ,
2 xy =(0 , p ( 0 ) ) ,
3 x y t e x t =(−3, −30) ,
4 a r r o w p r o p s=d i c t ( f a c e c o l o r= ’ o r a n g e ’ , s h r i n k =0 .0 5) )
1 im po rt m a t p l o t l i b . p y p l o t a s p l t
2
4 d e f demo_con_style ( ax , c o n n e c t i o n s t y l e ) :
5 x1 , y1 = 0 . 3 , 0 . 2
6 x2 , y2 = 0 . 8 , 0 . 6
7
8 ax . p l o t ( [ x1 , x2 ] , [ y1 , y2 ] , " . " )
9 ax . a n n o t a t e ( " " ,
10 xy=(x1 , y1 ) , x y c o o r d s= ’ data ’ ,
11 x y t e x t =(x2 , y2 ) , t e x t c o o r d s= ’ data ’ ,
12 a r r o w p r o p s=d i c t ( a r r o w s t y l e="−>" , c o l o r=" 0 . 5 " ,
13 s hr in k A =5 , s h r i n k B =5 ,
14 patchA=None , patchB=None ,
15 c o n n e c t i o n s t y l e=c o n n e c t i o n s t y l e ) )
16
20
21 f i g , a x s = p l t . s u b p l o t s ( 3 , 5 , f i g s i z e =(8 , 4 . 8 ) )
22 demo_con_style ( a x s [ 0 , 0 ] , " a n g l e 3 , angleA =90 , angleB=0" )
23 demo_con_style ( a x s [ 1 , 0 ] , " a n g l e 3 , angleA =0 , angleB =90" )
24 demo_con_style ( a x s [ 0 , 1 ] , " a r c 3 , rad =0. " )
25 demo_con_style ( a x s [ 1 , 1 ] , " a r c 3 , rad =0.3 " )
26 demo_con_style ( a x s [ 2 , 1 ] , " a r c 3 , rad =−0.3" )
27 demo_con_style ( a x s [ 0 , 2 ] , " a n g l e , angleA =−90, angleB =180 , rad=0" )
28 demo_con_style ( a x s [ 1 , 2 ] , " a n g l e , angleA =−90, angleB =180 , rad=5" )
29 demo_con_style ( a x s [ 2 , 2 ] , " a n g l e , angleA =−90, angleB =10 , rad=5" )
30 demo_con_style ( a x s [ 0 , 3 ] , " arc , angleA =−90, angleB =0 ,armA=30 ,armB=30 , rad=0" )
31 demo_con_style ( a x s [ 1 , 3 ] , " arc , angleA =−90, angleB =0 ,armA=30 ,armB=30 , rad=5" )
32 demo_con_style ( a x s [ 2 , 3 ] , " arc , angleA =−90, angleB =0 ,armA=0 ,armB=40 , rad=0" )
33 demo_con_style ( a x s [ 0 , 4 ] , " bar , f r a c t i o n =0.3 " )
34 demo_con_style ( a x s [ 1 , 4 ] , " bar , f r a c t i o n =−0.3" )
35 demo_con_style ( a x s [ 2 , 4 ] , " bar , a n g l e =180 , f r a c t i o n =−0.2" )
36
37 f o r ax i n a x s . f l a t :
41 p l t . show ( )
7 Axes
1 #! / u s r / b i n / env python3
2 # −∗− c o d i n g : u t f −8 −∗−
3 """
4 C r e a t e d on Tue May 5 1 0 : 2 8 : 5 0 2020
5
6 @author : kyphuc
7 """
8
9 #! / u s r / b i n / env python3
10 # −∗− c o d i n g : u t f −8 −∗−
11 """
12 C r e a t e d on Tue May 5 1 0 : 2 8 : 5 0 2020
13
14 @author : kyphuc
15 """
16
17 im po rt s y s
18 im po rt pandas a s pd
19 from PyQt5 . QtWidgets im por t ∗
20 from m a t p l o t l i b . backends . backend_qt5agg imp ort FigureCanvasQTAgg a s FigureCanvas
21 from m a t p l o t l i b . backends . backend_qt5agg imp ort NavigationToolbar2QT a s N a v i g a t i o n T o o l b a r
22 im po rt m a t p l o t l i b . p y p l o t a s p l t
23 im po rt m a t p l o t l i b . p a t c h e s a s p a t c h e s
24 im po rt random
25
26 c l a s s F i g u r e ( QWidget ) :
27 d e f __init__ ( s e l f , ∗ ∗ kwargs ) :
28 s u p e r ( ) . __init__ ( )
29 s e l f . i t e m s=kwargs [ ’ i t e m s ’ ]
30
31 s e l f . _layout = QGridLayout ( )
32 s e l f . setWindowTitle ( ’ Figure ’ )
33
34 self . add_figure ( 1 , 0 , 9 , 1 0 )
35 self . add_toolbar ( 0 , 0 , 1 , 1 0 )
36 self . add_button ( ’ b t n C l o s e ’ , ’ C l o s e ’ , 1 0 , 9 , 1 , 1 , s e l f . f c n _ C l o s e )
37 self . add_button ( ’ b t n P l o t ’ , ’ P l o t ’ , 1 0 , 8 , 1 , 1 , s e l f . f c n _ P l o t )
38
39
53 s e l f . s e t L a y o u t ( s e l f . _layout )
54
55
56 s e l f . r e s i z e (1200 ,600)
57 s e l f . show ( )
58
97 def fcn_Close ( s e l f ) :
98 plt . close ()
99 s e l f . close ()
100 QApplication . quit ( )
101
147 d e f main ( ) :
148 itemList =[]
149 item1=Item ( i d =1 , b e g i n =0 , f i n i s h =1 , machine =1)
150 item2=Item ( i d =2 , b e g i n =3 , f i n i s h =4 , machine =2)
151 item3=Item ( i d =3 , b e g i n =5 , f i n i s h =8 , machine =2)
152 item4=Item ( i d =4 , b e g i n =10 , f i n i s h =15 , machine =3)
153 item5=Item ( i d =5 , b e g i n =16 , f i n i s h =17 , machine =4)
154 i t e m L i s t =[ item1 , item2 , item3 , item4 , item5 ]
155
156 app = Q A p p l i c a t i o n ( s y s . a r g v )
157 s c r e e n = F i g u r e ( i t e m s=i t e m L i s t )
158 s c r e e n . show ( )
159 s y s . e x i t ( app . exec_ ( ) )
160
John Hunter Excellence in Plotting Contest 2020 submissions are open! Entries are due June 1, 2020.
Version 3.2.1
Fork me on GitHub
Table of Contents
matplotlib.axes matplotlib.axes
Table of Contents The Axes class
Subplots
The Axes class Plotting
Subplots Basic
Spans
Plotting Spectral
Basic Statistics
Spans Binned
Spectral Contours
Array
Statistics
Unstructured Triangles
Binned Text and Annotations
Contours Fields
Array Clearing
Unstructured Triangles Appearance
Text and Annotations Property cycle
Fields Axis / limits
Axis Limits and direction
Clearing
Axis Labels, title, and
Appearance legend
Axis scales
Property cycle Autoscaling and margins
Aspect ratio
Axis / limits
Ticks and tick labels
Axis Limits and direction
Units
Axis Labels, title, and legend
Adding Artists
Axis scales
Twinning
Autoscaling and margins Axes Position
Aspect ratio Async/Event based
Ticks and tick labels Interactive
/
Units Children
Drawing
Adding Artists Bulk property manipulation
General Artist Properties
Twinning
Artist Methods
Axes Position Projection
Other
Async/Event based Inheritance
Interactive
Related Topics
Children
Documentation overview
Drawing API Overview
Bulk property manipulation Previous:
matplotlib.artist.ArtistInspector
General Artist Properties Next:
Artist Methods matplotlib.axes.SubplotBase
Projection
Show Page Source
Other
Inheritance
Bases: matplotlib.axes._base._AxesBase
The Axes contains most of the figure elements: Axis, Tick, Line2D, Text,
Polygon, etc., and sets the coordinate system.
viewLim : Bbox
**kwargs
Property Description
adjustable {'box', 'datalim'}
agg_filter a filter function, which
takes a (m, n, 3) float
array and a dpi value,
and returns a (m, n, 3)
array
alpha float or None
anchor 2-tuple of floats or {'C',
'SW', 'S', 'SE', ...}
animated bool
aspect {'auto', 'equal'} or num
autoscale_on bool
autoscalex_on bool
autoscaley_on bool
axes_locator Callable[[Axes,
Renderer], Bbox]
axisbelow bool or 'line'
clip_box Bbox
clip_on bool
clip_path Patch or (Path,
Transform) or None
/
Property Description
contains callable
facecolor color
fc color
figure Figure
frame_on bool
gid str
in_layout bool
label object
navigate bool
navigate_mode unknown
path_effects AbstractPathEffect
picker None or bool or float or
callable
position [left, bottom, width,
height] or Bbox
prop_cycle unknown
rasterization_zorder float or None
rasterized bool or None
sketch_params (scale: float, length:
float, randomness:
float)
snap bool or None
title str
transform Transform
url str
visible bool
xbound unknown
xlabel str
xlim (bottom: float, top:
float)
xmargin float greater than -0.5
xscale {"linear", "log",
"symlog", "logit", ...}
xticklabels List[str]
xticks unknown
ybound unknown
ylabel str
ylim (bottom: float, top:
float)
/
Property Description
ymargin float greater than -0.5
yscale {"linear", "log",
"symlog", "logit", ...}
yticklabels List[str]
yticks unknown
zorder float
Subplots
SubplotBase Base class for subplots, which are Axes instances with additional
methods to facilitate generating and manipulating a set of Axes
within a figure.
subplot_class_factory This makes a new class that inherits from SubplotBase and the
given axes_class (which is assumed to be a subclass of axes.Axes).
Plo ng
Basic
Axes.plot Plot y versus x as lines and/or markers.
Axes.loglog Make a plot with log scaling on both the x and y axis.
Spans
Axes.axhline Add a horizontal line across the axis.
Spectral
Axes.acorr Plot the autocorrelation of x.
Sta s cs
Axes.boxplot Make a box and whisker plot.
Binned
Axes.hexbin Make a 2D hexagonal binning plot of points x, y.
Contours
Axes.clabel Label a contour plot.
Array
Axes.imshow Display data as an image; i.e.
Unstructured Triangles
Axes.tripcolor Create a pseudocolor plot of an unstructured triangular grid.
Axes.indicate_inset_zoom Add an inset indicator rectangle to the axes based on the axis
limits for an inset_ax and draw connectors between inset_ax and
the rectangle.
Fields
Axes.barbs Plot a 2D field of barbs.
Clearing
Axes.cla Clear the current axes.
/
Axes.clear Clear the axes.
Appearance
Axes.axis Convenience method to get or set some axis properties.
Axes.set_axisbelow Set whether axis ticks and gridlines are above or below most artists.
Axes.get_axisbelow Get whether axis ticks and gridlines are above or below most artists.
Property cycle
Axes.set_prop_cycle Set the property cycle of the Axes.
Axis / limits
Axes.get_xaxis Return the XAxis instance.
Axes.set_xbound Set the lower and upper numerical bounds of the x-axis.
Axes.get_xbound Return the lower and upper x-axis bounds, in increasing order.
Axes.set_ybound Set the lower and upper numerical bounds of the y-axis. /
Axes.get_ybound Return the lower and upper y-axis bounds, in increasing order.
Axis scales
Axes.set_xscale Set the x-axis scale.
Axes.get_autoscale_on Get whether autoscaling is applied for both axes on plot commands
Axes.set_autoscalex_on Set whether autoscaling for the x-axis is applied on plot commands
Axes.get_autoscalex_on Get whether autoscaling for the x-axis is applied on plot commands
Axes.set_autoscaley_on Set whether autoscaling for the y-axis is applied on plot commands
Axes.get_autoscaley_on Get whether autoscaling for the y-axis is applied on plot commands
Aspect ra o
Axes.apply_aspect Adjust the Axes for a specified data aspect ratio.
/
Axes.set_aspect Set the aspect of the axis scaling, i.e.
Axes.get_aspect
Axes.set_adjustable Define which parameter the Axes will change to achieve a given aspect.
Axes.get_adjustable
Axes.xaxis_date Sets up x-axis ticks and labels that treat the x data as dates.
Axes.yaxis_date Sets up y-axis ticks and labels that treat the y data as dates.
Units
Axes.convert_xunits Convert x using the unit type of the xaxis.
Adding Ar sts
Axes.add_artist Add an Artist to the axes, and return the artist.
/
Axes.add_child_axes Add an AxesBase to the axes' children; return the child axes.
Twinning
Axes.twinx Create a twin Axes sharing the xaxis.
Axes.get_shared_x_axes Return a reference to the shared axes Grouper object for x axes.
Axes.get_shared_y_axes Return a reference to the shared axes Grouper object for y axes.
Axes Posi on
Axes.get_anchor Get the anchor location.
Async/Event based
Axes.stale Whether the artist is 'stale' and needs to be re-drawn for the output to
match the internal state of the artist.
Axes.add_callback Add a callback function that will be called whenever one of the
Artist's properties changes.
Interac ve
Axes.can_pan Return True if this axes supports any pan/zoom button
functionality.
Axes.can_zoom Return True if this axes supports the zoom box button functionality.
Axes.end_pan Called when a pan operation completes (when the mouse button is
up.)
Axes.mouseover If this property is set to True, the artist will be queried for custom
context information when the mouse cursor moves over it.
Axes.in_axes Return True if the given mouseevent (in display coords) is in the
Axes
Axes.get_contains Return the custom contains function of the artist if set, or None.
Axes.contains_point Return whether point (pair of pixel coordinates) is inside the axes
patch.
Children
Axes.get_children Return a list of the child Artists of this Artist.
Drawing
Axes.draw Draw everything (plot lines, axes, labels)
Axes.draw_artist This method can only be used after an initial draw which
caches the renderer.
Axes.redraw_in_frame This method can only be used after an initial draw which
caches the renderer.
Axes.get_renderer_cache
Axes.set_rasterization_zorder
Parameters:
Axes.get_window_extent Return the axes bounding box in display space; args and
kwargs are empty.
Axes.get_tightbbox Return the tight bounding box of the axes, including axis
and their decorators (xlabel, title, etc).
General Ar st Proper es
Axes.set_agg_filter Set the agg filter.
Axes.set_alpha Set the alpha value used for blending - not supported on all
backends.
Axes.get_alpha Return the alpha value used for blending - not supported on all
backends
Axes.get_label Return the label used for this artist in the legend.
Axes.get_path_effects
Ar st Methods
Axes.remove Remove the artist from the figure if possible.
Projec on
Methods used by Axis that must be overridden for non-rectilinear Axes.
Axes.name
Axes.get_data_ratio_log [Deprecated] Return the aspect ratio of the raw data in log
scale.
Axes.get_xaxis_text1_transform
Returns:
Axes.get_xaxis_text2_transform
Returns:
Axes.get_yaxis_text1_transform
Returns:
Axes.get_yaxis_text2_transform
Returns:
Other /
Axes.zorder
Inheritance
matplotlib artist Artist matplotlib axes base
© Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012 - 2018 The Matplotlib
development team.
Last updated on Mar 19, 2020. Created using Sphinx 2.2.2. Doc version v3.2.1-6-g9a2f0578f.