Repository: matplotlib/matplotlib

Issue:
[Bug]: Blank EPS output with legend and annotate
### Bug summary

When saving a figure containing `plt.legend` and `plt.annotate` to an EPS file, the EPS output is blank. Removing either of these produces a valid EPS file.

### Code for reproduction

```Python
from matplotlib import pyplot as plt


plt.plot([1, 2, 3], label="Line")
plt.legend(frameon=False)
plt.annotate("a", xy=(1, 1))
plt.savefig("test.eps")
```


### Actual outcome

![image](https://github.com/user-attachments/assets/e8717e9d-a341-45ed-91b7-7186259dd878)

<details>
<summary><code>test.eps</code></summary>

```ps
%!PS-Adobe-3.0 EPSF-3.0
%%LanguageLevel: 3
%%Title: test.eps
%%Creator: Matplotlib v3.9.2, https://matplotlib.org/
%%CreationDate: Fri Dec 13 18:53:27 2024
%%Orientation: portrait
%%BoundingBox: 0 0 461 346
%%HiResBoundingBox: 0.000000 0.000000 460.800000 345.600000
%%EndComments
%%BeginProlog
/mpldict 9 dict def
mpldict begin
/_d { bind def } bind def
/m { moveto } _d
/l { lineto } _d
/r { rlineto } _d
/c { curveto } _d
/cl { closepath } _d
/ce { closepath eofill } _d
/sc { setcachedevice } _d
%!PS-Adobe-3.0 Resource-Font
%%Creator: Converted from TrueType to Type 3 by Matplotlib.
10 dict begin
/FontName /DejaVuSans def
/PaintType 0 def
/FontMatrix [0.00048828125 0 0 0.00048828125 0 0] def
/FontBBox [-2090 -948 3673 2524] def
/FontType 3 def
/Encoding [/a /e /i /L /period /n /zero /one /two /three /five /seven] def
/CharStrings 13 dict dup begin
/.notdef 0 def
/a{1255 0 123 -29 1069 1147 sc
702 563 m
553 563 450 546 393 512 c
336 478 307 420 307 338 c
307 273 328 221 371 182 c
414 144 473 125 547 125 c
649 125 731 161 792 233 c
854 306 885 402 885 522 c
885 563 l
702 563 l

1069 639 m
1069 0 l
885 0 l
885 170 l
843 102 791 52 728 19 c
665 -13 589 -29 498 -29 c
383 -29 292 3 224 67 c
157 132 123 218 123 326 c
123 452 165 547 249 611 c
334 675 460 707 627 707 c
885 707 l
885 725 l
885 810 857 875 801 921 c
746 968 668 991 567 991 c
503 991 441 983 380 968 c
319 953 261 930 205 899 c
205 1069 l
272 1095 338 1114 401 1127 c
464 1140 526 1147 586 1147 c
748 1147 869 1105 949 1021 c
1029 937 1069 810 1069 639 c

ce} _d
/e{1260 0 113 -29 1151 1147 sc
1151 606 m
1151 516 l
305 516 l
313 389 351 293 419 226 c
488 160 583 127 705 127 c
776 127 844 136 910 153 c
977 170 1043 196 1108 231 c
1108 57 l
1042 29 974 8 905 -7 c
836 -22 765 -29 694 -29 c
515 -29 374 23 269 127 c
165 231 113 372 113 549 c
113 732 162 878 261 985 c
360 1093 494 1147 662 1147 c
813 1147 932 1098 1019 1001 c
1107 904 1151 773 1151 606 c

967 660 m
966 761 937 841 882 901 c
827 961 755 991 664 991 c
561 991 479 962 417 904 c
356 846 320 764 311 659 c
967 660 l

ce} _d
/i{569 0 193 0 377 1556 sc
193 1120 m
377 1120 l
377 0 l
193 0 l
193 1120 l

193 1556 m
377 1556 l
377 1323 l
193 1323 l
193 1556 l

ce} _d
/L{1141 0 201 0 1130 1493 sc
201 1493 m
403 1493 l
403 170 l
1130 170 l
1130 0 l
201 0 l
201 1493 l

ce} _d
/period{651 0 219 0 430 254 sc
219 254 m
430 254 l
430 0 l
219 0 l
219 254 l

ce} _d
/n{1298 0 186 0 1124 1147 sc
1124 676 m
1124 0 l
940 0 l
940 670 l
940 776 919 855 878 908 c
837 961 775 987 692 987 c
593 987 514 955 457 892 c
400 829 371 742 371 633 c
371 0 l
186 0 l
186 1120 l
371 1120 l
371 946 l
415 1013 467 1064 526 1097 c
586 1130 655 1147 733 1147 c
862 1147 959 1107 1025 1027 c
1091 948 1124 831 1124 676 c

ce} _d
/zero{1303 0 135 -29 1167 1520 sc
651 1360 m
547 1360 469 1309 416 1206 c
364 1104 338 950 338 745 c
338 540 364 387 416 284 c
469 182 547 131 651 131 c
756 131 834 182 886 284 c
939 387 965 540 965 745 c
965 950 939 1104 886 1206 c
834 1309 756 1360 651 1360 c

651 1520 m
818 1520 946 1454 1034 1321 c
1123 1189 1167 997 1167 745 c
1167 494 1123 302 1034 169 c
946 37 818 -29 651 -29 c
484 -29 356 37 267 169 c
179 302 135 494 135 745 c
135 997 179 1189 267 1321 c
356 1454 484 1520 651 1520 c

ce} _d
/one{1303 0 225 0 1114 1493 sc
254 170 m
584 170 l
584 1309 l
225 1237 l
225 1421 l
582 1493 l
784 1493 l
784 170 l
1114 170 l
1114 0 l
254 0 l
254 170 l

ce} _d
/two{1303 0 150 0 1098 1520 sc
393 170 m
1098 170 l
1098 0 l
150 0 l
150 170 l
227 249 331 356 463 489 c
596 623 679 709 713 748 c
778 821 823 882 848 932 c
874 983 887 1032 887 1081 c
887 1160 859 1225 803 1275 c
748 1325 675 1350 586 1350 c
523 1350 456 1339 385 1317 c
315 1295 240 1262 160 1217 c
160 1421 l
241 1454 317 1478 388 1495 c
459 1512 523 1520 582 1520 c
737 1520 860 1481 952 1404 c
1044 1327 1090 1223 1090 1094 c
1090 1033 1078 974 1055 919 c
1032 864 991 800 930 725 c
913 706 860 650 771 557 c
682 465 556 336 393 170 c

ce} _d
/three{1303 0 156 -29 1139 1520 sc
831 805 m
928 784 1003 741 1057 676 c
1112 611 1139 530 1139 434 c
1139 287 1088 173 987 92 c
886 11 742 -29 555 -29 c
492 -29 428 -23 361 -10 c
295 2 227 20 156 45 c
156 240 l
212 207 273 183 340 166 c
407 149 476 141 549 141 c
676 141 772 166 838 216 c
905 266 938 339 938 434 c
938 522 907 591 845 640 c
784 690 698 715 588 715 c
414 715 l
414 881 l
596 881 l
695 881 771 901 824 940 c
877 980 903 1037 903 1112 c
903 1189 876 1247 821 1288 c
767 1329 689 1350 588 1350 c
533 1350 473 1344 410 1332 c
347 1320 277 1301 201 1276 c
201 1456 l
278 1477 349 1493 416 1504 c
483 1515 547 1520 606 1520 c
759 1520 881 1485 970 1415 c
1059 1346 1104 1252 1104 1133 c
1104 1050 1080 980 1033 923 c
986 866 918 827 831 805 c

ce} _d
/five{1303 0 158 -29 1124 1493 sc
221 1493 m
1014 1493 l
1014 1323 l
406 1323 l
406 957 l
435 967 465 974 494 979 c
523 984 553 987 582 987 c
749 987 881 941 978 850 c
1075 759 1124 635 1124 479 c
1124 318 1074 193 974 104 c
874 15 733 -29 551 -29 c
488 -29 424 -24 359 -13 c
294 -2 227 14 158 35 c
158 238 l
218 205 280 181 344 165 c
408 149 476 141 547 141 c
662 141 754 171 821 232 c
888 293 922 375 922 479 c
922 583 888 665 821 726 c
754 787 662 817 547 817 c
493 817 439 811 385 799 c
332 787 277 768 221 743 c
221 1493 l

ce} _d
/seven{1303 0 168 0 1128 1493 sc
168 1493 m
1128 1493 l
1128 1407 l
586 0 l
375 0 l
885 1323 l
168 1323 l
168 1493 l

ce} _d
end readonly def

/BuildGlyph {
 exch begin
 CharStrings exch
 2 copy known not {pop /.notdef} if
 true 3 1 roll get exec
 end
} _d

/BuildChar {
 1 index /Encoding get exch get
 1 index /BuildGlyph get exec
} _d

FontName currentdict end definefont pop
end
%%EndProlog
mpldict begin
0 0 translate
0 0 460.8 345.6 rectclip

end
showpage
```
</details>

### Expected outcome


![image](https://github.com/user-attachments/assets/6461f8fb-b2a4-41f5-b143-4fb1c3cf7330)


<details>
<summary><code>test.eps</code></summary>

```ps
%!PS-Adobe-3.0 EPSF-3.0
%%LanguageLevel: 3
%%Title: test-good.eps
%%Creator: Matplotlib v3.9.2, https://matplotlib.org/
%%CreationDate: Fri Dec 13 18:57:11 2024
%%Orientation: portrait
%%BoundingBox: 0 0 461 346
%%HiResBoundingBox: 0.000000 0.000000 460.800000 345.600000
%%EndComments
%%BeginProlog
/mpldict 9 dict def
mpldict begin
/_d { bind def } bind def
/m { moveto } _d
/l { lineto } _d
/r { rlineto } _d
/c { curveto } _d
/cl { closepath } _d
/ce { closepath eofill } _d
/sc { setcachedevice } _d
%!PS-Adobe-3.0 Resource-Font
%%Creator: Converted from TrueType to Type 3 by Matplotlib.
10 dict begin
/FontName /DejaVuSans def
/PaintType 0 def
/FontMatrix [0.00048828125 0 0 0.00048828125 0 0] def
/FontBBox [-2090 -948 3673 2524] def
/FontType 3 def
/Encoding [/a /e /i /L /period /n /zero /one /two /three /five /seven] def
/CharStrings 13 dict dup begin
/.notdef 0 def
/a{1255 0 123 -29 1069 1147 sc
702 563 m
553 563 450 546 393 512 c
336 478 307 420 307 338 c
307 273 328 221 371 182 c
414 144 473 125 547 125 c
649 125 731 161 792 233 c
854 306 885 402 885 522 c
885 563 l
702 563 l

1069 639 m
1069 0 l
885 0 l
885 170 l
843 102 791 52 728 19 c
665 -13 589 -29 498 -29 c
383 -29 292 3 224 67 c
157 132 123 218 123 326 c
123 452 165 547 249 611 c
334 675 460 707 627 707 c
885 707 l
885 725 l
885 810 857 875 801 921 c
746 968 668 991 567 991 c
503 991 441 983 380 968 c
319 953 261 930 205 899 c
205 1069 l
272 1095 338 1114 401 1127 c
464 1140 526 1147 586 1147 c
748 1147 869 1105 949 1021 c
1029 937 1069 810 1069 639 c

ce} _d
/e{1260 0 113 -29 1151 1147 sc
1151 606 m
1151 516 l
305 516 l
313 389 351 293 419 226 c
488 160 583 127 705 127 c
776 127 844 136 910 153 c
977 170 1043 196 1108 231 c
1108 57 l
1042 29 974 8 905 -7 c
836 -22 765 -29 694 -29 c
515 -29 374 23 269 127 c
165 231 113 372 113 549 c
113 732 162 878 261 985 c
360 1093 494 1147 662 1147 c
813 1147 932 1098 1019 1001 c
1107 904 1151 773 1151 606 c

967 660 m
966 761 937 841 882 901 c
827 961 755 991 664 991 c
561 991 479 962 417 904 c
356 846 320 764 311 659 c
967 660 l

ce} _d
/i{569 0 193 0 377 1556 sc
193 1120 m
377 1120 l
377 0 l
193 0 l
193 1120 l

193 1556 m
377 1556 l
377 1323 l
193 1323 l
193 1556 l

ce} _d
/L{1141 0 201 0 1130 1493 sc
201 1493 m
403 1493 l
403 170 l
1130 170 l
1130 0 l
201 0 l
201 1493 l

ce} _d
/period{651 0 219 0 430 254 sc
219 254 m
430 254 l
430 0 l
219 0 l
219 254 l

ce} _d
/n{1298 0 186 0 1124 1147 sc
1124 676 m
1124 0 l
940 0 l
940 670 l
940 776 919 855 878 908 c
837 961 775 987 692 987 c
593 987 514 955 457 892 c
400 829 371 742 371 633 c
371 0 l
186 0 l
186 1120 l
371 1120 l
371 946 l
415 1013 467 1064 526 1097 c
586 1130 655 1147 733 1147 c
862 1147 959 1107 1025 1027 c
1091 948 1124 831 1124 676 c

ce} _d
/zero{1303 0 135 -29 1167 1520 sc
651 1360 m
547 1360 469 1309 416 1206 c
364 1104 338 950 338 745 c
338 540 364 387 416 284 c
469 182 547 131 651 131 c
756 131 834 182 886 284 c
939 387 965 540 965 745 c
965 950 939 1104 886 1206 c
834 1309 756 1360 651 1360 c

651 1520 m
818 1520 946 1454 1034 1321 c
1123 1189 1167 997 1167 745 c
1167 494 1123 302 1034 169 c
946 37 818 -29 651 -29 c
484 -29 356 37 267 169 c
179 302 135 494 135 745 c
135 997 179 1189 267 1321 c
356 1454 484 1520 651 1520 c

ce} _d
/one{1303 0 225 0 1114 1493 sc
254 170 m
584 170 l
584 1309 l
225 1237 l
225 1421 l
582 1493 l
784 1493 l
784 170 l
1114 170 l
1114 0 l
254 0 l
254 170 l

ce} _d
/two{1303 0 150 0 1098 1520 sc
393 170 m
1098 170 l
1098 0 l
150 0 l
150 170 l
227 249 331 356 463 489 c
596 623 679 709 713 748 c
778 821 823 882 848 932 c
874 983 887 1032 887 1081 c
887 1160 859 1225 803 1275 c
748 1325 675 1350 586 1350 c
523 1350 456 1339 385 1317 c
315 1295 240 1262 160 1217 c
160 1421 l
241 1454 317 1478 388 1495 c
459 1512 523 1520 582 1520 c
737 1520 860 1481 952 1404 c
1044 1327 1090 1223 1090 1094 c
1090 1033 1078 974 1055 919 c
1032 864 991 800 930 725 c
913 706 860 650 771 557 c
682 465 556 336 393 170 c

ce} _d
/three{1303 0 156 -29 1139 1520 sc
831 805 m
928 784 1003 741 1057 676 c
1112 611 1139 530 1139 434 c
1139 287 1088 173 987 92 c
886 11 742 -29 555 -29 c
492 -29 428 -23 361 -10 c
295 2 227 20 156 45 c
156 240 l
212 207 273 183 340 166 c
407 149 476 141 549 141 c
676 141 772 166 838 216 c
905 266 938 339 938 434 c
938 522 907 591 845 640 c
784 690 698 715 588 715 c
414 715 l
414 881 l
596 881 l
695 881 771 901 824 940 c
877 980 903 1037 903 1112 c
903 1189 876 1247 821 1288 c
767 1329 689 1350 588 1350 c
533 1350 473 1344 410 1332 c
347 1320 277 1301 201 1276 c
201 1456 l
278 1477 349 1493 416 1504 c
483 1515 547 1520 606 1520 c
759 1520 881 1485 970 1415 c
1059 1346 1104 1252 1104 1133 c
1104 1050 1080 980 1033 923 c
986 866 918 827 831 805 c

ce} _d
/five{1303 0 158 -29 1124 1493 sc
221 1493 m
1014 1493 l
1014 1323 l
406 1323 l
406 957 l
435 967 465 974 494 979 c
523 984 553 987 582 987 c
749 987 881 941 978 850 c
1075 759 1124 635 1124 479 c
1124 318 1074 193 974 104 c
874 15 733 -29 551 -29 c
488 -29 424 -24 359 -13 c
294 -2 227 14 158 35 c
158 238 l
218 205 280 181 344 165 c
408 149 476 141 547 141 c
662 141 754 171 821 232 c
888 293 922 375 922 479 c
922 583 888 665 821 726 c
754 787 662 817 547 817 c
493 817 439 811 385 799 c
332 787 277 768 221 743 c
221 1493 l

ce} _d
/seven{1303 0 168 0 1128 1493 sc
168 1493 m
1128 1493 l
1128 1407 l
586 0 l
375 0 l
885 1323 l
168 1323 l
168 1493 l

ce} _d
end readonly def

/BuildGlyph {
 exch begin
 CharStrings exch
 2 copy known not {pop /.notdef} if
 true 3 1 roll get exec
 end
} _d

/BuildChar {
 1 index /Encoding get exch get
 1 index /BuildGlyph get exec
} _d

FontName currentdict end definefont pop
end
%%EndProlog
mpldict begin
0 0 translate
0 0 460.8 345.6 rectclip
gsave
0 0 m
460.8 0 l
460.8 345.6 l
0 345.6 l
cl
1 setgray
fill
grestore
gsave
57.6 38.016 m
414.72 38.016 l
414.72 304.128 l
57.6 304.128 l
cl
1 setgray
fill
grestore
0.8 setlinewidth
1 setlinejoin
0 setlinecap
[] 0 setdash
0 setgray
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

0 0 m
0 -3.5 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
73.8327 38.016 o
grestore
/DejaVuSans 10.000 selectfont
gsave

62.6999 23.4222 translate
0 rotate
0 0 m /zero glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /zero glyphshow
15.9033 0 m /zero glyphshow
grestore
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

0 0 m
0 -3.5 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
114.415 38.016 o
grestore
/DejaVuSans 10.000 selectfont
gsave

103.282 23.4222 translate
0 rotate
0 0 m /zero glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /two glyphshow
15.9033 0 m /five glyphshow
grestore
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

0 0 m
0 -3.5 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
154.996 38.016 o
grestore
/DejaVuSans 10.000 selectfont
gsave

143.864 23.4222 translate
0 rotate
0 0 m /zero glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /five glyphshow
15.9033 0 m /zero glyphshow
grestore
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

0 0 m
0 -3.5 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
195.578 38.016 o
grestore
/DejaVuSans 10.000 selectfont
gsave

184.445 23.4222 translate
0 rotate
0 0 m /zero glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /seven glyphshow
15.9033 0 m /five glyphshow
grestore
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

0 0 m
0 -3.5 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
236.16 38.016 o
grestore
/DejaVuSans 10.000 selectfont
gsave

225.027 23.4222 translate
0 rotate
0 0 m /one glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /zero glyphshow
15.9033 0 m /zero glyphshow
grestore
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

0 0 m
0 -3.5 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
276.742 38.016 o
grestore
/DejaVuSans 10.000 selectfont
gsave

265.609 23.4222 translate
0 rotate
0 0 m /one glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /two glyphshow
15.9033 0 m /five glyphshow
grestore
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

0 0 m
0 -3.5 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
317.324 38.016 o
grestore
/DejaVuSans 10.000 selectfont
gsave

306.191 23.4222 translate
0 rotate
0 0 m /one glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /five glyphshow
15.9033 0 m /zero glyphshow
grestore
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

0 0 m
0 -3.5 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
357.905 38.016 o
grestore
/DejaVuSans 10.000 selectfont
gsave

346.773 23.4222 translate
0 rotate
0 0 m /one glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /seven glyphshow
15.9033 0 m /five glyphshow
grestore
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

0 0 m
0 -3.5 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
398.487 38.016 o
grestore
/DejaVuSans 10.000 selectfont
gsave

387.354 23.4222 translate
0 rotate
0 0 m /two glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /zero glyphshow
15.9033 0 m /zero glyphshow
grestore
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

-0 0 m
-3.5 0 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
57.6 50.112 o
grestore
/DejaVuSans 10.000 selectfont
gsave

28.3344 46.3151 translate
0 rotate
0 0 m /one glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /zero glyphshow
15.9033 0 m /zero glyphshow
grestore
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

-0 0 m
-3.5 0 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
57.6 80.352 o
grestore
/DejaVuSans 10.000 selectfont
gsave

28.3344 76.5551 translate
0 rotate
0 0 m /one glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /two glyphshow
15.9033 0 m /five glyphshow
grestore
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

-0 0 m
-3.5 0 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
57.6 110.592 o
grestore
/DejaVuSans 10.000 selectfont
gsave

28.3344 106.795 translate
0 rotate
0 0 m /one glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /five glyphshow
15.9033 0 m /zero glyphshow
grestore
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

-0 0 m
-3.5 0 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
57.6 140.832 o
grestore
/DejaVuSans 10.000 selectfont
gsave

28.3344 137.035 translate
0 rotate
0 0 m /one glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /seven glyphshow
15.9033 0 m /five glyphshow
grestore
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

-0 0 m
-3.5 0 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
57.6 171.072 o
grestore
/DejaVuSans 10.000 selectfont
gsave

28.3344 167.275 translate
0 rotate
0 0 m /two glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /zero glyphshow
15.9033 0 m /zero glyphshow
grestore
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

-0 0 m
-3.5 0 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
57.6 201.312 o
grestore
/DejaVuSans 10.000 selectfont
gsave

28.3344 197.515 translate
0 rotate
0 0 m /two glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /two glyphshow
15.9033 0 m /five glyphshow
grestore
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

-0 0 m
-3.5 0 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
57.6 231.552 o
grestore
/DejaVuSans 10.000 selectfont
gsave

28.3344 227.755 translate
0 rotate
0 0 m /two glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /five glyphshow
15.9033 0 m /zero glyphshow
grestore
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

-0 0 m
-3.5 0 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
57.6 261.792 o
grestore
/DejaVuSans 10.000 selectfont
gsave

28.3344 257.995 translate
0 rotate
0 0 m /two glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /seven glyphshow
15.9033 0 m /five glyphshow
grestore
gsave
/o {
gsave
newpath
translate
0.8 setlinewidth
1 setlinejoin

0 setlinecap

-0 0 m
-3.5 0 l

gsave
0 setgray
fill
grestore
stroke
grestore
} bind def
57.6 292.032 o
grestore
/DejaVuSans 10.000 selectfont
gsave

28.3344 288.235 translate
0 rotate
0 0 m /three glyphshow
6.3623 0 m /period glyphshow
9.54102 0 m /zero glyphshow
15.9033 0 m /zero glyphshow
grestore
1.5 setlinewidth
2 setlinecap
0.122 0.467 0.706 setrgbcolor
gsave
57.6 38.016 357.12 266.112 rectclip
73.832727 50.112 m
236.16 171.072 l
398.487273 292.032 l
stroke
grestore
0.8 setlinewidth
0 setlinejoin
0 setgray
gsave
57.6 38.016 m
57.6 304.128 l
stroke
grestore
gsave
414.72 38.016 m
414.72 304.128 l
stroke
grestore
gsave
57.6 38.016 m
414.72 38.016 l
stroke
grestore
gsave
57.6 304.128 m
414.72 304.128 l
stroke
grestore
/DejaVuSans 10.000 selectfont
gsave

236.16 50.112 translate
0 rotate
0 0 m /a glyphshow
grestore
1.5 setlinewidth
1 setlinejoin
0.122 0.467 0.706 setrgbcolor
gsave
66.6 291.03425 m
76.6 291.03425 l
86.6 291.03425 l
stroke
grestore
0 setgray
/DejaVuSans 10.000 selectfont
gsave

94.6 287.534 translate
0 rotate
0 0 m /L glyphshow
5.57129 0 m /i glyphshow
8.34961 0 m /n glyphshow
14.6875 0 m /e glyphshow
grestore

end
showpage
```
</details>

### Additional information

The EPS file is valid with `plt.text`:

```python
plt.plot([1, 2, 3], label="Line")
plt.legend(frameon=False)
plt.text(1, 1, s="a")
plt.savefig("test-good.eps")
plt.show()
```

### Operating system

Arch

### Matplotlib Version

3.9.3

### Matplotlib Backend

module://matplotlib_inline.backend_inline

### Python version

3.12.7

### Jupyter version

4.3.3

### Installation

pip


Discussion:
Thanks for the clear report @AllanChain.  I confirm that I have reproduced this with our `main` development branch.  Saving as png gives no problem so it does seem to be specific to ps/eps.
I can reproduce the problem with v3.9.0 but not with v3.8.4.
Bisects to #27469, and there is no problem if we manually set the legend location e.g.

```python
plt.legend(frameon=False, loc='upper left')
```



Patch:
diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py
index ace3f668e740..0c2dfc19705c 100644
--- a/lib/matplotlib/legend.py
+++ b/lib/matplotlib/legend.py
@@ -934,7 +934,7 @@ def _init_legend_box(self, handles, labels, markerfirst=True):
         self.texts = text_list
         self.legend_handles = handle_list
 
-    def _auto_legend_data(self):
+    def _auto_legend_data(self, renderer):
         """
         Return display coordinates for hit testing for "best" positioning.
 
@@ -969,7 +969,7 @@ def _auto_legend_data(self):
                 if len(hoffsets):
                     offsets.extend(transOffset.transform(hoffsets))
             elif isinstance(artist, Text):
-                bboxes.append(artist.get_window_extent())
+                bboxes.append(artist.get_window_extent(renderer))
 
         return bboxes, lines, offsets
 
@@ -1150,7 +1150,7 @@ def _find_best_position(self, width, height, renderer):
 
         start_time = time.perf_counter()
 
-        bboxes, lines, offsets = self._auto_legend_data()
+        bboxes, lines, offsets = self._auto_legend_data(renderer)
 
         bbox = Bbox.from_bounds(0, 0, width, height)
 


Test patch:
diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py
index 61892378bd03..67b10fb2a365 100644
--- a/lib/matplotlib/tests/test_legend.py
+++ b/lib/matplotlib/tests/test_legend.py
@@ -1,4 +1,5 @@
 import collections
+import io
 import itertools
 import platform
 import time
@@ -1427,6 +1428,21 @@ def test_legend_text():
     assert_allclose(leg_bboxes[1].bounds, leg_bboxes[0].bounds)
 
 
+def test_legend_annotate():
+    fig, ax = plt.subplots()
+
+    ax.plot([1, 2, 3], label="Line")
+    ax.annotate("a", xy=(1, 1))
+    ax.legend(loc=0)
+
+    with mock.patch.object(
+            fig, '_get_renderer', wraps=fig._get_renderer) as mocked_get_renderer:
+        fig.savefig(io.BytesIO())
+
+    # Finding the legend position should not require _get_renderer to be called
+    mocked_get_renderer.assert_not_called()
+
+
 def test_boxplot_legend_labels():
     # Test that legend entries are generated when passing `label`.
     np.random.seed(19680801)