@@ -64,10 +64,10 @@ def setup():
64
64
'axes.edgecolor' : 'gray' ,
65
65
# Legend defaults – place legend outside axes on the right, no frame
66
66
'legend.loc' : 'center left' ,
67
- # 'legend.bbox_to_anchor': (1.02, 0.5), # Removed per instructions
68
67
'legend.frameon' : False ,
69
68
'legend.framealpha' : 0 ,
70
69
'legend.borderaxespad' : 0.0 ,
70
+ 'lines.scale_dashes' : False
71
71
}
72
72
73
73
# Update rcParams
@@ -1455,10 +1455,23 @@ def get_aspect(ax):
1455
1455
from scipy .interpolate import splprep , splev
1456
1456
from matplotlib .collections import PatchCollection
1457
1457
1458
- def vector_contours (fig ,ax ,mask , smooth_factor = 5 , color = 'r' , linewidth = 1 ):
1459
- pad = 1
1460
- msk = np .pad (mask ,pad ,mode = 'constant' )
1458
+ def vector_contours (fig ,ax ,mask , crop = None , smooth_factor = 5 , color = 'r' , linewidth = 1 ,
1459
+ y_offset = 0 , x_offset = 0 ,
1460
+ pad = 2 ,
1461
+ mode = 'constant'
1462
+ ):
1461
1463
1464
+ msk = np .pad (mask ,pad ,mode = 'edge' )
1465
+
1466
+ # msk = np.pad(mask,pad,mode=mode)
1467
+
1468
+ if crop is not None :
1469
+ # Crop the mask to the specified region
1470
+ # msk = msk[crop]
1471
+ y_offset += crop [0 ].start
1472
+ x_offset += crop [1 ].start
1473
+
1474
+ msk = np .pad (msk ,1 ,mode = 'constant' , constant_values = 0 )
1462
1475
1463
1476
# set up dimensions
1464
1477
dim = msk .ndim
@@ -1479,19 +1492,32 @@ def vector_contours(fig,ax,mask, smooth_factor=5, color = 'r', linewidth=1):
1479
1492
affinity_graph ,
1480
1493
coords ,
1481
1494
neighbors ,
1482
- cardinal_only = 1 )
1495
+ cardinal_only = True )
1483
1496
1484
1497
# List to hold patches
1485
1498
patches = []
1486
1499
for contour in contour_list :
1487
1500
if len (contour ) > 1 :
1488
- pts = np .stack ([c [contour ] for c in coords ]).T
1501
+ pts = np .stack ([c [contour ] for c in coords ]).T [:, ::- 1 ] # YX to XY
1502
+ pts += np .array ([x_offset ,y_offset ]) # Apply offsets
1489
1503
tck , u = splprep (pts .T , u = None , s = len (pts )/ smooth_factor , per = 1 )
1490
1504
u_new = np .linspace (u .min (), u .max (), len (pts ))
1491
1505
x_new , y_new = splev (u_new , tck , der = 0 )
1506
+
1492
1507
1493
1508
# Define the points of the polygon
1494
- points = np .column_stack ([y_new - pad , x_new - pad ])
1509
+ # points = np.column_stack([y_new-pad+y_offset, x_new-pad+x_offset])
1510
+ # points = np.column_stack([ x_new-pad+x_offset,y_new-pad+y_offset])
1511
+ # points = np.column_stack([ x_new-2*pad+x_offset,y_new-2*pad+y_offset])
1512
+ # points = np.column_stack([x_new-pad,y_new-pad])
1513
+ if isinstance (pad ,tuple ):
1514
+ # If pad is a tuple, apply it to x and y separately
1515
+ points = np .column_stack ([x_new - (pad [0 ][0 ]+ 1 ), y_new - (pad [1 ][0 ]+ 1 )])
1516
+ else :
1517
+ points = np .column_stack ([x_new - (pad + 1 ),y_new - (pad + 1 )])
1518
+
1519
+
1520
+
1495
1521
1496
1522
# Create a Path from the points
1497
1523
path = mpath .Path (points , closed = True )
@@ -1511,8 +1537,8 @@ def vector_contours(fig,ax,mask, smooth_factor=5, color = 'r', linewidth=1):
1511
1537
# Add the PatchCollection to the axis/axes
1512
1538
if isinstance (ax ,list ):
1513
1539
for a in ax :
1514
- patch_collection = PatchCollection (patches , match_original = True )
1540
+ patch_collection = PatchCollection (patches , match_original = True , snap = False )
1515
1541
a .add_collection (patch_collection )
1516
1542
else :
1517
- patch_collection = PatchCollection (patches , match_original = True )
1543
+ patch_collection = PatchCollection (patches , match_original = True , snap = False )
1518
1544
ax .add_collection (patch_collection )
0 commit comments