MCPcopy
hub / github.com/matplotlib/matplotlib / _set_lim

Method _set_lim

lib/matplotlib/axis.py:1242–1316  ·  view source on GitHub ↗

Set view limits. This method is a helper for the Axes ``set_xlim``, ``set_ylim``, and ``set_zlim`` methods. Parameters ---------- v0, v1 : float The view limits. (Passing *v0* as a (low, high) pair is not supported; normaliz

(self, v0, v1, *, emit=True, auto)

Source from the content-addressed store, hash-verified

1240 # and use it if it's available (else just use 0..1)
1241
1242 def _set_lim(self, v0, v1, *, emit=True, auto):
1243 """
1244 Set view limits.
1245
1246 This method is a helper for the Axes ``set_xlim``, ``set_ylim``, and
1247 ``set_zlim`` methods.
1248
1249 Parameters
1250 ----------
1251 v0, v1 : float
1252 The view limits. (Passing *v0* as a (low, high) pair is not
1253 supported; normalization must occur in the Axes setters.)
1254 emit : bool, default: True
1255 Whether to notify observers of limit change.
1256 auto : bool or None, default: False
1257 Whether to turn on autoscaling of the x-axis. True turns on, False
1258 turns off, None leaves unchanged.
1259 """
1260 name = self._get_axis_name()
1261
1262 self.axes._process_unit_info([(name, (v0, v1))], convert=False)
1263 v0 = self.axes._validate_converted_limits(v0, self.convert_units)
1264 v1 = self.axes._validate_converted_limits(v1, self.convert_units)
1265
1266 if v0 is None or v1 is None:
1267 # Axes init calls set_xlim(0, 1) before get_xlim() can be called,
1268 # so only grab the limits if we really need them.
1269 old0, old1 = self.get_view_interval()
1270 if v0 is None:
1271 v0 = old0
1272 if v1 is None:
1273 v1 = old1
1274
1275 if self.get_scale() == 'log' and (v0 <= 0 or v1 <= 0):
1276 # Axes init calls set_xlim(0, 1) before get_xlim() can be called,
1277 # so only grab the limits if we really need them.
1278 old0, old1 = self.get_view_interval()
1279 if v0 <= 0:
1280 _api.warn_external(f"Attempt to set non-positive {name}lim on "
1281 f"a log-scaled axis will be ignored.")
1282 v0 = old0
1283 if v1 <= 0:
1284 _api.warn_external(f"Attempt to set non-positive {name}lim on "
1285 f"a log-scaled axis will be ignored.")
1286 v1 = old1
1287 if v0 == v1:
1288 _api.warn_external(
1289 f"Attempting to set identical low and high {name}lims "
1290 f"makes transformation singular; automatically expanding.")
1291 reverse = bool(v0 > v1) # explicit cast needed for python3.8+np.bool_.
1292 v0, v1 = self.get_major_locator().nonsingular(v0, v1)
1293 v0, v1 = self.limit_range_for_scale(v0, v1)
1294 v0, v1 = sorted([v0, v1], reverse=bool(reverse))
1295
1296 self.set_view_interval(v0, v1, ignore=True)
1297 # Mark viewlims as no longer stale without triggering an autoscale.
1298 for ax in self._get_shared_axes():
1299 ax._stale_viewlims[name] = False

Callers 6

set_invertedMethod · 0.95
_set_lim3dMethod · 0.80
apply_callbackFunction · 0.80
__clearMethod · 0.80
set_xlimMethod · 0.80
set_ylimMethod · 0.80

Calls 14

_get_axis_nameMethod · 0.95
get_view_intervalMethod · 0.95
get_scaleMethod · 0.95
get_major_locatorMethod · 0.95
limit_range_for_scaleMethod · 0.95
set_view_intervalMethod · 0.95
_get_shared_axesMethod · 0.95
_set_autoscale_onMethod · 0.95
_process_unit_infoMethod · 0.80
processMethod · 0.80
nonsingularMethod · 0.45

Tested by

no test coverage detected