pyecharts 不显示y轴刻度,可以多图显示
时间: 2023-09-30 11:03:26 浏览: 214
python多仪表盘pyecharts显示
如果 Pyecharts 不显示 Y 轴刻度,可能是因为 Y 轴刻度的范围太小,可以通过设置 Y 轴的 `min` 和 `max` 值来解决。例如:
```python
from pyecharts import options as opts
from pyecharts.charts import Line
x_data = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
y_data = [820, 932, 901, 934, 1290, 1330, 1320]
line = (
Line()
.add_xaxis(x_data)
.add_yaxis("Sales", y_data, label_opts=opts.LabelOpts(is_show=True))
.set_global_opts(
yaxis_opts=opts.AxisOpts(min_=800, max_=1400), # 设置 Y 轴范围
title_opts=opts.TitleOpts(title="Line Chart with Y-Axis Range") # 设置标题
)
)
line.render_notebook()
```
关于多图显示,可以使用 `Grid` 类实现。例如:
```python
from pyecharts import options as opts
from pyecharts.charts import Bar, Grid, Line
x_data = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
y_data1 = [820, 932, 901, 934, 1290, 1330, 1320]
y_data2 = [820, 932, 901, 934, 1290, 1330, 1320]
bar = (
Bar()
.add_xaxis(x_data)
.add_yaxis("Sales", y_data1, label_opts=opts.LabelOpts(is_show=True))
.set_global_opts(title_opts=opts.TitleOpts(title="Bar Chart"))
)
line = (
Line()
.add_xaxis(x_data)
.add_yaxis("Sales", y_data2, label_opts=opts.LabelOpts(is_show=True))
.set_global_opts(
yaxis_opts=opts.AxisOpts(min_=800, max_=1400), # 设置 Y 轴范围
title_opts=opts.TitleOpts(title="Line Chart with Y-Axis Range") # 设置标题
)
)
grid = (
Grid()
.add(bar, grid_opts=opts.GridOpts(pos_left="5%", pos_right="5%", height="50%"))
.add(line, grid_opts=opts.GridOpts(pos_left="5%", pos_right="5%", height="50%"))
)
grid.render_notebook()
```
这里使用了 `Bar` 和 `Line` 类创建了两个图表,然后使用 `Grid` 类将它们组合成一个网格。需要注意的是,在 `Grid` 类中需要为每个图表设置 `grid_opts` 参数,用于设置图表在网格中的位置和大小。
阅读全文