plt.show()不在Jupyter笔记本上渲染任何内容

2024-06-24 12:23:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Jupyter中得到了下面的代码,当前遵循的是关于DataCamp的教程,但是我的图没有生成

import matplotlib as mpl
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
plt.show()

seattle_weather_dic = {'MONTH':['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
                   'MLY-TAVG-NORMAL':[42.1,43.4,46.6,50.5,56.0,61.0,65.9,66.5,61.6,53.3,46.2,41.1]} 
seattle_weather = pd.DataFrame.from_dict(seattle_weather_dic) 
ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"])
plt.show()

Tags: 代码importmatplotlibasshowjupyterpltax
1条回答
网友
1楼 · 发布于 2024-06-24 12:23:53

试试这个:

%matplotlib inline
import matplotlib as mpl
import matplotlib.pyplot as plt
import pandas as pd
seattle_weather_dic = {'MONTH':['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
                   'MLY-TAVG-NORMAL':[42.1,43.4,46.6,50.5,56.0,61.0,65.9,66.5,61.6,53.3,46.2,41.1]} 
seattle_weather = pd.DataFrame.from_dict(seattle_weather_dic) 
fig,ax=plt.subplots()
ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL"])
plt.show()

我已经定义了ax,并在'MONTH'之后添加了一个:

相关问题 更多 >