@@ -613,15 +613,46 @@ def set_picker(self, p):
613
613
self ._picker = p
614
614
615
615
def get_window_extent (self , renderer ):
616
- bbox = Bbox ([[0 , 0 ], [0 , 0 ]])
617
- trans_data_to_xy = self .get_transform ().transform
618
- bbox .update_from_data_xy (trans_data_to_xy (self .get_xydata ()),
619
- ignore = True )
620
- # correct for marker size, if any
616
+ """
617
+ Get bbox of Line2D in pixel space.
618
+
619
+ Notes
620
+ -----
621
+ Both the (stroked) line itself or any markers that have been placed
622
+ every ``markevery`` vertices along the line could be responsible for a
623
+ `Line2D`'s extents.
624
+ """
625
+ # marker contribution
621
626
if self ._marker :
622
- ms = (self ._markersize / 72.0 * self .figure .dpi ) * 0.5
623
- bbox = bbox .padded (ms )
624
- return bbox
627
+ pts_box = self ._marker .get_drawn_bbox (
628
+ self ._markersize , self ._markeredgewidth )
629
+ pix_box = pts_box .transformed (
630
+ Affine2D ().scale (self .figure .dpi / 72.0 ))
631
+ else :
632
+ pix_box = Bbox ([[0 , 0 ], [0 , 0 ]])
633
+ marker_bbox = Bbox .null ()
634
+ trans_data_to_xy = self .get_transform ().transform
635
+ xy = trans_data_to_xy (self .get_xydata ())
636
+ if self ._markevery :
637
+ xy = xy [::self ._markevery ]
638
+ bottom_left = xy + np .array ([pix_box .x0 , pix_box .y0 ])
639
+ marker_bbox .update_from_data_xy (bottom_left , ignore = True )
640
+ top_right = xy + np .array ([pix_box .x1 , pix_box .y1 ])
641
+ marker_bbox .update_from_data_xy (top_right , ignore = False )
642
+
643
+ # line's contribution
644
+ if self .is_dashed ():
645
+ cap = self ._dashcapstyle
646
+ join = self ._dashjoinstyle
647
+ else :
648
+ cap = self ._solidcapstyle
649
+ join = self ._solidjoinstyle
650
+ line_bbox = Bbox .null ()
651
+ path , affine = (self ._get_transformed_path ()
652
+ .get_transformed_path_and_affine ())
653
+ lw = self .get_linewidth () / 72.0 * self .figure .dpi
654
+ path_bbox = path .get_stroked_extents (lw , affine , join , cap )
655
+ return Bbox .union ([path_bbox , marker_bbox ])
625
656
626
657
@Artist .axes .setter
627
658
def axes (self , ax ):
0 commit comments