新手求教:调用pyecharts画图时,x轴未完全显示,因此想采用formatter回调函数将标签换行,(学习)代码如下,可是formatter回调函数,pyecharts文档中的几个参数.data/value/name/seriesName都测试了,没作用!甚至把回调函数设置为lambda x: '哈哈'+x+'哈哈'
后,在图上也没找到相关改动,求大佬们教教!!
def str_new_line(stri: str)->str:
s_new_line = ''
for i in range(len(stri.data)):
s_new_line += stri.data[i]
if i!=0 and i%4==0:
s_new_line += '\n'
return s_new_line
def draw_bar(top_10_cats, kind):
bar = (
Bar()
.add_xaxis(list(top_10_cats['Name']))
.add_yaxis('二手车价格', list(top_10_cats['Sec_price']))
.set_global_opts(
toolbox_opts=opts.ToolboxOpts(),
xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(
interval=0,
# rotate=45,
font_size=6,
color='auto',
formatter=str_new_line)),
title_opts=opts.TitleOpts(title='最具性价比二手车top10',
subtitle='类型{}'.format(kind))
)
)
return bar
你好,请问问题解决了么