File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -168,13 +168,18 @@ def _update_anchors(self):
168
168
xdata = xdata [mask ]
169
169
ydata = ydata [mask ]
170
170
171
- # Find the first line segment surrounding x
172
- for i , (xa , xb ) in enumerate (zip (xdata [:- 1 ], xdata [1 :])):
173
- if min (xa , xb ) <= x <= max (xa , xb ):
174
- ya , yb = ydata [i ], ydata [i + 1 ]
175
- break
171
+ # If the valid data is a single point, then just use that point
172
+ if len (xdata ) == 1 :
173
+ xa , xb = xdata [0 ], xdata [0 ]
174
+ ya , yb = ydata [0 ], ydata [0 ]
176
175
else :
177
- raise ValueError ("x label location is outside data range!" )
176
+ # Find the first line segment surrounding x
177
+ for i , (xa , xb ) in enumerate (zip (xdata [:- 1 ], xdata [1 :])):
178
+ if min (xa , xb ) <= x <= max (xa , xb ):
179
+ ya , yb = ydata [i ], ydata [i + 1 ]
180
+ break
181
+ else :
182
+ raise ValueError ("x label location is outside data range!" )
178
183
179
184
# Interpolate y position of label, (interp needs sorted data)
180
185
if xa != xb :
Original file line number Diff line number Diff line change @@ -361,6 +361,13 @@ def test_auto_layout(setup_mpl):
361
361
return plt .gcf ()
362
362
363
363
364
+ @pytest .mark .mpl_image_compare
365
+ def test_single_point_line (setup_mpl ):
366
+ plt .plot (1 , 1 , label = "x" )
367
+ labelLines (plt .gca ().get_lines ())
368
+ return plt .gcf ()
369
+
370
+
364
371
def test_warning_out_of_range ():
365
372
X = [0 , 1 ]
366
373
Y = [0 , 1 ]
You can’t perform that action at this time.
0 commit comments