@@ -67,7 +67,8 @@ def default_units(value, axis):
67
67
return None
68
68
69
69
qc .convert = MagicMock (side_effect = convert )
70
- qc .axisinfo = MagicMock (side_effect = lambda u , a : munits .AxisInfo (label = u ))
70
+ qc .axisinfo = MagicMock (side_effect = lambda u , a :
71
+ munits .AxisInfo (label = u , default_limits = (0 , 100 )))
71
72
qc .default_units = MagicMock (side_effect = default_units )
72
73
return qc
73
74
@@ -219,3 +220,47 @@ def test_shared_axis_categorical():
219
220
ax2 .plot (d2 .keys (), d2 .values ())
220
221
ax1 .xaxis .set_units (UnitData (["c" , "d" ]))
221
222
assert "c" in ax2 .xaxis .get_units ()._mapping .keys ()
223
+
224
+
225
+ def test_empty_default_limits (quantity_converter ):
226
+ munits .registry [Quantity ] = quantity_converter
227
+ fig , ax1 = plt .subplots ()
228
+ ax1 .xaxis .update_units (Quantity ([10 ], "miles" ))
229
+ fig .draw_no_output ()
230
+ assert ax1 .get_xlim () == (0 , 100 )
231
+ ax1 .yaxis .update_units (Quantity ([10 ], "miles" ))
232
+ fig .draw_no_output ()
233
+ assert ax1 .get_ylim () == (0 , 100 )
234
+
235
+ fig , ax = plt .subplots ()
236
+ ax .axhline (30 )
237
+ ax .plot (Quantity (np .arange (0 , 3 ), "miles" ),
238
+ Quantity (np .arange (0 , 6 , 2 ), "feet" ))
239
+ fig .draw_no_output ()
240
+ assert ax .get_xlim () == (0 , 2 )
241
+ assert ax .get_ylim () == (0 , 30 )
242
+
243
+ fig , ax = plt .subplots ()
244
+ ax .axvline (30 )
245
+ ax .plot (Quantity (np .arange (0 , 3 ), "miles" ),
246
+ Quantity (np .arange (0 , 6 , 2 ), "feet" ))
247
+ fig .draw_no_output ()
248
+ assert ax .get_xlim () == (0 , 30 )
249
+ assert ax .get_ylim () == (0 , 4 )
250
+
251
+ fig , ax = plt .subplots ()
252
+ ax .xaxis .update_units (Quantity ([10 ], "miles" ))
253
+ ax .axhline (30 )
254
+ fig .draw_no_output ()
255
+ assert ax .get_xlim () == (0 , 100 )
256
+ assert ax .get_ylim () == (28.5 , 31.5 )
257
+
258
+ fig , ax = plt .subplots ()
259
+ ax .yaxis .update_units (Quantity ([10 ], "miles" ))
260
+ ax .axvline (30 )
261
+ fig .draw_no_output ()
262
+ assert ax .get_ylim () == (0 , 100 )
263
+ assert ax .get_xlim () == (28.5 , 31.5 )
264
+
265
+
266
+
0 commit comments