python - 为什么我不能在 Spyder 中使用 matplotlib.pyplot?

标签 python pandas anaconda

我正在上在线类(class)。在练习中,我必须绘制两个直方图来比较雨天和无雨天的乘客量,这是我在在线类(class)中使用的代码。

import numpy as np
import pandas
import matplotlib.pyplot as plt

def entries_histogram(turnstile_weather):

    plt.figure()
    ax = turnstile_weather['ENTRIESn_hourly'][turnstile_weather['rain'] == 0].plot(kind = 'hist', title = 'Histogram of ENTRIESn_hourly', bins = 30)
    turnstile_weather['ENTRIESn_hourly'][turnstile_weather['rain'] == 1].plot(kind = 'hist', bins = 30, ax=ax)
    ax.set_ylabel('Frequency')
    ax.set_xlabel('ENTRIESn_hourly')
    return plt

它在在线类(class)的网页上运行完美,但是当我安装 Anaconda 并使用 Spyder 软件运行完全相同的代码时。它向我显示错误:

C:\Anaconda3\lib\site-packages\pandas\tools\plotting.py in plot_series(series, label, kind, use_index, rot, xticks, yticks, xlim, ylim, ax, style, grid, legend, logx, logy, secondary_y, **kwds)
   2231         klass = _plot_klass[kind]
   2232     else:
-> 2233         raise ValueError('Invalid chart type given %s' % kind)
   2234 
   2235     """

ValueError: Invalid chart type given hist

为什么?

最佳答案

快速回答:您可以通过将 pandas 更新到最新版本来解决问题:

conda install pandas

kind='hist' 选项已添加到版本 0.15.0Series.plot() 中。您的代码示例应适用于最新版本 0.15.2

有关详细信息,请参阅 release notes of 0.15.0 的增强部分和 pull request 7809在 github 上。

关于python - 为什么我不能在 Spyder 中使用 matplotlib.pyplot?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28294446/

相关文章:

python - 通过 Postman 将 JSON 数据发布到 FastAPI 后端时,值不是有效的字典

Python 在 Flash 应用程序中模拟按键

python - Anaconda:如何安装不在 Anaconda 目录中的软件包?

python - 使用predict_generator和VGG16的内存错误

python - 如何在pygame中使用其他字体?

python - 如何证明(左) Pandas 数据框中的一列字符串?

python - 根据 Pandas 上的多个键列减去值

python - dfply:变异字符串列:TypeError

python - 执行 "import tensorflow.keras.utils.np_utils"时出错

python - 使用 conda-forge 作为 Anaconda 的默认 channel 在 Mac Pro M1 上安装软件包