[英]Pandas dataframe error: matplotlib.axes._subplots.AxesSubplot
import pandas as pd
import matplotlib.pyplot as plt
file = 'd:\\a\\pandas\\test.xlsx'
data = pd.ExcelFile(file)
df1 = data.parse('Link')
df2 = df1[['dataFor', 'total']]
df2
returns: 收益:
print (type(df2))
tells me 告诉我
class 'pandas.core.frame.DataFrame'
trying 试
df2.plot(kind='line')
returns 回报
matplotlib.axes._subplots.AxesSubplot at 0xe4241d0
Could it be the environment? 可能是环境吗?
Jupyter notebook > Help > About
The version of the notebook server is 4.2.3 and is running on:
Python 3.5.2 |Anaconda 4.2.0 (32-bit)| (default, Jul 5 2016, 11:45:57) [MSC v.1900 32 bit (Intel)]
Where is the fault? 故障在哪里? Is matplotlib still the standard or should beginners go for Bokeh or for both?
matplotlib仍然是标准还是初学者应该选择Bokeh还是两者兼而有之?
In case you want to see the plot inline, use 如果您想要内联查看绘图,请使用
%matplotlib inline
in the header (before the imports). 在标题中(在导入之前)。
If you want to show the graphic in a window, add the line 如果要在窗口中显示图形,请添加该行
plt.show()
at the end (make sure you have imported import matplotlib.pyplot as plt
in the header). 最后(确保您已导入
import matplotlib.pyplot as plt
标题中的import matplotlib.pyplot as plt
)。
## importing libraries
## notice to import %matplotlib inline to plot within notebook
import pandas as pd
%matplotlib inline
import matplotlib.pyplot as plt
import datetime
## making a DF like yours
df2 = pd.DataFrame([], columns=['dataFor','total'])
df2['dataFor'] = [datetime.datetime(2013, 9, 11),datetime.datetime(2013, 9, 12),datetime.datetime(2013, 9, 13),datetime.datetime(2013, 9, 14),datetime.datetime(2013, 9, 15),datetime.datetime(2013, 9, 16),datetime.datetime(2013, 9, 17)]
df2['total'] = [11,15,17,18,19,20,21]
## notice date are datetimes objects and not strings
df2.plot(kind='line')
output: 输出:
if one wants to improve graph layout: 如果想要改进图形布局:
plt.figure(figsize=(20,10))
plt.plot(df2.dataFor, df2.total, linewidth=5)
plt.plot(df2.dataFor, df2.total, '*', markersize=20, color='red')
plt.xticks(fontsize=20, fontweight='bold',rotation=90)
plt.yticks(fontsize=20, fontweight='bold')
plt.xlabel('Dates',fontsize=20, fontweight='bold')
plt.ylabel('Total Count',fontsize=20, fontweight='bold')
plt.title('Counts per time',fontsize=20, fontweight='bold')
plt.tight_layout()
I got the same problem on performing the plot but I got it solved by running the import clause followed by %matplotlib. 我在执行绘图时遇到了同样的问题,但我通过运行import子句后跟%matplotlib解决了问题。 I think I'm using the latest version.
我想我正在使用最新版本。 I've tried the " %matplotlib inline " but for some reasons, it doesn't work on my end.
我已经尝试了“%matplotlib内联”但由于某些原因,它不适用于我的目的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.