2016-05-12 32 views
0

我有载体叫v,时间,伏特。我用matplotlib做子图,这样我可以更好地查看我的结果。但是,没有剧情出现我不知道为什么?媒介的大小是否重要?我有很大的载体。Python使用Matplotlib绘图。情节不显示

import matplotlib.pyplot as plt 
plt.subplot(2, 1, 1) 
spike_id = [i[0] for i in v] 
spike_time = [i[1] for i in v] 
plt.plot(spike_time, spike_id, ".") 
plt.xlabel("Time(ms)") 
plt.ylabel("NeuronID") 


plt.subplot(2, 1, 2) 
plt.plot(time,volts , "-") 
plt.xlabel("Time (ms)") 
plt.ylabel("Volts (mv)") 


plt.show() 
+0

你在使用什么环境? Windows,Linux,OS X?从IDE?命令行? IPython/Jupyter笔记本?有没有错误?你的'rcParams'或'matplotlibrc'为你的安装设置正确吗?你以前能够绘制事情吗?请[编辑]你的问题并尽可能多地添加相关细节。 – MattDMo

回答

2

这可能是因为你没有定义一个数字来包含它。

这里是你的代码的修改:

from matplotlib.pyplot import figure, plot, show, xlabel, ylabel 

spike_id = [i[0] for i in v] 
spike_time = [i[1] for i in v] 

fig = figure(figsize=[16,9]) 

# Plot number 1: 
fig.add_subplot(211) 
plot(spike_time, spike_id, ".") 
xlabel("Time(ms)") 
ylabel("NeuronID") 

# plot number 2: 
fig.add_subplot(212) 
plot(time,volts , "-") 
xlabel("Time (ms)") 
ylabel("Volts (mv)") 

show() 

你还问,如果向量事项的大小。

不可以。如果可以用Python进行计算,它可以在MatPlotLib中显示(主要用C实现)。如果有几百万个进程可能需要一些时间。另外,考虑计算您的spike_idspike_time作为生成器或NumPy数组,以避免不必要的迭代。这里是如何:

发电机:

spike_id = (i[0] for i in v) 
spike_time = (i[1] for i in v) 

NumPy的:

使用与NumPy的允许矢量化,这将大大优化您的程序,并使其相当快;尤其是在处理大量数据的情况下。

这听起来像是你正在处理一些信号数据(可能是EEG或EMG?)。无论如何,NumPy将为您提供各种非常有用的工具来处理和分析这些数据。

from numpy import array 

v_array = array(v) 

spike_id = v_array[:, 0] 
spike_time = v_array[:, 1] 

如果您使用的IPython/Jupyter笔记本,您可以嵌入您的笔记本电脑里面的人物,像这样:

from matplotlib.pyplot import figure, plot, xlabel, ylabel 
%matplotlib inline 

,从而可以跳过show()因为这将不再是必要的。

希望这会有所帮助。