在 Jupyter Lab Notebook 中绘图时出现 Matplotlib 断言错误

问题描述 投票:0回答:1

我在 jupyter 实验室内运行 pandas 绘图命令时收到此错误。

有谁知道是什么问题吗?

AssertionError                            Traceback (most recent call last)
Cell In[9], line 1
----> 1 a2_data.boxplot(column=['MinTemp', 'MaxTemp', 'Rainfall', 'Evaporation', 'WindGustSpeed', 'WindSpeed9am', 'WindSpeed3pm', 'Humidity9am', 'Humidity3pm', 'Temp9am','Temp3pm'],rot=90);

File C:\Program Files\Python312\Lib\site-packages\pandas\plotting\_core.py:533, in boxplot_frame(self, column, by, ax, fontsize, rot, grid, figsize, layout, return_type, backend, **kwargs)
    516 @Substitution(data="", backend=_backend_doc)
    517 @Appender(_boxplot_doc)
    518 def boxplot_frame(
   (...)
    530     **kwargs,
    531 ):
    532     plot_backend = _get_plot_backend(backend)
--> 533     return plot_backend.boxplot_frame(
    534         self,
    535         column=column,
    536         by=by,
    537         ax=ax,
    538         fontsize=fontsize,
    539         rot=rot,
    540         grid=grid,
    541         figsize=figsize,
    542         layout=layout,
    543         return_type=return_type,
    544         **kwargs,
    545     )

File C:\Program Files\Python312\Lib\site-packages\pandas\plotting\_matplotlib\boxplot.py:492, in boxplot_frame(self, column, by, ax, fontsize, rot, grid, figsize, layout, return_type, **kwds)
    477 def boxplot_frame(
    478     self,
    479     column=None,
   (...)
    488     **kwds,
    489 ):
    490     import matplotlib.pyplot as plt
--> 492     ax = boxplot(
    493         self,
    494         column=column,
    495         by=by,
    496         ax=ax,
    497         fontsize=fontsize,
    498         grid=grid,
    499         rot=rot,
    500         figsize=figsize,
    501         layout=layout,
    502         return_type=return_type,
    503         **kwds,
    504     )
    505     plt.draw_if_interactive()
    506     return ax

File C:\Program Files\Python312\Lib\site-packages\pandas\plotting\_matplotlib\boxplot.py:471, in boxplot(data, column, by, ax, fontsize, rot, grid, figsize, layout, return_type, **kwds)
    468     else:
    469         data = data[columns]
--> 471     result = plot_group(columns, data.values.T, ax, **kwds)
    472     ax.grid(grid)
    474 return result

File C:\Program Files\Python312\Lib\site-packages\pandas\plotting\_matplotlib\boxplot.py:414, in boxplot.<locals>.plot_group(keys, values, ax, **kwds)
    411     ax.tick_params(axis="both", labelsize=fontsize)
    413 # GH 45465: x/y are flipped when "vert" changes
--> 414 _set_ticklabels(
    415     ax=ax, labels=keys, is_vertical=kwds.get("vert", True), rotation=rot
    416 )
    417 maybe_color_bp(bp, color_tup=colors, **kwds)
    419 # Return axes in multiplot case, maybe revisit later # 985

File C:\Program Files\Python312\Lib\site-packages\pandas\plotting\_matplotlib\boxplot.py:57, in _set_ticklabels(ax, labels, is_vertical, **kwargs)
     55 if len(ticks) != len(labels):
     56     i, remainder = divmod(len(ticks), len(labels))
---> 57     assert remainder == 0, remainder
     58     labels *= i
     59 if is_vertical:

AssertionError: 3

我已经多次重新启动内核,我的电脑,并且还更改了后端配置以使用qt5agg,但无济于事。 (更正:是的,将其改回内联,因为 qt5agg 只是将它们作为单独的窗口吐出)这之前一切正常。

我希望这些图能够内联生成,在我拥有的每个代码块之后生成一个。其他 pandas 函数工作正常,它只是专门用于 matplotlib 的绘图。

这是按代码块执行顺序排列的代码片段。

import pandas as pd
import numpy as np

a2_data = pd.read_csv("13545429.csv")
a2_data.sample(10)

a2_data.boxplot(column=['MinTemp', 'MaxTemp', 'Rainfall', 'Evaporation', 'WindGustSpeed', 'WindSpeed9am', 'WindSpeed3pm', 'Humidity9am', 'Humidity3pm', 'Temp9am', 'Temp3pm'],rot=90);

仅此而已。

将命令更改为单列会导致空白输出

a2_data.boxplot(column='Pressure9am')

输出

<Axes: >

python pandas matplotlib plot
1个回答
0
投票

突然之间,它就可以工作了。我认为这是因为我安装了 Pandoc Python 模块而没有实际安装 Pandoc 本身(我没有意识到它是 Python 之外的一个单独的程序。看起来 Python Pandoc 模块搞乱了绘图,尽管我不确定如何.

© www.soinside.com 2019 - 2024. All rights reserved.