from pyecharts.charts import WordCloud from pyecharts.globals import SymbolType,ThemeType from IPython.display import IFrame data4 = data[['户型']].value_counts() # 查看售卖房屋频率较高的小区 c = ( WordCloud(init_opts=opts.InitOpts(width='800px', height='600px', theme=ThemeType.ROMANTIC)) .add(data['户型'], [list(z) for z in zip(data4.index.tolist(), data4.values.tolist())], word_size_range=[20, 80]) .set_global_opts(title_opts=opts.TitleOpts(title='出售房屋数量的各小区', title_textstyle_opts=opts.TextStyleOpts(font_size=23)), tooltip_opts=opts.TooltipOpts(formatter='{b}: {c}')) .set_series_opts(label_opts=opts.LabelOpts(font_size=6, font_family='Microsoft YaHei')) ) c.render('D:/爬虫/二手房/广州二手房户型数量的词云图.html') c.render_notebook() print(list(z) for z in zip(data4.index.tolist(), data4.values.tolist())) print('D:/爬虫/二手房/广州二手房户型数量的词云图.html') IFrame("D:/爬虫/二手房/广州二手房户型数量的词云图.html", width=800, height=600)为什么使用此代码网页中只显示标题,没有词云图,可以怎么改正
时间: 2024-03-25 13:37:46 浏览: 12
您的代码中缺少 `opts` 模块的导入,因此在 `c` 对象的设置中会出现错误。请添加以下代码导入 `opts` 模块:
```python
from pyecharts import options as opts
```
此外,您可以尝试将字体大小调大一些,以便更好地显示词云图。例如,将 `label_opts` 中的 `font_size` 设置为 16:
```python
label_opts=opts.LabelOpts(font_size=16, font_family='Microsoft YaHei')
```
最后,请确保您在 Jupyter Notebook 中正确地加载了 HTML 文件。可以使用 `IFrame` 函数加载 HTML 文件,如下所示:
```python
from IPython.display import IFrame
IFrame("D:/爬虫/二手房/广州二手房户型数量的词云图.html", width=800, height=600)
```
综上所述,您可以尝试以下修正代码:
```python
from pyecharts.charts import WordCloud
from pyecharts.globals import SymbolType, ThemeType
from pyecharts import options as opts
from IPython.display import IFrame
data4 = data[['户型']].value_counts()
c = (
WordCloud(init_opts=opts.InitOpts(width='800px', height='600px', theme=ThemeType.ROMANTIC))
.add('出售房屋数量的各小区', [list(z) for z in zip(data4.index.tolist(), data4.values.tolist())], word_size_range=[20, 80])
.set_global_opts(title_opts=opts.TitleOpts(title='出售房屋数量的各小区', title_textstyle_opts=opts.TextStyleOpts(font_size=23)),
tooltip_opts=opts.TooltipOpts(formatter='{b}: {c}'))
.set_series_opts(label_opts=opts.LabelOpts(font_size=16, font_family='Microsoft YaHei'))
)
c.render('D:/爬虫/二手房/广州二手房户型数量的词云图.html')
IFrame("D:/爬虫/二手房/广州二手房户型数量的词云图.html", width=800, height=600)
```
如果问题仍然存在,您可以检查 HTML 文件是否存在以及路径是否正确。