【发布时间】:2016-11-15 12:03:02
【问题描述】:
我想将 pandas 直方图绘制到一个轴上,但这种行为真的很奇怪。我不知道这里出了什么问题。
fig1, ax1 = plt.subplots(figsize=(4,3))
fig2, ax2 = plt.subplots(figsize=(4,3))
fig3, ax3 = plt.subplots(figsize=(4,3))
# 1. This works
df['speed'].hist()
# 2. This doens't work
df['speed'].hist(ax=ax2)
# 3. This works
data = [1,2,3,5,6,2,3,4]
temp_df = pd.DataFrame(data)
temp_df.hist(ax=ax2)
jupyter notebook 返回的错误是:
AssertionError Traceback (most recent call last)
<ipython-input-46-d629de832772> in <module>()
7
8 # This doens't work
----> 9 df['speed'].hist(ax=ax2)
10
11 # # This works
D:\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in hist_series(self, by, ax, grid, xlabelsize, xrot, ylabelsize, yrot, figsize, bins, **kwds)
2953 ax = fig.gca()
2954 elif ax.get_figure() != fig:
-> 2955 raise AssertionError('passed axis not bound to passed figure')
2956 values = self.dropna().values
2957
AssertionError: passed axis not bound to passed figure
熊猫源代码在这里:
完全不知道我的代码有什么问题。
【问题讨论】:
-
我在尝试将 Pandas.hist() 图显示到 PyQt5 Ui 时也遇到了同样的问题。真令人沮丧。建议的解决方案均无效。
标签: python pandas matplotlib jupyter-notebook