简体   繁体   English

matplotlib 加载 memory 并且不显示 plot

[英]matplotlib loads memory and does not show plot

I want to plot a large (>100k rows) file in matplotlib .我想 plot matplotlib中的一个大(> 100k行)文件。 When I do it for the first time, I get the result I need.当我第一次这样做时,我得到了我需要的结果。 However, if I restart and rerun kernel, plt.show() infinitely loads memory and does not show the graph.但是,如果我重新启动并重新运行 kernel, plt.show()会无限加载 memory 并且不显示图表。

Tried restarting Jupyter Notebook and Anaconda, the problem remains.尝试重启 Jupyter Notebook 和 Anaconda,问题依旧。

import pandas as pd
import matplotlib.pyplot as plt

dataset = f'data/data_name.csv'
df = pd.read_csv(dataset)

pd.options.display.float_format = '{:.2f}'.format
df.set_index('time', inplace=True)

plt.figure(figure=18,6))
plt.plot(df['some_column']
plt.show()

From this moment, an instance of Python appears in processes, and it starts to consume memory with no end.从这一刻起,进程中出现了一个 Python 的实例,它开始无休止地消耗 memory。

Thank you in advance.先感谢您。

It appears the memory on your machine is being overwhelmed by the size of the plot and is crashing your kernel.您机器上的 memory 似乎被 plot 的大小所淹没,并且正在使您的 kernel 崩溃。 I'd suggest plotting fewer datapoints using df.sample(n=10**4, random_state=1) .我建议使用df.sample(n=10**4, random_state=1)绘制更少的数据点。 If your data is massive and nicely distributed, taking a sample should reduce the memory and allow for more rapid plotting.如果您的数据量大且分布良好,则取样应减少 memory 并允许更快地绘制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM