本文整理匯總了Python中matplotlib.pyplot.eventplot方法的典型用法代碼示例。如果您正苦於以下問題:Python pyplot.eventplot方法的具體用法?Python pyplot.eventplot怎麽用?Python pyplot.eventplot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.eventplot方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_eventplot_colors
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import eventplot [as 別名]
def test_eventplot_colors(colors):
'''Test the *colors* parameter of eventplot. Inspired by the issue #8193.
'''
data = [[i] for i in range(4)] # 4 successive events of different nature
# Build the list of the expected colors
expected = [c if c is not None else 'C0' for c in colors]
# Convert the list into an array of RGBA values
# NB: ['rgbk'] is not a valid argument for to_rgba_array, while 'rgbk' is.
if len(expected) == 1:
expected = expected[0]
expected = np.broadcast_to(mcolors.to_rgba_array(expected), (len(data), 4))
fig, ax = plt.subplots()
if len(colors) == 1: # tuple with a single string (like '0.5' or 'rgbk')
colors = colors[0]
collections = ax.eventplot(data, colors=colors)
for coll, color in zip(collections, expected):
assert_allclose(coll.get_color(), color)
示例2: test_eventplot_colors
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import eventplot [as 別名]
def test_eventplot_colors(colors):
'''Test the *colors* parameter of eventplot. Inspired by the issue #8193.
'''
data = [[i] for i in range(4)] # 4 successive events of different nature
# Build the list of the expected colors
expected = [c if c is not None else 'C0' for c in colors]
# Convert the list into an array of RGBA values
# NB: ['rgbk'] is not a valid argument for to_rgba_array, while 'rgbk' is.
if len(expected) == 1:
expected = expected[0]
expected = broadcast_to(mcolors.to_rgba_array(expected), (len(data), 4))
fig, ax = plt.subplots()
if len(colors) == 1: # tuple with a single string (like '0.5' or 'rgbk')
colors = colors[0]
collections = ax.eventplot(data, colors=colors)
for coll, color in zip(collections, expected):
assert_allclose(coll.get_color(), color)
示例3: make_raster_plot
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import eventplot [as 別名]
def make_raster_plot(self):
fname = os.path.join(self.save_dir, 'raster.png')
if os.path.exists(fname):
return
plt.figure(figsize=(30,15))
ptps = self.ptps
order = np.argsort(ptps)
sorted_ptps = np.round(np.sort(ptps),2)
for j in range(self.n_units):
k = order[j]
idx = self.spike_train[:,1] == k
spt = self.spike_train[idx, 0]/self.sampling_rate
prob = self.soft_assignment[idx]
if np.sum(prob) > 1:
spt = np.sort(np.random.choice(
spt, int(np.sum(prob)), False, prob/np.sum(prob)))
plt.eventplot(spt, lineoffsets=j, color='k', linewidths=0.01)
plt.yticks(np.arange(0,self.n_units,10), sorted_ptps[0:self.n_units:10])
plt.ylabel('ptps', fontsize=self.fontsize)
plt.xlabel('time (seconds)', fontsize=self.fontsize)
plt.title('Raster Plot Sorted by PTP', fontsize=self.fontsize)
plt.savefig(fname, bbox_inches='tight', dpi=100)
plt.close()
示例4: test_eventplot_defaults
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import eventplot [as 別名]
def test_eventplot_defaults():
'''
test that eventplot produces the correct output given the default params
(see bug #3728)
'''
np.random.seed(0)
data1 = np.random.random([32, 20]).tolist()
data2 = np.random.random([6, 20]).tolist()
data = data1 + data2
fig = plt.figure()
axobj = fig.add_subplot(111)
colls = axobj.eventplot(data)
示例5: test_eventplot_problem_kwargs
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import eventplot [as 別名]
def test_eventplot_problem_kwargs():
'''
test that 'singular' versions of LineCollection props raise an
IgnoredKeywordWarning rather than overriding the 'plural' versions (e.g.
to prevent 'color' from overriding 'colors', see issue #4297)
'''
np.random.seed(0)
data1 = np.random.random([20]).tolist()
data2 = np.random.random([10]).tolist()
data = [data1, data2]
fig = plt.figure()
axobj = fig.add_subplot(111)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
colls = axobj.eventplot(data,
colors=['r', 'b'],
color=['c', 'm'],
linewidths=[2, 1],
linewidth=[1, 2],
linestyles=['solid', 'dashed'],
linestyle=['dashdot', 'dotted'])
# check that three IgnoredKeywordWarnings were raised
assert len(w) == 3
assert all(issubclass(wi.category, IgnoredKeywordWarning) for wi in w)
示例6: test_empty_eventplot
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import eventplot [as 別名]
def test_empty_eventplot():
fig, ax = plt.subplots(1, 1)
ax.eventplot([[]], colors=[(0.0, 0.0, 0.0, 0.0)])
plt.draw()
示例7: test_eventplot_legend
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import eventplot [as 別名]
def test_eventplot_legend():
plt.eventplot([1.0], label='Label')
plt.legend()
示例8: add_ptp_vs_time
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import eventplot [as 別名]
def add_ptp_vs_time(self, ptp, spt, template):
plt.scatter(spt, ptp/self.sampling_rate, c='k')
plt.plot([np.min(spt), np.max(spt)], [temp.ptp(), temp.ptp()], 'r')
#plt.eventplot(spt, color='k', linewidths=0.01)
plt.title('ptp vs spike times (red = template ptp)',
fontsize=self.fontsize)
return gs
示例9: test_eventplot
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import eventplot [as 別名]
def test_eventplot():
'''
test that eventplot produces the correct output
'''
np.random.seed(0)
data1 = np.random.random([32, 20]).tolist()
data2 = np.random.random([6, 20]).tolist()
data = data1 + data2
num_datasets = len(data)
colors1 = [[0, 1, .7]] * len(data1)
colors2 = [[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
[1, .75, 0],
[1, 0, 1],
[0, 1, 1]]
colors = colors1 + colors2
lineoffsets1 = 12 + np.arange(0, len(data1)) * .33
lineoffsets2 = [-15, -3, 1, 1.5, 6, 10]
lineoffsets = lineoffsets1.tolist() + lineoffsets2
linelengths1 = [.33] * len(data1)
linelengths2 = [5, 2, 1, 1, 3, 1.5]
linelengths = linelengths1 + linelengths2
fig = plt.figure()
axobj = fig.add_subplot(111)
colls = axobj.eventplot(data, colors=colors, lineoffsets=lineoffsets,
linelengths=linelengths)
num_collections = len(colls)
assert num_collections == num_datasets
# Reuse testcase from above for a labeled data test
data = {"pos": data, "c": colors, "lo": lineoffsets, "ll": linelengths}
fig = plt.figure()
axobj = fig.add_subplot(111)
colls = axobj.eventplot("pos", colors="c", lineoffsets="lo",
linelengths="ll", data=data)
num_collections = len(colls)
assert num_collections == num_datasets
示例10: plot_spike_trains_for_example
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import eventplot [as 別名]
def plot_spike_trains_for_example(
spikes: torch.Tensor,
n_ex: Optional[int] = None,
top_k: Optional[int] = None,
indices: Optional[List[int]] = None,
) -> None:
# language=rst
"""
Plot spike trains for top-k neurons or for specific indices.
:param spikes: Spikes for one simulation run of shape
``(n_examples, n_neurons, time)``.
:param n_ex: Allows user to pick which example to plot spikes for.
:param top_k: Plot k neurons that spiked the most for n_ex example.
:param indices: Plot specific neurons' spiking activity instead of top_k.
"""
assert n_ex is not None and 0 <= n_ex < spikes.shape[0]
plt.figure()
if top_k is None and indices is None: # Plot all neurons' spiking activity
spike_per_neuron = [np.argwhere(i == 1).flatten() for i in spikes[n_ex, :, :]]
plt.title("Spiking activity for all %d neurons" % spikes.shape[1])
elif top_k is None: # Plot based on indices parameter
assert indices is not None
spike_per_neuron = [
np.argwhere(i == 1).flatten() for i in spikes[n_ex, indices, :]
]
elif indices is None: # Plot based on top_k parameter
assert top_k is not None
# Obtain the top k neurons that fired the most
top_k_loc = np.argsort(np.sum(spikes[n_ex, :, :], axis=1), axis=0)[::-1]
spike_per_neuron = [
np.argwhere(i == 1).flatten() for i in spikes[n_ex, top_k_loc[0:top_k], :]
]
plt.title("Spiking activity for top %d neurons" % top_k)
else:
raise ValueError('One of "top_k" or "indices" or both must be None')
plt.eventplot(spike_per_neuron, linelengths=[0.5] * len(spike_per_neuron))
plt.xlabel("Simulation Time")
plt.ylabel("Neuron index")
plt.show()
示例11: plot_spike_trains_for_example
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import eventplot [as 別名]
def plot_spike_trains_for_example(
spikes: torch.Tensor,
n_ex: Optional[int] = None,
top_k: Optional[int] = None,
indices: Optional[List[int]] = None,
) -> None:
# language=rst
"""
Plot spike trains for top-k neurons or for specific indices.
:param spikes: Spikes for one simulation run of shape
``(n_examples, n_neurons, time)``.
:param n_ex: Allows user to pick which example to plot spikes for.
:param top_k: Plot k neurons that spiked the most for n_ex example.
:param indices: Plot specific neurons' spiking activity instead of top_k.
"""
assert n_ex is not None and 0 <= n_ex < spikes.shape[0]
plt.figure()
if top_k is None and indices is None: # Plot all neurons' spiking activity
spike_per_neuron = [
np.argwhere(i == 1).flatten() for i in spikes[n_ex, :, :]
]
plt.title("Spiking activity for all %d neurons" % spikes.shape[1])
elif top_k is None: # Plot based on indices parameter
assert indices is not None
spike_per_neuron = [
np.argwhere(i == 1).flatten() for i in spikes[n_ex, indices, :]
]
elif indices is None: # Plot based on top_k parameter
assert top_k is not None
# Obtain the top k neurons that fired the most
top_k_loc = np.argsort(np.sum(spikes[n_ex, :, :], axis=1), axis=0)[
::-1
]
spike_per_neuron = [
np.argwhere(i == 1).flatten()
for i in spikes[n_ex, top_k_loc[0:top_k], :]
]
plt.title("Spiking activity for top %d neurons" % top_k)
else:
raise ValueError('One of "top_k" or "indices" or both must be None')
plt.eventplot(spike_per_neuron, linelengths=[0.5] * len(spike_per_neuron))
plt.xlabel("Simulation Time")
plt.ylabel("Neuron index")
plt.show()