pyecharts 展示折线图时,有时会遇到X轴标签过多而显示不齐的情况。
比如这样
1
2
|
Name: pyecharts Version: 1.7 . 1 |
最关键就是这句
1
|
line.set_global_opts(xaxis_opts = opts.AxisOpts(name_rotate = 60 , axislabel_opts = { "rotate" : 15 })) |
如果是高版本的 pyecharts ,代码可能有所不同。
1
2
3
4
5
6
7
8
9
10
|
import pyecharts.options as opts from pyecharts.charts import Line line = Line() line.set_global_opts(title_opts = opts.TitleOpts(title = "豆瓣影评人数top10电影" )) line.add_xaxis([ "肖申克的救赎" , "这个杀手不太冷" , "千与千寻" , "阿甘正传" , "霸王别姬" , "泰坦尼克号" , "我不是药神" , "盗梦空间" , "三傻大闹宝莱坞" , "疯狂动物城" ] ) line.add_yaxis( "影片评价人数top10" , [ 2529510 , 2060322 , 1981694 , 1900413 , 1880377 , 1862155 , 1847187 , 1825058 , 1659816 , 1657343 ]) line.set_global_opts(xaxis_opts = opts.AxisOpts(name_rotate = 60 , axislabel_opts = { "rotate" : 15 })) line.render( "top10折线图.html" ) |
显示效果如下
echarts X轴旋转30°
上代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
xAxis: { type : 'category' , axisLabel: { rotate: 30 , / / 旋转 30 度 show: true, / / 这行代码控制着坐标轴x轴的文字是否显示 textStyle: { color: '#fff' , / / x轴上的字体颜色 fontSize: '12' / / x轴字体大小 } }, boundaryGap: false, data: [ '3-04' , '3-05' , '3-06' , '3-07' , '3-08' ] }, |
-
扫码下载安卓APP
-
微信扫一扫关注我们
微信扫一扫打开小程序
手Q扫一扫打开小程序
-
返回顶部
友情链接:
6547题库网 |
Scratch从入门到精通|
Copyright © 小码农 |
2020-2022
发表评论