问题:利用pyecharts绘图,有时候我们的x轴标签名比较长,发现会被挤出去,就算调整x轴标签旋转45°都没用,那么该如何解决该问题呢?
利用Gird解决dataZoom与x轴标签重叠问题
pyecharts 版本1.5.1
from pyecharts import options as opts
from pyecharts.charts import Bar,Grid
import random
x = [
"名字很长的x轴1",
"名字很长的x轴2",
"名字很长的x轴3",
"名字很长的x轴4",
"名字很长的x轴5",
"名字很长的x轴6",
"名字很长的x轴7",
"名字很长的x轴8",
"名字很长的x轴9",
]
y = [random.randint(10,90) for x in range(10)]
grid = Grid()
bar = Bar("利用Gird解决dataZoom与x轴标签重叠问题")
bar.add(
"",
x,
y,
is_datazoom_show = True,
xaxis_interval=0,
xaxis_rotate=30
)
# 将bar 图添加到grid中,并调整grid_bottom 参数,使bar图上移25%
grid.add(bar, grid_opts=opts.GridOpts(pos_bottom="25%"))
grid.render()