本文整理汇总了Python中axes.Axes类的典型用法代码示例。如果您正苦于以下问题:Python Axes类的具体用法?Python Axes怎么用?Python Axes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Axes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, fig, rect=[0.0, 0.0, 1.0, 1.0], *args, **kwargs):
self.fig = fig
azim = cbook.popd(kwargs, 'azim', -60)
elev = cbook.popd(kwargs, 'elev', 30)
self.xy_viewLim = unit_bbox()
self.zz_viewLim = unit_bbox()
self.xy_dataLim = unit_bbox()
self.zz_dataLim = unit_bbox()
# inihibit autoscale_view until the axises are defined
# they can't be defined until Axes.__init__ has been called
self._ready = 0
Axes.__init__(self, self.fig, rect,
frameon=True,
xticks=[], yticks=[], *args, **kwargs)
self.M = None
self._ready = 1
self.view_init(elev, azim)
self.mouse_init()
self.create_axes()
self.set_top_view()
#self.axesPatch.set_edgecolor((1,0,0,0))
self.axesPatch.set_linewidth(0)
#self.axesPatch.set_facecolor((0,0,0,0))
self.fig.add_axes(self)
示例2: _get_axes
def _get_axes(*arrays):
""" find list of axes from a list of axis-aligned DimArray objects
"""
dims = get_dims(*arrays) # all dimensions present in objects
axes = Axes()
for dim in dims:
common_axis = None
for o in arrays:
# skip missing dimensions
if dim not in o.dims: continue
axis = o.axes[dim]
# update values
if common_axis is None or (common_axis.size==1 and axis.size > 1):
common_axis = axis
# Test alignment for non-singleton axes
if not (axis.size == 1 or np.all(axis.values==common_axis.values)):
raise ValueError("axes are not aligned")
# append new axis
axes.append(common_axis)
return axes
示例3: empty
def empty(axes=None, dims=None, shape=None, dtype=float):
""" Initialize an empty array
axes and dims have the same meaning as DimArray's initializer
shape, optional: can be provided in combination with `dims`
if `axes=` is omitted.
>>> a = empty([('time',[2000,2001]),('items',['a','b','c'])])
>>> a.fill(3)
>>> a
dimarray: 6 non-null elements (0 null)
dimensions: 'time', 'items'
0 / time (2): 2000 to 2001
1 / items (3): a to c
array([[ 3., 3., 3.],
[ 3., 3., 3.]])
>>> b = empty(dims=('time','items'), shape=(2, 3))
See also:
---------
empty_like, ones, zeros, nans
"""
axes = Axes._init(axes, dims=dims, shape=shape)
if shape is None:
shape = [ax.size for ax in axes]
values = np.empty(shape, dtype=dtype)
return DimArray(values, axes=axes, dims=dims)
示例4: set_w_ylim
def set_w_ylim(self, *args, **kwargs):
gl,self.get_ylim = self.get_ylim,self.get_w_ylim
vl,self.viewLim = self.viewLim,self.xy_viewLim
vmin,vmax = Axes.set_ylim(self, *args, **kwargs)
self.get_ylim = gl
self.viewLim = vl
return vmin,vmax
示例5: __init__
def __init__(self, *args, **kwargs):
"""
Initializes plot properties.
"""
# data points
if len(args) < 1:
self.xvalues = asarray([])
self.yvalues = asarray([])
elif len(args) < 2:
self.yvalues = asarray(args[0]).flatten()
self.xvalues = arange(1, len(self.yvalues) + 1)
else:
self.xvalues = asarray(args[0]).flatten()
self.yvalues = asarray(args[1]).flatten()
# line style
self.line_style = kwargs.get('line_style', None)
self.line_width = kwargs.get('line_width', None)
self.opacity = kwargs.get('opacity', None)
self.color = kwargs.get('color', None)
self.fill = kwargs.get('fill', False)
# marker style
self.marker = kwargs.get('marker', None)
self.marker_size = kwargs.get('marker_size', None)
self.marker_edge_color = kwargs.get('marker_edge_color', None)
self.marker_face_color = kwargs.get('marker_face_color', None)
self.marker_opacity = kwargs.get('marker_opacity', None)
# error bars
self.xvalues_error = asarray(kwargs.get('xvalues_error', [])).flatten()
self.yvalues_error = asarray(kwargs.get('yvalues_error', [])).flatten()
self.error_marker = kwargs.get('error_marker', None)
self.error_color = kwargs.get('error_color', None)
self.error_style = kwargs.get('error_style', None)
self.error_width = kwargs.get('error_width', None)
# comb (or stem) plots
self.ycomb = kwargs.get('ycomb', False)
self.xcomb = kwargs.get('xcomb', False)
self.closed = kwargs.get('closed', False)
self.const_plot = kwargs.get('const_plot', False)
# legend entry for this plot
self.legend_entry = kwargs.get('legend_entry', None)
# custom plot options
self.pgf_options = kwargs.get('pgf_options', [])
# catch common mistakes
if not isinstance(self.pgf_options, list):
raise TypeError('pgf_options should be a list.')
# add plot to axes
self.axes = kwargs.get('axis', Axes.gca())
self.axes.children.append(self)
示例6: scatter3D
def scatter3D(self, xs, ys, zs, *args, **kwargs):
had_data = self.has_data()
patches = Axes.scatter(self,xs,ys,*args,**kwargs)
patches = art3d.wrap_patch(patches, zs)
#
self.auto_scale_xyz(xs,ys,zs, had_data)
return patches
示例7: __init__
def __init__(self, *args, **kwargs):
if len(args) == 1:
self.xvalues, self.yvalues = meshgrid(
arange(args[0].shape[0]),
arange(args[0].shape[1]))
self.zvalues = args[0]
else:
self.xvalues, self.yvalues, self.zvalues = args
# shading
self.shading = kwargs.get('shading', None)
# custom plot options
self.pgf_options = kwargs.get('pgf_options', [])
# catch common mistakes
if not isinstance(self.pgf_options, list):
raise TypeError('pgf_options should be a list.')
# add plot to axis
self.axes = kwargs.get('axes', Axes.gca())
self.axes.children.append(self)
# adjust default behavior for 3D plots
self.axes.axis_on_top = False
self.axes.xlabel_near_ticks = False
self.axes.ylabel_near_ticks = False
self.axes.zlabel_near_ticks = False
示例8: from_pandas
def from_pandas(cls, data, dims=None):
""" Initialize a DimArray from pandas
data: pandas object (Series, DataFrame, Panel, Panel4D)
dims, optional: dimension (axis) names, otherwise look at ax.name for ax in data.axes
>>> import pandas as pd
>>> s = pd.Series([3,5,6], index=['a','b','c'])
>>> s.index.name = 'dim0'
>>> DimArray.from_pandas(s)
dimarray: 3 non-null elements (0 null)
dimensions: 'dim0'
0 / dim0 (3): a to c
array([3, 5, 6])
Also work with Multi-Index
>>> panel = pd.Panel(np.arange(2*3*4).reshape(2,3,4))
>>> b = panel.to_frame() # pandas' method to convert Panel to DataFrame via MultiIndex
>>> DimArray.from_pandas(b) # doctest: +SKIP
dimarray: 24 non-null elements (0 null)
dimensions: 'major,minor', 'x1'
0 / major,minor (12): (0, 0) to (2, 3)
1 / x1 (2): 0 to 1
...
"""
try:
import pandas as pd
except ImportError:
raise ImportError("pandas module is required to use this method")
axisnames = []
axes = []
for i, ax in enumerate(data.axes):
# axis name
name = ax.name
if dims is not None: name = dims[i]
if name is None: name = 'x%i'% (i)
# Multi-Index: make a Grouped Axis object
if isinstance(ax, pd.MultiIndex):
# level names
names = ax.names
for j, nm in enumerate(names):
if nm is None:
names[j] = '%s_%i'%(name,j)
miaxes = Axes.from_arrays(ax.levels, dims=names)
axis = GroupedAxis(*miaxes)
# Index: Make a simple Axis
else:
axis = Axis(ax.values, name)
axes.append(axis)
#axisnames, axes = zip(*[(ax.name, ax.values) for ax in data.axes])
return cls(data.values, axes=axes)
示例9: draw
def draw(self, renderer):
# draw the background patch
self.axesPatch.draw(renderer)
self._frameon = False
# add the projection matrix to the renderer
self.M = self.get_proj()
renderer.M = self.M
renderer.vvec = self.vvec
renderer.eye = self.eye
renderer.get_axis_position = self.get_axis_position
#self.set_top_view()
self.w_xaxis.draw(renderer)
self.w_yaxis.draw(renderer)
self.w_zaxis.draw(renderer)
Axes.draw(self, renderer)
示例10: plot3D
def plot3D(self, xs, ys, zs, *args, **kwargs):
had_data = self.has_data()
lines = Axes.plot(self, xs,ys, *args, **kwargs)
if len(lines)==1:
line = lines[0]
art3d.wrap_line(line, zs)
#
self.auto_scale_xyz(xs,ys,zs, had_data)
return lines
示例11: __init__
def __init__(self, *args, **kwargs):
# legend entries
self.legend_entries = args
# legend properties
self.at = kwargs.get('at', None)
self.anchor = kwargs.get('anchor', None)
self.location = kwargs.get('location', None)
self.align = kwargs.get('align', 'left')
self.box = kwargs.get('box', True)
self.font_size = kwargs.get('font_size', None)
# assign legend to axis
self.axes = kwargs.get('axes', Axes.gca())
self.axes.legend = self
示例12: __init__
def __init__(self, image, **kwargs):
"""
@type image: string/array_like/PIL Image
@param image: a filepath or an image in grayscale or RGB
@param vmin:
@param vmax:
@param cmap:
"""
self.cmap = kwargs.get('cmap', 'gray')
if isinstance(image, str):
self.image = PILImage.open(image)
elif isinstance(image, PILImage.Image):
self.image = image.copy()
else:
if isinstance(image, ndarray):
# copy array
image = array(image)
if image.dtype.kind != 'i':
vmin = kwargs.get('vmin', min(image))
vmax = kwargs.get('vmax', max(image))
# rescale image
image = (image - vmin) / (vmax - vmin)
image = array(image * 256., dtype='int32')
image[image < 0] = 0
image[image > 255] = 255
image = array(image, dtype='uint8')
if image.ndim < 3:
image = repeat(image.reshape(image.shape[0], -1, 1), 3, 2)
self.image = PILImage.fromarray(image)
# add image to axis
self.axes = kwargs.get('axis', Axes.gca())
self.axes.children.append(self)
self.idx = Image._counter
Image._counter += 1
示例13: plot
def plot(self, *args, **kwargs):
had_data = self.has_data()
zval = cbook.popd(kwargs, 'z', 0)
zdir = cbook.popd(kwargs, 'dir', 'z')
lines = Axes.plot(self, *args, **kwargs)
#
linecs = [art3d.Line2DW(l, z=zval, dir=zdir) for l in lines]
#
xs = lines[0].get_xdata()
ys = lines[0].get_ydata()
zs = [zval for x in xs]
xs,ys,zs = art3d.juggle_axes(xs,ys,zs,zdir)
#
self.auto_scale_xyz(xs,ys,zs, had_data)
#
return linecs
示例14: __init__
def __init__(self, x, y, r, **kwargs):
self.x = x
self.y = y
self.r = r
# properties
self.color = kwargs.get('color', None)
self.line_style = kwargs.get('line_style', None)
self.line_width = kwargs.get('line_width', None)
# custom plot options
self.pgf_options = kwargs.get('pgf_options', [])
# catch common mistakes
if not isinstance(self.pgf_options, list):
raise TypeError('pgf_options should be a list.')
# add rectangle to axes
self.axes = kwargs.get('axes', Axes.gca())
self.axes.children.append(self)
示例15: __init__
def __init__(self, x, y, dx, dy, **kwargs):
self.x = x
self.y = y
self.dx = dx
self.dy = dy
# properties
self.color = kwargs.get('color', None)
self.arrow_style = kwargs.get('arrow_style', '-latex')
self.line_style = kwargs.get('line_style', None)
# custom plot options
self.pgf_options = kwargs.get('pgf_options', [])
# catch common mistakes
if not isinstance(self.pgf_options, list):
raise TypeError('pgf_options should be a list.')
# add arrow to axes
self.axes = kwargs.get('axis', Axes.gca())
self.axes.children.append(self)