Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在jupyter笔记本中保存熊猫的绘图_Python_Pandas_Matplotlib_Jupyter Notebook_Pandas Groupby - Fatal编程技术网

Python 在jupyter笔记本中保存熊猫的绘图

Python 在jupyter笔记本中保存熊猫的绘图,python,pandas,matplotlib,jupyter-notebook,pandas-groupby,Python,Pandas,Matplotlib,Jupyter Notebook,Pandas Groupby,我试图在jupyter笔记本中保存熊猫数据帧的绘图,但我得到了一个72字节大小的空白图像 以下是我正在使用的代码: EperDtDF = spark.sql("SELECT timestamp, data.ldr from deviceData where timestamp >= '2018-05-01T00:00:00+02:00' and timestamp < '2018-05-07T23:59:59+02:00'") EperDtDF.cache()

我试图在jupyter笔记本中保存熊猫数据帧的绘图,但我得到了一个72字节大小的空白图像

以下是我正在使用的代码:

    EperDtDF = spark.sql("SELECT timestamp, data.ldr from deviceData where timestamp >= '2018-05-01T00:00:00+02:00' and timestamp < '2018-05-07T23:59:59+02:00'")
    EperDtDF.cache()
    EperDtPanda = EperDtDF.toPandas().set_index('timestamp')
    slice = EperDtPanda[0:4321].plot() # slice of first 6h (double of previous calculation)

    fig = slice.get_figure()
    fig.savefig('test2', format='png')
创建的文件就在那里,名称正确,但只有72个字节,我无法打开它,因为它是一个空白图像


如何保存正确显示的绘图

生成文件名时也会发生这种情况吗?您可以尝试将matplotlib.pyplot作为plt导入,而不是最后两行:plt.savefig'test2.png'将.png手动添加到文件名将解决此问题。使用字符串作为文件名(不带扩展名)并设置格式,这是可以复制的。不幸的是,上述注释都没有帮助:-/