33Connectionstyle Demo
44====================
55
6+ When creating an annotation using `~.Axes.annotate`, the arrow shape can be
7+ controlled via the *connectionstyle* parameter of *arrowprops*. For further
8+ details see the description of `.FancyArrowPatch`.
69"""
710
811import matplotlib .pyplot as plt
912
1013
11- fig , axs = plt .subplots (3 , 5 , figsize = (8 , 4.8 ))
12- x1 , y1 = 0.3 , 0.3
13- x2 , y2 = 0.7 , 0.7
14-
15-
16- def demo_con_style (ax , connectionstyle , label = None ):
14+ def demo_con_style (ax , connectionstyle ):
1715 x1 , y1 = 0.3 , 0.2
1816 x2 , y2 = 0.8 , 0.6
1917
2018 ax .plot ([x1 , x2 ], [y1 , y2 ], "." )
2119 ax .annotate ("" ,
2220 xy = (x1 , y1 ), xycoords = 'data' ,
2321 xytext = (x2 , y2 ), textcoords = 'data' ,
24- arrowprops = dict (arrowstyle = "->" ,
25- color = "0.5" ,
22+ arrowprops = dict (arrowstyle = "->" , color = "0.5" ,
2623 shrinkA = 5 , shrinkB = 5 ,
27- patchA = None ,
28- patchB = None ,
24+ patchA = None , patchB = None ,
2925 connectionstyle = connectionstyle ,
3026 ),
3127 )
@@ -34,6 +30,7 @@ def demo_con_style(ax, connectionstyle, label=None):
3430 transform = ax .transAxes , ha = "left" , va = "top" )
3531
3632
33+ fig , axs = plt .subplots (3 , 5 , figsize = (8 , 4.8 ))
3734demo_con_style (axs [0 , 0 ], "angle3,angleA=90,angleB=0" )
3835demo_con_style (axs [1 , 0 ], "angle3,angleA=0,angleB=90" )
3936demo_con_style (axs [0 , 1 ], "arc3,rad=0." )
@@ -51,6 +48,20 @@ def demo_con_style(ax, connectionstyle, label=None):
5148
5249for ax in axs .flat :
5350 ax .set (xlim = (0 , 1 ), ylim = (0 , 1 ), xticks = [], yticks = [], aspect = 1 )
54- fig .tight_layout (pad = 0 )
51+ fig .tight_layout (pad = 0.2 )
5552
5653plt .show ()
54+
55+ #############################################################################
56+ #
57+ # ------------
58+ #
59+ # References
60+ # """"""""""
61+ #
62+ # The use of the following functions, methods, classes and modules is shown
63+ # in this example:
64+
65+ import matplotlib
66+ matplotlib .axes .Axes .annotate
67+ matplotlib .patches .FancyArrowPatch
0 commit comments