gpt4 book ai didi

python - Pandas 在 Windows 终端中绘图

转载 作者:太空狗 更新时间:2023-10-29 22:21:40 25 4
gpt4 key购买 nike

我有一个简单的 Pandas 数据框。尝试从 IPython 的 Windows 10 终端 session 进行绘图给了我这个:

In [4]: df = pd.DataFrame({'Y':[1, 3, 5, 7, 9], 'X':[0, 2, 4, 6, 8]})

In [5]: df
Out[5]:
X Y
0 0 1
1 2 3
2 4 5
3 6 7
4 8 9

In [6]: df.plot(kind='line')
Out[6]: <matplotlib.axes._subplots.AxesSubplot at 0x26c4d366940>

In [7]:

我看不到任何情节。我做错了什么吗?

最佳答案

我认为您可以尝试为笔记本添加 %matplotlib inlineipython notebook --matplotlib inline:

%matplotlib inline
#ipython notebook --matplotlib inline
import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame({'Y':[1, 3, 5, 7, 9], 'X':[0, 2, 4, 6, 8]})

df.plot(kind='line')

或者您可以为控制台添加 plt.show():

import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame({'Y':[1, 3, 5, 7, 9], 'X':[0, 2, 4, 6, 8]})

df.plot(kind='line')
plt.show()

关于python - Pandas 在 Windows 终端中绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35594501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com