本文整理汇总了Python中matplotlib.axes.Axes.plot方法的典型用法代码示例。如果您正苦于以下问题:Python Axes.plot方法的具体用法?Python Axes.plot怎么用?Python Axes.plot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.axes.Axes
的用法示例。
在下文中一共展示了Axes.plot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_metrics_evolution
# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import plot [as 别名]
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
示例2: plot_evolution
# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import plot [as 别名]
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
示例3: fibers_2d_xy
# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import plot [as 别名]
def fibers_2d_xy():
'''
Plot fibers in 2D section (plane XY)
'''
fig3 = figure(5)
ax3 = Axes(fig3, [.1, .1, .8, .8])
fig3.add_axes(ax3)
for i in range(0, len(sx[0])):
l = Line2D([sx[0][i] - fib.lf / 2. * cos(phi_x[0][i]), sx[0][i] + fib.lf / 2. * cos(phi_x[0][i])], \
[sy[0][i] - fib.lf / 2. * cos(phi_y[0][i]), sy[0][i] + fib.lf / 2. * cos(phi_y[0][i])], \
linewidth = .5, color = 'black')
#print i, sx[0][i], lf / 2. * cosphi_x[0][i], [sx[0][i] - lf / 2. * cosphi_x[0][i], sx[0][i] + lf / 2. * cosphi_x[0][i]], \
# [sy[0][i] - lf / 2. * cosphi_y[0][i], sy[0][i] + lf / 2. * cosphi_y[0][i]], \
# [sz[0][i] - lf / 2. * cosphi_z[0][i], sz[0][i] + lf / 2. * cosphi_z[0][i]]
ax3.add_line(l)
ax3.plot(sx, sy, 'ko', markersize = 3.0)
ax3.plot([ -spec.l_x / 2., spec.l_x / 2. ], [spec.l_y / 2., spec.l_y / 2.], 'k-', linewidth = 2)
ax3.plot([ -spec.l_x / 2., spec.l_x / 2. ], [-spec.l_y / 2., -spec.l_y / 2.], 'k-', linewidth = 2)
ax3.plot([ spec.l_x / 2., spec.l_x / 2. ], [-spec.l_y / 2., spec.l_y / 2.], 'k-', linewidth = 2)
ax3.plot([ -spec.l_x / 2., -spec.l_x / 2. ], [-spec.l_y / 2., spec.l_y / 2.], 'k-', linewidth = 2)
ax3.set_axis_off()
#ax3.set_xlim( -l_x / 2., l_x / 2. )
#ax3.set_ylim( -l_y / 2., l_y / 2. )
title('Fibers in 2D - xy')
draw()
示例4: fibers_2d_yz
# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import plot [as 别名]
def fibers_2d_yz():
'''
Plot fibers in 2D section (plane YZ)
'''
fig2 = figure(1)
ax2 = Axes(fig2, [.1, .1, .8, .8])
fig2.add_axes(ax2)
for i in range(0, len(sx[0])):
l = Line2D([sy[0][i] - fib.lf / 2. * cos(phi_y[0][i]), sy[0][i] + fib.lf / 2. * cos(phi_y[0][i])], \
[sz[0][i] - fib.lf / 2. * cos(phi_z[0][i]), sz[0][i] + fib.lf / 2. * cos(phi_z[0][i])], \
linewidth = .5)
#print i, sx[0][i], lf / 2. * cosphi_x[0][i], [sx[0][i] - lf / 2. * cosphi_x[0][i], sx[0][i] + lf / 2. * cosphi_x[0][i]], \
# [sy[0][i] - lf / 2. * cosphi_y[0][i], sy[0][i] + lf / 2. * cosphi_y[0][i]], \
# [sz[0][i] - lf / 2. * cosphi_z[0][i], sz[0][i] + lf / 2. * cosphi_z[0][i]]
ax2.add_line(l)
ax2.plot(sy, sz, 'ro')
ax2.plot([ -spec.l_y / 2., spec.l_y / 2. ], [spec.l_z / 2., spec.l_z / 2.], 'r-')
ax2.plot([ -spec.l_y / 2., spec.l_y / 2. ], [-spec.l_z / 2., -spec.l_z / 2.], 'r-')
ax2.plot([ spec.l_y / 2., spec.l_y / 2. ], [-spec.l_z / 2., spec.l_z / 2.], 'r-')
ax2.plot([ -spec.l_y / 2., -spec.l_y / 2. ], [-spec.l_z / 2., spec.l_z / 2.], 'r-')
#ax2.set_xlim( -l_y / 2., l_y / 2. )
#ax2.set_ylim( -l_z / 2., l_z / 2. )
title('Fibers in 2D - yz')
draw()
return 0
示例5: drawG
# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import plot [as 别名]
def drawG(fig, n, roundN, graphs):
graphsId = difGraphsId(graphs)
size = len(graphsId)
print 'size ', size
bgnX = 0.1
bgnY = 0.1
width = 0.8 / size
height = 0.35
for idx in range(size):
ax = Axes(fig, [bgnX, bgnY, width * 0.9, height])
ax.set_xticks(range(-1,3))
ax.set_yticks(range(-1, n+1))
ax.set_frame_on(False)
gid = graphsId[idx]
ax.set_title( 'Round ' + str(gid+1) )
for i in range(-1, n + 1):
ax.plot(0, i, marker = 'o')
ax.plot(1, i, marker = 'o')
for edge in graphs[gid]:
nodes = [int(i) for i in edge.split('-')]
nodes[1] -= n
line = Line2D([0, 1], nodes)
if gid == 0:
line.set_color('b')
else:
color = 'r'
for e in graphs[gid-1]:
if edge == e:
color = 'b'
break
line.set_color(color)
ax.add_line( line )
preId = max(gid-1, 0)
for edge in graphs[preId]:
color = 'g'
for e in graphs[gid]:
if edge == e:
color = 'b'
break
if color == 'g':
nodes = [int(i) for i in edge.split('-')]
nodes[1] -= n
line = Line2D([0, 1], nodes, linestyle= '--')
line.set_color(color)
ax.add_line( line )
fig.add_axes( ax )
bgnX += width
示例6: plot
# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import plot [as 别名]
def plot(self, *args, **kwargs):
if "projection" in kwargs:
projection = kwargs.pop("projection")
else:
projection = self.name
vars = args[:2]
args = args[2:]
if len(vars) == 2 and isinstance(vars[1], (str, unicode)):
args = (vars[1],) + args
vars = vars[:1]
if ((len(vars) == 1 and
isinstance(vars[0], hfarray) and
len(vars[0].dims) >= 1)):
y = vars[0]
x = hfarray(y.dims[0])
vars = (x, y)
if self.HFTOOLS_default_x_name is None:
self.HFTOOLS_default_x_name = y.dims[0].name
fmt = self.axes.xaxis.get_major_formatter()
if hasattr(fmt, "update_template"):
fmt.default_label = self.HFTOOLS_default_x_name
fmt.update_template()
if len(vars) == 1:
y = vars[0]
if projection in _projfun:
x, y = _projfun[projection](None, y)
return Axes.plot(self, y, *args, **kwargs)
elif np.iscomplexobj(y):
return Axes.plot(self, y.real, y.imag, *args, **kwargs)
else:
return Axes.plot(self, y, *args, **kwargs)
elif len(vars) == 2:
x = vars[0]
y = vars[1]
xunit = getattr(x, "unit", None)
yunit = getattr(y, "unit", None)
if projection in _projfun:
x, y = _projfun[projection](x, y)
lines = self._plot_helper(x, y, *args, **kwargs)
elif np.iscomplexobj(y):
xunit = yunit
lines = self._plot_helper(y.real, y.imag, *args, **kwargs)
else:
lines = self._plot_helper(x, y, *args, **kwargs)
if xunit:
self.set_xlabel_unit(xunit)
if yunit:
self.set_ylabel_unit(yunit)
return lines
else:
raise Exception("Missing plot data")
示例7: plot_regional_evolution
# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import plot [as 别名]
def plot_regional_evolution(cls, ax: axes.Axes, y, x=None, **plot_config):
# default config
config = defaultdict(lambda: None)
config['xlabel'] = 'time'
config['colourmap'] = cls.colour_map
for key, value in plot_config.items():
config[key] = value
# plotting the graph
if x is None:
x = np.arange(len(y))
# separating out the data for each region
region_data = defaultdict(list)
for i in range(len(y)):
for region_id in y[i].keys():
region_data[region_id].append((x[i], y[i][region_id]))
# set the colour mapping for region ids
region_ids = sorted(tuple(region_data.keys()))
colours = plt.get_cmap(config['colourmap'])(np.linspace(0, 1.0, len(region_ids)))
lines = []
for i, data_i in region_data.items():
x_i, y_i = tuple(zip(*data_i))
line, = ax.plot(x_i, y_i)
line.set_color(colours[region_ids.index(i)])
lines.append(line)
cls.apply_plot_config(ax, config)
return lines, region_ids
示例8: plot
# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import plot [as 别名]
def plot(self, xs, ys, *args, **kwargs):
'''
Plot 2D or 3D data.
========== ================================================
Argument Description
========== ================================================
*xs*, *ys* X, y coordinates of vertices
*zs* z value(s), either one for all points or one for
each point.
*zdir* Which direction to use as z ('x', 'y' or 'z')
when plotting a 2d set.
========== ================================================
Other arguments are passed on to
:func:`~matplotlib.axes.Axes.plot`
'''
had_data = self.has_data()
zs = kwargs.pop('zs', 0)
zdir = kwargs.pop('zdir', 'z')
argsi = 0
if len(args) > 0 and cbook.iterable(args[0]) and \
len(xs) == len(args[0]) and cbook.is_scalar(args[0][0]):
zs = args[argsi]
argsi += 1
elif len(args) > 0 and cbook.is_scalar(args[0]):
zs = args[argsi]
argsi += 1
if not cbook.iterable(zs):
zs = np.ones(len(xs)) * zs
lines = Axes.plot(self, xs, ys, *args[argsi:], **kwargs)
for line in lines:
art3d.line_2d_to_3d(line, zs=zs, zdir=zdir)
self.auto_scale_xyz(xs, ys, zs, had_data)
return lines
示例9: plot
# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import plot [as 别名]
def plot(self, xs, ys, *args, **kwargs):
'''
Plot 2D or 3D data.
========== ================================================
Argument Description
========== ================================================
*xs*, *ys* X, y coordinates of vertices
*zs* z value(s), either one for all points or one for
each point.
*zdir* Which direction to use as z ('x', 'y' or 'z')
when plotting a 2d set.
========== ================================================
Other arguments are passed on to
:func:`~matplotlib.axes.Axes.plot`
'''
# FIXME: This argument parsing might be better handled
# when we set later versions of python for
# minimum requirements. Currently at 2.4.
# Note that some of the reason for the current difficulty
# is caused by the fact that we want to insert a new
# (semi-optional) positional argument 'Z' right before
# many other traditional positional arguments occur
# such as the color, linestyle and/or marker.
had_data = self.has_data()
zs = kwargs.pop('zs', 0)
zdir = kwargs.pop('zdir', 'z')
argsi = 0
# First argument is array of zs
if len(args) > 0 and cbook.iterable(args[0]) and \
len(xs) == len(args[0]) :
# So, we know that it is an array with
# first dimension the same as xs.
# Next, check to see if the data contained
# therein (if any) is scalar (and not another array).
if len(args[0]) == 0 or cbook.is_scalar(args[0][0]) :
zs = args[argsi]
argsi += 1
# First argument is z value
elif len(args) > 0 and cbook.is_scalar(args[0]):
zs = args[argsi]
argsi += 1
# Match length
if not cbook.iterable(zs):
zs = np.ones(len(xs)) * zs
lines = Axes.plot(self, xs, ys, *args[argsi:], **kwargs)
for line in lines:
art3d.line_2d_to_3d(line, zs=zs, zdir=zdir)
self.auto_scale_xyz(xs, ys, zs, had_data)
return lines
示例10: drawEP
# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import plot [as 别名]
def drawEP(fig, n, roundN, endowments, prices):
ax = Axes(fig, [.1, .55, .8, .35])
ax.grid(True)
ax.set_xticks( range(roundN+1) )
ax.set_frame_on(False)
users = [[] for i in range(n)]
for i in range(n):
for j in range(roundN):
users[i].append( float(Fraction(endowments[j][i])) )
users[i].append( float(Fraction(prices[roundN-1][i])) )
x = range(roundN+1)
for i in range(n):
price = round(float(Fraction(prices[roundN-1][i])), 3)
ax.plot(x, users[i], linestyle = '--', marker = 'o', label = str(i) + ": " + str(price))
# ax.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=2, ncol=min(n, 5), mode="expand", borderaxespad=0.)
ax.legend()
fig.add_axes( ax )
示例11: _plot_helper
# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import plot [as 别名]
def _plot_helper(self, x, y, *args, **kwargs):
if not hasattr(y, "dims"):
return Axes.plot(self, x, y, *args, **kwargs)
if x.ndim == 1 and y.ndim == 1:
return Axes.plot(self, x, y, *args, **kwargs)
else:
return Axes.plot(self, remove_tail(x), remove_tail(y), *args, **kwargs)
Ns = y.shape[1:4]
kw = kwargs.copy()
lines = []
if len(Ns) == 1:
C = zip(itertools.cycle(self.colorcycle), range(Ns[0]))
for c, i in C:
#kw.update(dict(color=c))
if hasattr(x, "dims") and (get_dims_names(x) ==
get_dims_names(y)):
xx = x[:, i].squeeze()
else:
xx = x
lines.extend(Axes.plot(self, xx, remove_tail(y[:, i]),
*args, **kw))
elif len(Ns) == 2:
C = zip(itertools.cycle(self.colorcycle), range(Ns[0]))
M = zip(itertools.cycle(self.markercycle), range(Ns[1]))
for c, i in C:
for m, j in M:
if hasattr(x, "dims") and (get_dims_names(x) ==
get_dims_names(y)):
xx = x[:, i, j].squeeze()
else:
xx = x
#kw.update(dict(color=c, marker=m))
lines.extend(Axes.plot(self, xx,
remove_tail(y[:, i, j]),
*args, **kw))
elif len(Ns) > 2:
C = zip(itertools.cycle(self.colorcycle), range(Ns[0]))
M = zip(itertools.cycle(self.markercycle), range(Ns[1]))
L = zip(itertools.cycle(self.linecycle), range(Ns[2]))
for c, i in C:
for m, j in M:
for l, k in L:
if hasattr(x, "dims") and (get_dims_names(x) ==
get_dims_names(y)):
xx = x[:, i, j, k].squeeze()
else:
xx = x
#kw.update(dict(color=c, marker=m, line=l))
lines.extend(Axes.plot(self, xx,
remove_tail(y[:, i, j, k]),
*args, **kw))
return lines
示例12: plot
# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import plot [as 别名]
def plot(self, *args, **kwargs):
"""
If the **mantid** projection is chosen, it can be
used the same as :py:meth:`matplotlib.axes.Axes.plot` for arrays,
or it can be used to plot :class:`mantid.api.MatrixWorkspace`
or :class:`mantid.api.IMDHistoWorkspace`. You can have something like::
import matplotlib.pyplot as plt
from mantid import plots
...
fig, ax = plt.subplots(subplot_kw={'projection':'mantid'})
ax.plot(workspace,'rs',specNum=1) #for workspaces
ax.plot(x,y,'bo') #for arrays
fig.show()
For keywords related to workspaces, see :func:`plotfunctions.plot`.
"""
if helperfunctions.validate_args(*args):
logger.debug('using plotfunctions')
def _data_update(artists, workspace):
# It's only possible to plot 1 line at a time from a workspace
x, y, _, __ = plotfunctions._plot_impl(self, workspace, args, kwargs)
artists[0].set_data(x, y)
self.relim()
self.autoscale()
return artists
workspace = args[0]
spec_num = self._get_spec_number(workspace, kwargs)
return self.track_workspace_artist(
workspace, plotfunctions.plot(self, *args, **kwargs),
_data_update, spec_num)
else:
return Axes.plot(self, *args, **kwargs)
示例13: plot_regional_points
# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import plot [as 别名]
def plot_regional_points(cls, ax: axes.Axes, region_data, **plot_config):
# default config
config = defaultdict(lambda: None)
config['colourmap'] = cls.colour_map
config['marker'] = 'o'
config['linestyle'] = ''
config['markersize'] = 3
for key, value in plot_config.items():
config[key] = value
# set the colour mapping for region ids
region_ids = sorted(tuple(region_data.keys()))
colours = plt.get_cmap(config['colourmap'])(np.linspace(0, 1.0, len(region_ids)))
all_dots = []
for i, data_i in region_data.items():
dots, = ax.plot(*data_i)
# dots = ax.scatter(x_i, y_i)
dots.set_color(colours[region_ids.index(i)])
all_dots.append(dots)
cls.apply_plot_config(ax, config)
示例14: plot
# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import plot [as 别名]
def plot(self, *args, **kwargs):
'''
If the **mantid** projection is chosen, it can be
used the same as :py:meth:`matplotlib.axes.Axes.plot` for arrays,
or it can be used to plot :class:`mantid.api.MatrixWorkspace`
or :class:`mantid.api.IMDHistoWorkspace`. You can have something like::
import matplotlib.pyplot as plt
from mantid import plots
...
fig, ax = plt.subplots(subplot_kw={'projection':'mantid'})
ax.plot(workspace,'rs',specNum=1) #for workspaces
ax.plot(x,y,'bo') #for arrays
fig.show()
For keywords related to workspaces, see :func:`mantid.plots.plotfunctions.plot`.
'''
if mantid.plots.helperfunctions.validate_args(*args, **kwargs):
mantid.kernel.logger.debug('using mantid.plots.plotfunctions')
return mantid.plots.plotfunctions.plot(self, *args, **kwargs)
else:
return Axes.plot(self, *args, **kwargs)
示例15: plot
# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import plot [as 别名]
def plot(self, *args, **kwargs):
'''
Plot the given data into the Smith Chart. Behavior similar to basic
:meth:`matplotlib.axes.Axes.plot`, but with some extensions:
- Additional support for complex data. Complex values must be
either of type 'complex' or a numpy.ndarray with dtype=complex.
- If 'zorder' is not provided, the current default value is used.
- If 'marker' is not providet, the default value is used.
- Extra keywords are added.
Extra keyword arguments:
*no_transform*:
If set, given data points are plotted directly, without
transforming them into smith space.
*path_interpolation*:
If set, interpolates the path with the given steps. If the
value is 0, a bezier arc is drawn.
*markerhack*:
If set, activates the manipulation of start and end markern
of the created line.
*rotate_marker*:
if *markerhack* is active, rotates the endmarker in direction
of the corresponding path.
See :meth:`matplotlib.axes.Axes.plot` for mor details
'''
new_args = ()
for arg in args:
if isinstance(arg, np.ndarray) and arg.dtype == np.complex64 or \
isinstance(arg, np.ndarray) and arg.dtype == np.float32 or \
isinstance(arg, complex) or isinstance(arg, float):
new_args += (np.real(arg), np.imag(arg))
else:
new_args += (arg,)
if 'zorder' not in kwargs:
kwargs['zorder'] = self._current_zorder
self._current_zorder += 0.001
if 'marker' not in kwargs:
kwargs['marker'] = self._get_key("plot.marker")
if "path_interpolation" in kwargs:
steps = kwargs.pop("path_interpolation")
else:
steps = None
if "markerhack" in kwargs:
markerhack = kwargs.pop("markerhack")
else:
markerhack = self._get_key("plot.hacklines")
if "rotate_marker" in kwargs:
rotate_marker = kwargs.pop("rotate_marker")
else:
rotate_marker = self._get_key("plot.rotatemarker")
if "no_transform" in kwargs:
no_transform = kwargs.pop("no_transform")
else:
no_transform = False
lines = Axes.plot(self, *new_args, **kwargs)
for line in lines:
if no_transform:
x, y = line.get_data()
z = self._moebius_inv_z(x + y * 1j)
line.set_data(z.real, z.imag)
if steps is not None:
line.get_path()._interpolation_steps = steps
if markerhack:
self._hack_linedraw(line, rotate_marker)
return lines