本文整理汇总了Python中matplotlib.axes.Axes类的典型用法代码示例。如果您正苦于以下问题:Python Axes类的具体用法?Python Axes怎么用?Python Axes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Axes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_collection3d
def add_collection3d(self, col, zs=0, zdir='z'):
'''
Add a 3d collection object to the plot.
2D collection types are converted to a 3D version by
modifying the object and adding z coordinate information.
Supported are:
- PolyCollection
- LineColleciton
- PatchCollection
'''
zvals = np.atleast_1d(zs)
if len(zvals) > 0 :
zsortval = min(zvals)
else :
zsortval = 0 # FIXME: Fairly arbitrary. Is there a better value?
if type(col) is collections.PolyCollection:
art3d.poly_collection_2d_to_3d(col, zs=zs, zdir=zdir)
col.set_sort_zpos(zsortval)
elif type(col) is collections.LineCollection:
art3d.line_collection_2d_to_3d(col, zs=zs, zdir=zdir)
col.set_sort_zpos(zsortval)
elif type(col) is collections.PatchCollection:
art3d.patch_collection_2d_to_3d(col, zs=zs, zdir=zdir)
col.set_sort_zpos(zsortval)
Axes.add_collection(self, col)
示例2: draw
def draw(self, renderer):
if self._parent is not None:
self.axes.viewLim.set(self._parent.viewLim)
self.set_position(self._parent.get_position())
Axes.draw(self, renderer)
示例3: TelescopeEventView
class TelescopeEventView(tk.Frame, object):
""" A frame showing the camera view of a single telescope """
def __init__(self, root, telescope, data=None, *args, **kwargs):
self.telescope = telescope
super(TelescopeEventView, self).__init__(root)
self.figure = Figure(figsize=(5, 5), facecolor='none')
self.ax = Axes(self.figure, [0, 0, 1, 1], aspect=1)
self.ax.set_axis_off()
self.figure.add_axes(self.ax)
self.camera_plot = CameraPlot(telescope, self.ax, data, *args, **kwargs)
self.canvas = FigureCanvasTkAgg(self.figure, master=self)
self.canvas.show()
self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=True)
self.canvas._tkcanvas.pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
self.canvas._tkcanvas.config(highlightthickness=0)
@property
def data(self):
return self.camera_plot.data
@data.setter
def data(self, value):
self.camera_plot.data = value
self.canvas.draw()
示例4: _set_lim_and_transforms
def _set_lim_and_transforms(self):
"""
This is called once when the plot is created to set up all the
transforms for the data, text and grids.
"""
rot = 30
# Get the standard transform setup from the Axes base class
Axes._set_lim_and_transforms(self)
# Need to put the skew in the middle, after the scale and limits,
# but before the transAxes. This way, the skew is done in Axes
# coordinates thus performing the transform around the proper origin
# We keep the pre-transAxes transform around for other users, like the
# spines for finding bounds
self.transDataToAxes = self.transScale + \
self.transLimits + transforms.Affine2D().skew_deg(rot, 0)
# Create the full transform from Data to Pixels
self.transData = self.transDataToAxes + self.transAxes
# Blended transforms like this need to have the skewing applied using
# both axes, in axes coords like before.
self._xaxis_transform = (transforms.blended_transform_factory(
self.transScale + self.transLimits,
transforms.IdentityTransform()) +
transforms.Affine2D().skew_deg(rot, 0)) + self.transAxes
示例5: center_histogram_2d
def center_histogram_2d(par1, par2):
fig22 = figure(22)
ax22 = Axes(fig22, [.1, .1, .8, .8])
fig22.add_axes(ax22)
div = 10.
ll1 = l_dict[par1]
ll2 = l_dict[par2]
ss1 = ss_dict[par1]
ss2 = ss_dict[par2]
H, xedges, yedges = histogram2d(ss1[0], ss2[0], bins = [linspace(-ll1 / 2., ll1 / 2., div + 1) , linspace(-ll2 / 2., ll2 / 2., div * ll1 / ll2 + 1)], normed = 0)
#extent = [-ll1 / 2., ll1 / 2., -ll2 / 2., ll2 / 2.]#[xedges[0], xedges[-1], yedges[0], yedges[-1]]
#im = imshow( H, extent=extent )#'binary', cmap='jet'
#im.set_interpolation( 'bilinear' )
#colorbar()
ax22 = Axes3D(fig22, [.1, .1, .8, .8])
x = (xedges[range(0, len(xedges) - 1)] + xedges[range(1, len(xedges))]) / 2.
y = (yedges[range(0, len(yedges) - 1)] + yedges[range(1, len(yedges))]) / 2.
#ax10.scatter3D( xedges.ravel(), yedges.ravel(), H.ravel() )
xx = outer(x, ones(len(y)))
yy = outer(ones(len(x)), y)
ax22.plot_wireframe(xx, yy, H)#, rstride=1, cstride=1
#H, xedges, yedges = histogram2d( ss1[0], ss2[0], bins=[div, div], normed=0 )
#ax22.set_xticks( arange( -ll1 / 2., ll1 / 2., ll1 / 10. ) )
#ax22.set_title( 'histogram of fibers centroid in 2D -- sim' )
#ax22 = Axes3D( fig22 )
#X, Y, Z = xedges, yedges, H
#ax22.plot3D( X.ravel(), Y.ravel(), Z.ravel(), 'ro' )
#ax22.contour3D( X[:-1], Y[:-1], Z )
#ax22.plot_wireframe( X, Y, Z, rstride=6, cstride=6, color='blue', linewidth=0.5 )
#ax22.plot_surface( X[:-1], Y[:-1], Z )
draw()
return 0
示例6: plot_metrics_evolution
def plot_metrics_evolution(cls, ax: axes.Axes, y, x=None, **plot_config):
# default config
config = defaultdict(lambda: None)
config['xlabel'] = 'time'
for key, value in plot_config.items():
config[key] = value
# major ticks every 50
# major_ticks = np.arange(0, 900, 50)
# ax.set_xticks(major_ticks)
# plotting the graph
if x is None:
x = np.arange(len(y))
# check if element of x is tuple or just number
lines = []
if isinstance(y[0], (list, tuple)):
for y_i in zip(*y):
line, = ax.plot(x, y_i)
lines.append(line)
else:
line, = ax.plot(x, y)
# colour
if config['colour'] is not None:
line.set_color(config['colour'])
lines.append(line)
cls.apply_plot_config(ax, config)
return lines
示例7: set_top_view
def set_top_view(self):
xdwl = (0.95/self.dist)
xdw = (0.9/self.dist)
ydwl = (0.95/self.dist)
ydw = (0.9/self.dist)
Axes.set_xlim(self, -xdwl, xdw)
Axes.set_ylim(self, -ydwl, ydw)
示例8: cla
def cla(self):
"""
Override to set up some reasonable defaults.
"""
# Don't forget to call the base class
Axes.cla(self)
# Turn off minor ticking altogether
self.xaxis.set_minor_locator(NullLocator())
self.yaxis.set_minor_locator(NullLocator())
self.xaxis.set_major_locator(MaxNLocator(5, prune='both'))
self.yaxis.set_major_locator(MaxNLocator(5, prune='both'))
# Do not display ticks -- we only want gridlines and text
self.xaxis.set_ticks_position('none')
self.yaxis.set_ticks_position('none')
self.set_center(None, None)
# FIXME: probabaly want to override autoscale_view
# to properly handle wrapping introduced by margin
# and properlty wrap data.
# It doesn't make sense to have xwidth > 360.
self._tight = True
示例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
# Calculate projection of collections and zorder them
zlist = [(col.do_3d_projection(renderer), col) for col in self.collections]
zlist.sort()
zlist.reverse()
for i, (z, col) in enumerate(zlist):
col.zorder = i
# Calculate projection of patches and zorder them
zlist = [(patch.do_3d_projection(renderer), patch) for patch in self.patches]
zlist.sort()
zlist.reverse()
for i, (z, patch) in enumerate(zlist):
patch.zorder = i
axes = (self.w_xaxis, self.w_yaxis, self.w_zaxis)
for ax in axes:
ax.draw_pane(renderer)
for ax in axes:
ax.draw(renderer)
Axes.draw(self, renderer)
示例10: cla
def cla(self):
"""Provide reasonable defaults for the axes.
"""
# Call the base class.
Axes.cla(self)
self.grid(True)
# Only the x-axis is shown, but there are 3 axes once all of the
# projections are included.
self.yaxis.set_visible(False)
# Adjust the number of ticks shown.
#self.set_xticks(np.linspace(0, self.viewLim.x1, 5))
self.set_xticks(np.linspace(0, self.total, 5))
# Turn off minor ticking altogether.
self.xaxis.set_minor_locator(NullLocator())
# Place the title a little higher than normal.
self.title.set_y(1.02)
# Modify the padding between the tick labels and the axis labels.
self.xaxis.labelpad = 10 # In display units
# Spacing from the vertices (tips) to the tip labels (in data coords, as
# a fraction of self.total)
self.tipoffset = 0.14
示例11: __init__
def __init__(self, fig, rect=None, *args, **kwargs):
if rect is None:
rect = [0.0, 0.0, 1.0, 1.0]
self.fig = fig
self.cids = []
azim = kwargs.pop("azim", -60)
elev = kwargs.pop("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.view_init(elev, azim)
self._ready = 0
Axes.__init__(self, self.fig, rect, frameon=True, xticks=[], yticks=[], *args, **kwargs)
self.M = None
self._ready = 1
self.mouse_init()
self.create_axes()
self.set_top_view()
self.axesPatch.set_linewidth(0)
self.fig.add_axes(self)
示例12: cla
def cla(self):
# Disconnect the various events we set.
for cid in self.cids:
self.figure.canvas.mpl_disconnect(cid)
self.cids = []
Axes.cla(self)
self.grid(rcParams['axes3d.grid'])
示例13: 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
# Calculate projection of collections and zorder them
zlist = [(col.do_3d_projection(renderer), col) \
for col in self.collections]
zlist.sort(reverse=True)
for i, (z, col) in enumerate(zlist):
col.zorder = getattr(col, '_force_zorder', i)
# Calculate projection of patches and zorder them
zlist = [(patch.do_3d_projection(renderer), patch) \
for patch in self.patches]
zlist.sort(reverse=True)
for i, (z, patch) in enumerate(zlist):
patch.zorder = i
self.w_xaxis.draw(renderer)
self.w_yaxis.draw(renderer)
self.w_zaxis.draw(renderer)
Axes.draw(self, renderer)
示例14: plot_evolution
def plot_evolution(cls, ax: axes.Axes, y, x=None, **plot_config):
# default config
config = defaultdict(lambda: None)
config['xlabel'] = 'time'
for key, value in plot_config.items():
config[key] = value
# plotting the graph
if x is None:
x = np.arange(len(y))
# check if element of x is tuple or just number
lines = []
if isinstance(y[0], (list, tuple)):
for y_i in zip(*y):
line, = ax.plot(x, y_i)
lines.append(line)
else:
line, = ax.plot(x, y)
lines.append(line)
cls.apply_plot_config(ax, config)
plt.tight_layout()
return lines
示例15: plot_mods
def plot_mods(ax: Axes, stats: Stats, most_popular_at_bottom=False, percentage=False):
# FIXME different colors when using percentage with 10 mods
mods_by_popularity = sorted(stats.players_by_mod.keys(),
key=lambda mod: stats.all_time_players_by_mod[mod], reverse=most_popular_at_bottom)
labels = ["{} - avg. {:.2f} players".format(mod, stats.all_time_players_by_mod[mod] / len(stats.dates))
for mod in mods_by_popularity]
colors = ['red', 'green', 'blue', 'yellow', 'purple', 'lime', 'gray', 'cyan', 'orange', 'deeppink', 'black']
colors = colors[0:len(mods_by_popularity)]
colors = colors if most_popular_at_bottom else reversed(colors)
ax.set_prop_cycle(color=colors)
all_mods_values = np.row_stack([stats.players_by_mod[mod] for mod in mods_by_popularity])
if percentage:
with np.errstate(invalid='ignore'):
all_mods_values = all_mods_values / all_mods_values.sum(axis=0) * 100
ax.stackplot(stats.dates, all_mods_values, labels=labels, linewidth=0.1)
if percentage:
ax.set_ylim(bottom=0, top=100)
else:
ax.set_ylim(bottom=0)
decorate_axes(ax)
handles, labels = ax.get_legend_handles_labels()
handles = handles if most_popular_at_bottom else reversed(handles)
labels = labels if most_popular_at_bottom else reversed(labels)
leg = ax.legend(handles, labels, loc='upper left', prop={'size': 10})
leg.get_frame().set_alpha(0.5)