Python 如何使用Mayavi在我的机器上构建3D条形图?

Python 如何使用Mayavi在我的机器上构建3D条形图?,python,jupyter-notebook,out-of-memory,data-visualization,mayavi,Python,Jupyter Notebook,Out Of Memory,Data Visualization,Mayavi,想使用Mayavi(在我的华硕笔记本电脑Intel CoreTM i7-4510U CPU@2.00 GHz,8 GBs内存,Windows 10上)和Jupyter笔记本电脑(在Python virtualenv上)构建一个3D条形图,但我得到的是灰色屏幕 ,我在New>Python3中单击并编写 使用pandas的快速CSV解析器,以及 运行第4行后,我可以看到内存使用率增加到使用CleanMem Mini Monitor时的88%,并且在不到1分钟的时间内得到了结果 然后,构建 不幸的是

想使用Mayavi(在我的华硕笔记本电脑Intel CoreTM i7-4510U CPU@2.00 GHz,8 GBs内存,Windows 10上)和Jupyter笔记本电脑(在Python virtualenv上)构建一个3D条形图,但我得到的是灰色屏幕

,我在New>Python3中单击并编写

使用pandas的快速CSV解析器,以及 运行第4行后,我可以看到内存使用率增加到使用CleanMem Mini Monitor时的88%,并且在不到1分钟的时间内得到了结果

然后,构建

不幸的是,我得到了这个回忆

---------------------------------------------------------------------------
MemoryError                               Traceback (most recent call last)
<ipython-input-6-9736b00b5abc> in <module>
      2 df2=df[[1]]
      3 df3=df[[2]]
----> 4 mlab.barchart(df1,df2,df3)

c:\infovis\virtualenvs\dev\lib\site-packages\mayavi\tools\helper_functions.py in the_function(*args, **kwargs)
     35 
     36     def the_function(*args, **kwargs):
---> 37         return pipeline(*args, **kwargs)
     38 
     39     if hasattr(pipeline, 'doc'):

c:\infovis\virtualenvs\dev\lib\site-packages\mayavi\tools\helper_functions.py in __call__(self, *args, **kwargs)
     80             scene.disable_render = True
     81         # Then call the real logic
---> 82         output = self.__call_internal__(*args, **kwargs)
     83         # And re-enable the rendering, if needed.
     84         if scene is not None:

c:\infovis\virtualenvs\dev\lib\site-packages\mayavi\tools\helper_functions.py in __call_internal__(self, *args, **kwargs)
   1093         """ Override the call to be able to scale automatically the axis.
   1094         """
-> 1095         g = Pipeline.__call_internal__(self, *args, **kwargs)
   1096         gs = g.glyph.glyph_source
   1097         # Use a cube source for glyphs.

c:\infovis\virtualenvs\dev\lib\site-packages\mayavi\tools\helper_functions.py in __call_internal__(self, *args, **kwargs)
     90         the last object created by the pipeline."""
     91         self.store_kwargs(kwargs)
---> 92         self.source = self._source_function(*args, **kwargs)
     93         # Copy the pipeline so as not to modify it for the next call
     94         self.pipeline = self._pipeline[:]

c:\infovis\virtualenvs\dev\lib\site-packages\mayavi\tools\sources.py in vertical_vectors_source(*args, **kwargs)
   1356 
   1357     data_source = MVerticalGlyphSource()
-> 1358     data_source.reset(x=x, y=y, z=z, scalars=s)
   1359 
   1360     name = kwargs.pop('name', 'VerticalVectorsSource')

c:\infovis\virtualenvs\dev\lib\site-packages\mayavi\tools\sources.py in reset(self, **traits)
    306                 traits['u'] = traits['v'] = np.ones_like(s),
    307                 traits['w'] = s
--> 308         super(MVerticalGlyphSource, self).reset(**traits)
    309 
    310     def _scalars_changed(self, s):

c:\infovis\virtualenvs\dev\lib\site-packages\mayavi\tools\sources.py in reset(self, **traits)
    172 
    173         else:
--> 174             points = np.c_[x.ravel(), y.ravel(), z.ravel()].ravel()
    175             points.shape = (-1, 3)
    176             self.trait_set(points=points, trait_change_notify=False)

c:\infovis\virtualenvs\dev\lib\site-packages\numpy\lib\index_tricks.py in __getitem__(self, key)
    404                 objs[k] = objs[k].astype(final_dtype)
    405 
--> 406         res = self.concatenate(tuple(objs), axis=axis)
    407 
    408         if matrix:

<__array_function__ internals> in concatenate(*args, **kwargs)

MemoryError: Unable to allocate array with shape (153543233, 3) and data type int64
---------------------------------------------------------------------------
MemoryError回溯(上次最近调用)
在里面
2 df2=df[[1]]
3 df3=df[[2]]
---->4 mlab.条形图(df1、df2、df3)
c:\infovis\virtualenvs\dev\lib\site packages\mayavi\tools\helper\u functions.py在函数中(*args,**kwargs)
35
36定义_函数(*args,**kwargs):
--->37回流管道(*args,**kwargs)
38
39如果hasattr(管道,“文件”):
c:\infovis\virtualenvs\dev\lib\site packages\mayavi\tools\helper\u functions.py在调用中(self,*args,**kwargs)
80 scene.disable_render=True
81#然后称之为真正的逻辑
--->82输出=self.\uuuuuu调用\uuuuuuuu内部(*参数,**kwargs)
83#并在需要时重新启用渲染。
84如果场景不是无:
c:\infovis\virtualenvs\dev\lib\site packages\mayavi\tools\helper\u functions.py in\uuuuu调用\uu内部(self,*args,**kwargs)
1093“覆盖调用,以便能够自动缩放轴。
1094         """
->1095 g=管道。调用内部(self,*args,**kwargs)
1096 gs=g.glyph.glyph\u源
1097#为字形使用立方体源。
c:\infovis\virtualenvs\dev\lib\site packages\mayavi\tools\helper\u functions.py in\uuuuu调用\uu内部(self,*args,**kwargs)
90管道创建的最后一个对象。”“”
91自助商店(kwargs)
--->92 self.source=self.\u source\u函数(*args,**kwargs)
93#复制管道,以免在下次调用时修改管道
94 self.pipeline=self.\u pipeline[:]
c:\infovis\virtualenvs\dev\lib\site packages\mayavi\tools\sources.py in vertical\u vectors\u source(*args,**kwargs)
1356
1357数据源=MVerticalGlyphSource()
->1358数据源重置(x=x,y=y,z=z,标量=s)
1359
1360 name=kwargs.pop('name','verticalvectorsource')
重置中的c:\infovis\virtualenvs\dev\lib\site packages\mayavi\tools\sources.py(self,**traits)
306个特征['u']=特征['v']=np.类似的特征,
307特征['w']=s
-->308超级(MVerticalGlyphSource,self).重置(**特征)
309
310 def标量已更改(自身):
重置中的c:\infovis\virtualenvs\dev\lib\site packages\mayavi\tools\sources.py(self,**traits)
172
173.其他:
-->174点=np.c_uu[x.ravel(),y.ravel(),z.ravel()].ravel()
175点。形状=(-1,3)
176自我特质设置(点=点,特质改变通知=假)
c:\infovis\virtualenvs\dev\lib\site packages\numpy\lib\index\u tricks.py in\uuuuu\getitem\uuuuuu(self,key)
404 objs[k]=objs[k].aType(最终数据类型)
405
-->406 res=self.concatenate(元组(objs),axis=axis)
407
408如果矩阵:
串联(*args,**kwargs)
MemoryError:无法分配形状为(153543233,3)且数据类型为int64的数组
结果是这样的


由于内存不断不足,我不得不想出一种减少数据量的方法

受启发,我决定使用采样(从CSV文件创建一个样本)

出于简化的原因,我决定使用随机样本

然后创建可视化的过程完全相同,只是文件名不同,结果如下


你确定条形图就是你想要的吗?看起来x和y坐标都是0或1,在任何情况下,100毫米的项目对于条形图来说都太多了。如果你真正想要的是直方图,或者求和
df[[2]]
每个x,y对的值,然后我认为您需要在调用显示功能之前自己进行一些数据处理。是的,条形图就是我想要的数据和尽可能多的项目。这可能需要很多,但如果不能在我的条件下使用mayavi,我希望找到其他可行的解决方案。如果E变得更糟,必须考虑采样之类的问题。我是否正确阅读<代码>(DF[[ 0 ] ],DF[[ 1 ] ] < /C>是你的(x,y)坐标,而<代码> df[[ 2 ] ] /代码>是高度值?你有很多重复(x,y)。s、 你希望如何显示它们?对。这里的x,y,z并不重要,因为唯一的目标是检查Mayavi是否能够创建一个包含那么多记录的条形图,并将其放入条形图中。(如果意义相关,可以对z进行平均,并用(0,0),(0,1),(1,0),(1,1))得到(x,y)。让我们来看看。
---------------------------------------------------------------------------
MemoryError                               Traceback (most recent call last)
<ipython-input-6-9736b00b5abc> in <module>
      2 df2=df[[1]]
      3 df3=df[[2]]
----> 4 mlab.barchart(df1,df2,df3)

c:\infovis\virtualenvs\dev\lib\site-packages\mayavi\tools\helper_functions.py in the_function(*args, **kwargs)
     35 
     36     def the_function(*args, **kwargs):
---> 37         return pipeline(*args, **kwargs)
     38 
     39     if hasattr(pipeline, 'doc'):

c:\infovis\virtualenvs\dev\lib\site-packages\mayavi\tools\helper_functions.py in __call__(self, *args, **kwargs)
     80             scene.disable_render = True
     81         # Then call the real logic
---> 82         output = self.__call_internal__(*args, **kwargs)
     83         # And re-enable the rendering, if needed.
     84         if scene is not None:

c:\infovis\virtualenvs\dev\lib\site-packages\mayavi\tools\helper_functions.py in __call_internal__(self, *args, **kwargs)
   1093         """ Override the call to be able to scale automatically the axis.
   1094         """
-> 1095         g = Pipeline.__call_internal__(self, *args, **kwargs)
   1096         gs = g.glyph.glyph_source
   1097         # Use a cube source for glyphs.

c:\infovis\virtualenvs\dev\lib\site-packages\mayavi\tools\helper_functions.py in __call_internal__(self, *args, **kwargs)
     90         the last object created by the pipeline."""
     91         self.store_kwargs(kwargs)
---> 92         self.source = self._source_function(*args, **kwargs)
     93         # Copy the pipeline so as not to modify it for the next call
     94         self.pipeline = self._pipeline[:]

c:\infovis\virtualenvs\dev\lib\site-packages\mayavi\tools\sources.py in vertical_vectors_source(*args, **kwargs)
   1356 
   1357     data_source = MVerticalGlyphSource()
-> 1358     data_source.reset(x=x, y=y, z=z, scalars=s)
   1359 
   1360     name = kwargs.pop('name', 'VerticalVectorsSource')

c:\infovis\virtualenvs\dev\lib\site-packages\mayavi\tools\sources.py in reset(self, **traits)
    306                 traits['u'] = traits['v'] = np.ones_like(s),
    307                 traits['w'] = s
--> 308         super(MVerticalGlyphSource, self).reset(**traits)
    309 
    310     def _scalars_changed(self, s):

c:\infovis\virtualenvs\dev\lib\site-packages\mayavi\tools\sources.py in reset(self, **traits)
    172 
    173         else:
--> 174             points = np.c_[x.ravel(), y.ravel(), z.ravel()].ravel()
    175             points.shape = (-1, 3)
    176             self.trait_set(points=points, trait_change_notify=False)

c:\infovis\virtualenvs\dev\lib\site-packages\numpy\lib\index_tricks.py in __getitem__(self, key)
    404                 objs[k] = objs[k].astype(final_dtype)
    405 
--> 406         res = self.concatenate(tuple(objs), axis=axis)
    407 
    408         if matrix:

<__array_function__ internals> in concatenate(*args, **kwargs)

MemoryError: Unable to allocate array with shape (153543233, 3) and data type int64
shuf -n 10000 BIGFILE.csv > SAMPLEFILE.csv