【问题标题】:Why I can't use matplotlib.pyplot in Spyder?为什么我不能在 Spyder 中使用 matplotlib.pyplot?
【发布时间】:2015-04-02 09:14:42
【问题描述】:

我正在参加在线课程。在练习中,我必须绘制两个直方图来比较下雨和不下雨的乘客,这是我在在线课程中使用的代码。

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

它在在线课程的网页上运行完美,但是当我安装 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

为什么?

【问题讨论】:

    标签: python pandas anaconda


    【解决方案1】:

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

    conda install pandas
    

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

    更多信息请参见github上release notes of 0.15.0pull request 7809的增强部分。

    【讨论】:

    • 我仍然有这个问题。我安装了matplotlib,甚至遵循了上面建议的解决方案,但它对我不起作用:import matplotlib.pyplot as plt Traceback(最近一次调用最后):文件“”,第 1 行,在 import matplotlib.pyplot as plt ModuleNotFoundError: No module named 'matplotlib'
    猜你喜欢
    • 2019-07-31
    • 2017-07-25
    • 2017-09-05
    • 2021-05-20
    • 2012-05-02
    • 2017-03-30
    • 2015-09-03
    • 2017-03-29
    • 2021-02-06
    相关资源
    最近更新 更多