我正在上在线类(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.0
的 Series.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/