import pandas as pd import numpy as np from pyecharts.charts import Map from pyecharts import options as opts # 读取数据文件 data = pd.read_csv('各省高考人数2.0.csv', encoding='utf-8') maps=( Map(opts.InitOpts(width="1400px",height="700px",theme='westeros')) .add("省份",#系列名称 [list(i) for i in zip (data['省份'],data['人数/万'])], "china", is_map_symbol_show=False,#省份处不显示小红点 ) .set_global_opts( title_opts=opts.TitleOpts(title="2023年各省高考人数",#标题 title_textstyle_opts==optsTextStyleOpts(font_size=20),#字体大小 pos_left='20%', pos_top='5%'),#标题位置 legend_opts=opts.LegendOpts(is_show=False),#不显示图例 visualmap_opts=opts.VisualMapOpts(max_=150.0, is_piecewise=True, split_number=4,#将数据分为四段 range_text=['人数/万',''],#图例显示文字单位 range_color=["#d9ecf2","#a2d5f2","#e8ffc1","#a5ecd7"], pos_left='20%', pos_top='70%', ), )) maps.render("./2023各省高考人数.html")显示positional argument follows keyword argument帮我修改一下程序
时间: 2024-03-23 20:38:50 浏览: 357
在代码中,出现了位置参数放在关键字参数之后的错误,需要将参数的顺序更改。修改后的程序如下:
```python
import pandas as pd
import numpy as np
from pyecharts.charts import Map
from pyecharts import options as opts
# 读取数据文件
data = pd.read_csv('各省高考人数2.0.csv', encoding='utf-8')
maps=(
Map(init_opts=opts.InitOpts(width="1400px",height="700px",theme='westeros'))
.add("省份",#系列名称
[list(i) for i in zip (data['省份'],data['人数/万'])], "china",
is_map_symbol_show=False,#省份处不显示小红点
)
.set_global_opts(
title_opts=opts.TitleOpts(title="2023年各省高考人数",#标题
pos_left='20%', pos_top='5%',
title_textstyle_opts=opts.TextStyleOpts(font_size=20),#字体大小
),#标题位置
legend_opts=opts.LegendOpts(is_show=False),#不显示图例
visualmap_opts=opts.VisualMapOpts(max_=150.0,
is_piecewise=True, split_number=4,#将数据分为四段
range_text=['人数/万',''],#图例显示文字单位
range_color=["#d9ecf2","#a2d5f2","#e8ffc1","#a5ecd7"],
pos_left='20%', pos_top='70%',
),
)
)
maps.render("./2023各省高考人数.html")
```
修改后的代码中,将初始化 Map 对象时的参数位置更改为关键字参数的形式,并且在设置标题时,将位置参数放到了关键字参数之前。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)