10 examples of 'matplotlib get axis limits' in Python

Every line of 'matplotlib get axis limits' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
638def set_limits(self, xlim=None, ylim=None, ax=None):
639 """
640 Set the display limits.
641
642 Parameters
643 ----------
644 xlim : tuple, optional
645 2-Tuple containing y-axis limits in km. None uses default limits.
646 ylim : tuple, optional
647 2-Tuple containing x-axis limits in km. None uses default limits.
648 ax : Axis
649 Axis to adjust. None will adjust the current axis.
650
651 """
652 if ax is None:
653 ax = plt.gca()
654 if ylim is not None:
655 ax.set_ylim(ylim)
656 if xlim is not None:
657 ax.set_xlim(xlim)
167def get_limits(self,axisId,figureId):
168 '''
169 Return axis limits.
170 '''
171 ax = self.mainFigureTemplates[figureId][axisId]['ax']
172 xLim = ax.get_xlim()
173 yLim = ax.get_ylim()
174 return [xLim,yLim]
104def setup_axis(X, Y, ax=None, fig=None, ylims=None):
105 """Setup axis, including timer for animation or snaps
106
107 Parameters
108 ----------
109 X :
110 space disctretization to get limits
111 Y :
112 solution to get limits
113 ax :
114 ax where to put everything, if None current axes are used (Default value = None)
115 fig :
116 fig where to put everything, if None current figure is used (Default value = None)
117 ylims :
118 custom ylims, if None y axis limits are calculated from Y (Default value = None)
119
120 Returns
121 -------
122 ax
123
124 fig
125
126 time_text
127 object to fill in text
128
129 """
130 if ax is None:
131 fig = plt.gcf()
132 ax = plt.gca()
133 if ylims is None:
134 lowery = nm.min(Y) - nm.min(Y) / 10
135 uppery = nm.max(Y) + nm.max(Y) / 10
136 else:
137 lowery = ylims[0]
138 uppery = ylims[1]
139 ax.set_ylim(lowery, uppery)
140 ax.set_xlim(X[0], X[-1])
141 time_text = ax.text(X[0] + nm.sign(X[0]) * X[0] / 10,
142 uppery - uppery / 10,
143 'empty', fontsize=15)
144 return ax, fig, time_text
405def setLimits(self, xmin, xmax, ymin, ymax, y2min=None, y2max=None):
406 """Set the limits of the X and Y axes at once.
407
408 :param float xmin: minimum bottom axis value
409 :param float xmax: maximum bottom axis value
410 :param float ymin: minimum left axis value
411 :param float ymax: maximum left axis value
412 :param float y2min: minimum right axis value
413 :param float y2max: maximum right axis value
414 """
415 self.__xLimits = xmin, xmax
416 self.__yLimits['left'] = ymin, ymax
417 if y2min is not None and y2max is not None:
418 self.__yLimits['right'] = y2min, y2max
872def GetYMaxRange(self):
873 yAxis = self._getYMaxRange()
874 if self.getLogScale()[1]:
875 yAxis = _Numeric.power(10, yAxis)
876 return yAxis
63@try_or_pass()
64def _get_ylim(self):
65 return self.ax.get_ylim()
328def get_yrange(self, yrange=[None, None],
329 xrange=[None, None], scale = 'linear'):
330# de = self.get_data_extent()
331 x, y, z = self._eval_xyz()
332 if x is None: return yrange
333 if y is None: return yrange
334 if scale == 'log': y = mask_negative(y)
335 return self._update_range(yrange, (np.nanmin(y), np.nanmax(y)))
23def _setup_axis(self, xmin, xmax, ymin, ymax):
24 self.y_axis = OrderedDict()
25 self.x_axis = OrderedDict()
26 for pos, y in enumerate(frange(ymin, ymax, (ymax-ymin)/float(self.size))):
27 self.y_axis[y] = pos
28 for pos, x in enumerate(frange(xmin, xmax, (xmax-xmin)/float(self.size))):
29 self.x_axis[x] = self.size- 1 - pos
54def update_ax2(ax1):
55 y1, y2 = ax1.get_ylim()
56 ax2.set_ylim(Tc(y1), Tc(y2))
57 ax2.figure.canvas.draw()
10def set_axes_equal(ax):
11 '''Make axes of 3D plot have equal scale so that spheres appear as spheres,
12 cubes as cubes, etc.. This is one possible solution to Matplotlib's
13 ax.set_aspect('equal') and ax.axis('equal') not working for 3D.
14
15 Input
16 ax: a matplotlib axis, e.g., as output from plt.gca().
17 '''
18
19 x_limits = ax.get_xlim3d()
20 y_limits = ax.get_ylim3d()
21 z_limits = ax.get_zlim3d()
22
23 x_range = abs(x_limits[1] - x_limits[0])
24 x_middle = np.mean(x_limits)
25 y_range = abs(y_limits[1] - y_limits[0])
26 y_middle = np.mean(y_limits)
27 z_range = abs(z_limits[1] - z_limits[0])
28 z_middle = np.mean(z_limits)
29
30 # The plot bounding box is a sphere in the sense of the infinity
31 # norm, hence I call half the max range the plot radius.
32 plot_radius = 0.5*max([x_range, y_range, z_range])
33
34 ax.set_xlim3d([x_middle - plot_radius, x_middle + plot_radius])
35 ax.set_ylim3d([y_middle - plot_radius, y_middle + plot_radius])
36 ax.set_zlim3d([z_middle - plot_radius, z_middle + plot_radius])

Related snippets