@@ -1322,6 +1322,12 @@ def __init__(self, x, y, dx, dy, width=0.001, length_includes_head=False,
1322
1322
"""
1323
1323
Parameters
1324
1324
----------
1325
+ x, y : float
1326
+ The x and y coordinates of the arrow base.
1327
+
1328
+ dx, dy : float
1329
+ The length of the arrow along x and y direction.
1330
+
1325
1331
width : float, default: 0.001
1326
1332
Width of full arrow tail.
1327
1333
@@ -1350,22 +1356,82 @@ def __init__(self, x, y, dx, dy, width=0.001, length_includes_head=False,
1350
1356
1351
1357
%(Patch_kwdoc)s
1352
1358
"""
1353
- if head_width is None :
1354
- head_width = 3 * width
1355
- if head_length is None :
1359
+ self ._x = x
1360
+ self ._y = y
1361
+ self ._dx = dx
1362
+ self ._dy = dy
1363
+ self ._width = width
1364
+ self ._length_includes_head = length_includes_head
1365
+ self ._head_width = head_width
1366
+ self ._head_length = head_length
1367
+ self ._shape = shape
1368
+ self ._overhang = overhang
1369
+ self ._head_starts_at_zero = head_starts_at_zero
1370
+ self ._make_verts ()
1371
+ super ().__init__ (self .verts , closed = True , ** kwargs )
1372
+
1373
+ def set_data (self , * , x = None , y = None , dx = None , dy = None , width = None ,
1374
+ head_width = None , head_length = None ):
1375
+ """
1376
+ Set `.FancyArrow` x, y, dx, dy, width, head_with, and head_length.
1377
+ Values left as None will not be updated.
1378
+
1379
+ Parameters
1380
+ ----------
1381
+ x, y : float or None, default: None
1382
+ The x and y coordinates of the arrow base.
1383
+
1384
+ dx, dy : float or None, default: None
1385
+ The length of the arrow along x and y direction.
1386
+
1387
+ width: float or None, default: None
1388
+ Width of full arrow tail.
1389
+
1390
+ head_width: float or None, default: None
1391
+ Total width of the full arrow head.
1392
+
1393
+ head_length: float or None, default: None
1394
+ Length of arrow head.
1395
+ """
1396
+ if x is not None :
1397
+ self ._x = x
1398
+ if y is not None :
1399
+ self ._y = y
1400
+ if dx is not None :
1401
+ self ._dx = dx
1402
+ if dy is not None :
1403
+ self ._dy = dy
1404
+ if width is not None :
1405
+ self ._width = width
1406
+ if head_width is not None :
1407
+ self ._head_width = head_width
1408
+ if head_length is not None :
1409
+ self ._head_length = head_length
1410
+ self ._make_verts ()
1411
+ self .set_xy (self .verts )
1412
+
1413
+ def _make_verts (self ):
1414
+ if self ._head_width is None :
1415
+ head_width = 3 * self ._width
1416
+ else :
1417
+ head_width = self ._head_width
1418
+ if self ._head_length is None :
1356
1419
head_length = 1.5 * head_width
1420
+ else :
1421
+ head_length = self ._head_length
1357
1422
1358
- distance = np .hypot (dx , dy )
1423
+ distance = np .hypot (self . _dx , self . _dy )
1359
1424
1360
- if length_includes_head :
1425
+ if self . _length_includes_head :
1361
1426
length = distance
1362
1427
else :
1363
1428
length = distance + head_length
1364
1429
if not length :
1365
- verts = np .empty ([0 , 2 ]) # display nothing if empty
1430
+ self . verts = np .empty ([0 , 2 ]) # display nothing if empty
1366
1431
else :
1367
1432
# start by drawing horizontal arrow, point at (0, 0)
1368
- hw , hl , hs , lw = head_width , head_length , overhang , width
1433
+ hw , hl = head_width , head_length
1434
+ hs , lw = self ._overhang , self ._width
1369
1435
left_half_arrow = np .array ([
1370
1436
[0.0 , 0.0 ], # tip
1371
1437
[- hl , - hw / 2 ], # leftmost
@@ -1374,36 +1440,37 @@ def __init__(self, x, y, dx, dy, width=0.001, length_includes_head=False,
1374
1440
[- length , 0 ],
1375
1441
])
1376
1442
# if we're not including the head, shift up by head length
1377
- if not length_includes_head :
1443
+ if not self . _length_includes_head :
1378
1444
left_half_arrow += [head_length , 0 ]
1379
1445
# if the head starts at 0, shift up by another head length
1380
- if head_starts_at_zero :
1446
+ if self . _head_starts_at_zero :
1381
1447
left_half_arrow += [head_length / 2 , 0 ]
1382
1448
# figure out the shape, and complete accordingly
1383
- if shape == 'left' :
1449
+ if self . _shape == 'left' :
1384
1450
coords = left_half_arrow
1385
1451
else :
1386
1452
right_half_arrow = left_half_arrow * [1 , - 1 ]
1387
- if shape == 'right' :
1453
+ if self . _shape == 'right' :
1388
1454
coords = right_half_arrow
1389
- elif shape == 'full' :
1455
+ elif self . _shape == 'full' :
1390
1456
# The half-arrows contain the midpoint of the stem,
1391
1457
# which we can omit from the full arrow. Including it
1392
1458
# twice caused a problem with xpdf.
1393
1459
coords = np .concatenate ([left_half_arrow [:- 1 ],
1394
1460
right_half_arrow [- 2 ::- 1 ]])
1395
1461
else :
1396
- raise ValueError ("Got unknown shape: %s" % shape )
1462
+ raise ValueError ("Got unknown shape: %s" % self . shape )
1397
1463
if distance != 0 :
1398
- cx = dx / distance
1399
- sx = dy / distance
1464
+ cx = self . _dx / distance
1465
+ sx = self . _dy / distance
1400
1466
else :
1401
1467
# Account for division by zero
1402
1468
cx , sx = 0 , 1
1403
1469
M = [[cx , sx ], [- sx , cx ]]
1404
- verts = np .dot (coords , M ) + (x + dx , y + dy )
1405
-
1406
- super ().__init__ (verts , closed = True , ** kwargs )
1470
+ self .verts = np .dot (coords , M ) + [
1471
+ self ._x + self ._dx ,
1472
+ self ._y + self ._dy ,
1473
+ ]
1407
1474
1408
1475
1409
1476
docstring .interpd .update (
0 commit comments