有效利用大数据量的内存

2024-05-14 03:51:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在进行如下绘图:

for i in range(len(classederror)):
    plt.scatter(xlag, classederror[i, :])
plt.show()

变量的大小为:

xlag = np.array(2, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250)

xlag.size = (11,)
  • classederror=176501行x 11列

但是,我遇到了内存问题,这是由于classederror的大容量造成的。你知道吗

有没有一种更有效的方法来避免记忆问题?你知道吗

我想做的事

如下图所示,x轴是xlag,y轴是classederror

我想在classederror中为x轴值的范围绘制每一行,并研究数据的分布,最后我应该得到类似下图的东西。你知道吗

enter image description here


Tags: 内存in绘图forsizelenshownp
1条回答
网友
1楼 · 发布于 2024-05-14 03:51:31

当然,绘制单个散点图要比绘制176501个散点图有效得多。你知道吗

import numpy as np
import matplotlib.pyplot as plt

xlag = np.array([2, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250])
classederror = (np.random.randn(176501, 11)*25)*(0.2+np.sort(np.random.rand(11)))

plt.scatter(np.tile(xlag,len(classederror)), classederror.flatten())

plt.show()

enter image description here

鉴于从这样一个图中所能得到的信息有限,直接画11条线可能是有意义的。你知道吗

import numpy as np
import matplotlib.pyplot as plt

xlag = np.array([2, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250])
classederror = (np.random.randn(176501, 11)*25)*(0.2+np.sort(np.random.rand(11)))

vals = np.c_[classederror.min(axis=0),classederror.max(axis=0)].T
x= np.c_[xlag,xlag].T
plt.plot(x,vals, color="C0", lw=2)

plt.show()

enter image description here

要获得有关点密度的信息,可以使用其他方法,例如小提琴图。你知道吗

plt.violinplot(classederror, xlag, points=50, widths=20,
                  showmeans=True, showextrema=True, showmedians=True)

enter image description here

相关问题 更多 >