pyecharts.charts.Boxplot.add_yaxis()的参数介绍
时间: 2023-03-26 16:01:05 浏览: 323
add_yaxis() 方法是 Pyecharts 中 Boxplot 类的一个方法,用于向图表中添加一个数据系列。它的参数介绍如下:
- name:数据系列的名称,字符串类型。
- y_axis:数据系列的数据,列表类型。
- tooltip_opts:数据系列的提示框配置项,字典类型。
- label_opts:数据系列的标签配置项,字典类型。
其中,name 和 y_axis 是必填参数,tooltip_opts 和 label_opts 是可选参数。
相关问题
import pandas as pd from pyecharts.charts import Boxplot # 读取csv文件 data = pd.read_csv('kag_risk_factors_cervical_cancer(1).csv') # 去掉空值 data = data.dropna() # 构造数据 values = [] for column_name in data.columns[2:]: values.append(list(data[column_name])) # 绘制箱型图 boxplot = ( Boxplot() .add_xaxis(list(data.columns[2:])) .add_yaxis("", box_data=values) .set_global_opts(title_opts=opts.TitleOpts(title="Risk Factors of Cervical Cancer")) ) # 显示图表 boxplot.render_notebook() TypeError: add_yaxis() got an unexpected keyword argument 'data_pair'怎么解决
这个错误是因为 pyecharts 最新版本更新了 add_yaxis() 函数,将原来的 data_pair 参数改为了 box_data。你需要将代码中的 data_pair 改为 box_data,如下所示:
```
import pandas as pd
from pyecharts.charts import Boxplot
# 读取csv文件
data = pd.read_csv('kag_risk_factors_cervical_cancer(1).csv')
# 去掉空值
data = data.dropna()
# 构造数据
values = []
for column_name in data.columns[2:]:
values.append(list(data[column_name]))
# 绘制箱型图
boxplot = (
Boxplot()
.add_xaxis(list(data.columns[2:]))
.add_yaxis("", box_data=values) # 将 data_pair 改为 box_data
.set_global_opts(title_opts=opts.TitleOpts(title="Risk Factors of Cervical Cancer"))
)
# 显示图表
boxplot.render_notebook()
```
这样就可以成功绘制箱型图了。
来几个pyecharts.charts.Boxplot的例子
好的,以下是几个pyecharts.charts.Boxplot的例子:
1.
```python
from pyecharts.charts import Boxplot
data = [
[850, 740, 900, 107, 930, 850, 950, 980, 980, 880],
[960, 940, 960, 940, 880, 800, 850, 880, 900],
[880, 880, 880, 860, 720, 720, 620, 860, 970],
[890, 810, 810, 820, 800, 770, 760, 740, 750],
]
boxplot = Boxplot()
boxplot.add_xaxis(["A", "B", "C", "D"])
boxplot.add_yaxis("boxplot", boxplot.prepare_data(data))
boxplot.set_global_opts(title_opts=opts.TitleOpts(title="Boxplot"))
boxplot.render("boxplot.html")
```
2.
```python
from pyecharts.charts import Boxplot
data = [
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
[820, 932, 901, 934, 129, 133, 132],
]
boxplot = Boxplot()
boxplot.add_xaxis(["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T"])
boxplot.add_yaxis("boxplot", boxplot.prepare_data(data))
boxplot.set_global_opts(title_opts=opts.TitleOpts(title="Boxplot"))
boxplot.render("boxplot.html")
```
希望这些例子能够帮助到你!
阅读全文