python 科研柱状图翻转
时间: 2023-11-06 21:57:02 浏览: 141
python的柱状图,绘制漂亮
在pyecharts中,要实现柱状图翻转,可以通过修改x轴数据和y轴数据的位置来实现。具体操作是将x轴数据赋值给y轴,将y轴数据赋值给x轴。下面是翻转后的代码示例:
```python
from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.globals import ThemeType
data_x = ['0天', '1天', '2天', '3天', '4天', '5天', '6天', '7天', '8天', '9天', '10天', '11天', '12天', '13天', '14天', '15天', '16天', '17天', '18天', '19天', '20天', '21天', '22天', '23天', '24天', '25天', '26天', '27天', '28天', '29天']
data_y = [5, 27, 27, 7, 13, 5, 1, 2, 29, 20, 21, 28, 5, 22, 23, 4, 20, 26, 25, 1, 3, 14, 23, 11, 4, 8, 2, 22, 13, 22]
c = (
Bar({"theme": ThemeType.MACARONS})
.add_xaxis(data_y) # 将原来的x轴数据赋值给y轴
.add_yaxis("商家A", data_x) # 将原来的y轴数据赋值给x轴
.set_global_opts(
title_opts=opts.TitleOpts(title="标题"),
datazoom_opts=opts.DataZoomOpts(orient="vertical"),
)
.render("翻转柱状图.html")
)
print("图表已生成!请查收!")
```
阅读全文