本文整理汇总了Python中matplotlib.collections.LineCollection.set_rasterized方法的典型用法代码示例。如果您正苦于以下问题:Python LineCollection.set_rasterized方法的具体用法?Python LineCollection.set_rasterized怎么用?Python LineCollection.set_rasterized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.collections.LineCollection
的用法示例。
在下文中一共展示了LineCollection.set_rasterized方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_trajectory
# 需要导入模块: from matplotlib.collections import LineCollection [as 别名]
# 或者: from matplotlib.collections.LineCollection import set_rasterized [as 别名]
def plot_trajectory(trajectories, name='trajectory', pos='left'):
print "Plotting trajectory: %s" % name
plt.figure(1, figsize=(4, 4))
ax = plt.subplot(111)
trajx = np.concatenate([t[0] for t in trajectories])
trajy = np.concatenate([t[1] for t in trajectories])
annote = set()
for t in trajectories:
for a in t[2]:
annote.add(a)
cmap = plt.get_cmap('Greys')
t = np.arange(trajx.shape[0]) * 0.001
points = np.array([trajy, trajx]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
lc = LineCollection(segments, cmap=cmap,
norm=plt.Normalize(-t[-1] * 0.5, t[-1] * 0.75))
lc.set_array(t)
lc.set_linewidth(3)
lc.set_rasterized(True)
ax.add_collection(lc)
for (a_t, l) in annote:
ix = int(a_t / 0.001) - 1
xy = (trajy[ix], trajx[ix])
xytext = (-30 if xy[0] > 0 else 30, -30 if xy[1] > 0 else 30)
if l == 'Start of next trial' and xy[1] > 0:
l = 'Start of\nnext trial'
xytext = (-50, 5)
if l == 'Release\n(premature)':
xytext = (-10, -35)
plt.annotate(l, xy, xycoords='data', xytext=xytext, ha='center',
va='center', textcoords='offset points',
arrowprops={'arrowstyle': '->',
'connectionstyle': 'arc3, rad=0.2'})
plt.axhline(0.0, color='k', ls=":")
plt.axvline(0.0, color='k', ls=":")
if 'left' in pos:
plt.ylabel("Task state (arbitrary units)")
ax.get_yaxis().tick_left()
else:
plt.yticks(())
ax.get_xaxis().tick_bottom()
plt.xlabel("Relative time in task state (arbitrary units)")
plt.axis((-1.5, 1.5, -2.0, 1.5))
plt.subplots_adjust(bottom=0.12, top=0.97, left=0.17, right=0.97)
save_or_show('plots/' + name + '_traj')