当前位置:网站首页>Pyechart drawing multiple Y-axis line graphs
Pyechart drawing multiple Y-axis line graphs
2022-06-28 20:43:00 【Enter into self pleasure】
pyechart Draw multiple lines y Axonometric chart
Draw three polylines , And use different y Axis : Use the following data to draw a line chart , And set according to the unit y Axis
data :
x_data=['06-24 21:00','06-24 20:00','06-24 19:00','06-24 18:00', #x Axis
'06-24 17:00','06-24 16:00','06-24 15:00','06-24 14:00','06-24 13:00',
'06-24 12:00','06-24 11:00','06-24 10:00','06-24 09:00','06-24 08:00',
'06-24 07:00','06-24 06:00','06-24 05:00','06-24 04:00','06-24 03:00',
'06-24 02:00','06-24 01:00','06-24 00:00','06-23 23:00','06-23 22:00']
pm25=[20.0,24.0,26.0,24.0,21.0,19.0,19.0,18.0,17.0,16.0,19.0,21.0,23.0, #y0 Axis Company ug/m³
26.0,28.0,26.0,26.0,26.0,26.0,25.0,25.0,26.0,25.0,24.0,]
aqi=[52.0,94.0,116.0,138.0,139.0,133.0,128.0,120.0,112.0,110.0,105.0, #y1 Axis No unit
70.0,58.0,57.0,52.0,51.0,49.0,48.0,51.0,53.0,51.0,53.0,54.0,73.0,]
co=[0.434,0.444,0.52,0.519,0.495,0.49,0.508,0.503,0.498,0.499,0.55,0.642, #y2 Axis Company mg/m³
0.727,0.8,0.819,0.767,0.752,0.729,0.72,0.743,0.755,0.753,0.767,0.748,]
Adding y Use... For axis data yaxis_index Appoint y The index of the axis ,`
line.add_yaxis( # The first curve
series_name='PM2.5',
y_axis=pm25,
label_opts=opts.LabelOpts(is_show=False),
yaxis_index=0, # Set up y Index axis
is_smooth=True,
)
line.add_yaxis( # Add the second curve
series_name='AQI',
y_axis=aqi,
label_opts=opts.LabelOpts(is_show=False),
yaxis_index=1, # Set up y Index axis
is_smooth=True,
)
line.add_yaxis( # Add a third curve
series_name='CO',
y_axis=co,
label_opts=opts.LabelOpts(is_show=False),
yaxis_index=2, # Set up y Axis
is_smooth=True,
)
Use extend_axis Method add y Axis and specify format ,position Parameter settings add y Axis position ,position='left' For the left ,position='right' For the right ;offset Parameter settings y Distance between axes . Added y Axis index from yaxis_index=1 Start .yaxis_index=0 Mainly y Axis , stay set_global_opts Set its specific format in .
line.extend_axis(
yaxis=opts.AxisOpts(type_='value', position='right'))
line.extend_axis(
yaxis=opts.AxisOpts(
name='mg/m³',
type_='value',
position='left', offset=40))
design sketch :
All the code :
import pyecharts.options as opts
from pyecharts.charts import Line
x_data=['06-24 21:00','06-24 20:00','06-24 19:00','06-24 18:00', #x Axis
'06-24 17:00','06-24 16:00','06-24 15:00','06-24 14:00','06-24 13:00',
'06-24 12:00','06-24 11:00','06-24 10:00','06-24 09:00','06-24 08:00',
'06-24 07:00','06-24 06:00','06-24 05:00','06-24 04:00','06-24 03:00',
'06-24 02:00','06-24 01:00','06-24 00:00','06-23 23:00','06-23 22:00']
pm25=[20.0,24.0,26.0,24.0,21.0,19.0,19.0,18.0,17.0,16.0,19.0,21.0,23.0, #y0 Axis Company ug/m³
26.0,28.0,26.0,26.0,26.0,26.0,25.0,25.0,26.0,25.0,24.0,]
aqi=[52.0,94.0,116.0,138.0,139.0,133.0,128.0,120.0,112.0,110.0,105.0, #y1 Axis No unit
70.0,58.0,57.0,52.0,51.0,49.0,48.0,51.0,53.0,51.0,53.0,54.0,73.0,]
co=[0.434,0.444,0.52,0.519,0.495,0.49,0.508,0.503,0.498,0.499,0.55,0.642, #y2 Axis Company mg/m³
0.727,0.8,0.819,0.767,0.752,0.729,0.72,0.743,0.755,0.753,0.767,0.748,]
x_data=x_data[::-1] # In chronological order
pm25=pm25[::-1]
aqi=aqi[::-1]
co=co[::-1]
line=Line().add_xaxis(xaxis_data=x_data) # add to x Axis
line.add_yaxis( # The first curve
series_name='PM2.5',
y_axis=pm25,
label_opts=opts.LabelOpts(is_show=False),
yaxis_index=0, # Set up y Axis
is_smooth=True,
)
line.add_yaxis( # Add the second curve
series_name='AQI',
y_axis=aqi,
label_opts=opts.LabelOpts(is_show=False),
yaxis_index=1, # Set up y Axis
is_smooth=True,
)
line.add_yaxis( # Add a third curve
series_name='CO',
y_axis=co,
label_opts=opts.LabelOpts(is_show=False),
yaxis_index=2, # Set up y Axis
is_smooth=True,
)
line.extend_axis(
yaxis=opts.AxisOpts(type_='value', position='right'))
line.extend_axis(
yaxis=opts.AxisOpts(
name='mg/m³',
type_='value',
position='left', offset=40))
line.set_global_opts(
title_opts=opts.TitleOpts(title='24 Hourly air quality trend chart ',pos_top='top', pos_left='center'),
tooltip_opts=opts.TooltipOpts(trigger="axis"),
yaxis_opts=opts.AxisOpts(
name='ug/m³',
type_="value",
axistick_opts=opts.AxisTickOpts(is_show=True),
splitline_opts=opts.SplitLineOpts(is_show=True),
),
legend_opts=opts.LegendOpts(pos_top='40'),
xaxis_opts=opts.AxisOpts(type_="category", boundary_gap=False),)
line.render('li.html')
边栏推荐
猜你喜欢

Automatic operation and maintenance platform based on Apache APIs

【毕业季·进击的技术er】努力只能及格,拼命才能优秀!

方 差 分 析

Leetcode 36. 有效的数独(可以,一次过)
![[learning notes] Introduction to principal component analysis](/img/24/a760d1cd095a967ef258b623eb465c.png)
[learning notes] Introduction to principal component analysis

Bitbucket failed to pull the warehouse Using SSH

Apisik helps Middle East social software realize localized deployment

How to use dataant to monitor Apache apisex

数据标准化处理

2022 t elevator repair test question bank simulation test platform operation
随机推荐
LeetCode每日一题——30. 串联所有单词的子串
mysql-发生系统错误1067
Pie (poj3122) super detailed and easy to understand binary introduction
酷学院华少:如何在SaaS赛道里做成一家头部公司
Leetcode daily question - 515 Find the maximum value in each tree row
数据资产为王,如何解析企业数字化转型与数据资产管理的关系?
Input and output character data
阿里云 MSE 基于 Apache APISIX 的全链路灰度方案实践
Bitbucket failed to pull the warehouse Using SSH
不同框架的绘制神经网络结构可视化
Alibaba cloud MSE full link grayscale solution practice based on Apache apisik
学习太极创客 — MQTT 第二章(八)ESP8266 MQTT 用户密码认证
Is it safe to open a dig money account? Is it reliable?
方 差 分 析
APISIX 助力中东社交软件,实现本地化部署
开通挖财账号安全吗?是靠谱的吗?
RT-Thread线程同步与线程通信
应用实践 | 10 亿数据秒级关联,货拉拉基于 Apache Doris 的 OLAP 体系演进(附 PPT 下载)
Troubleshooting of pyinstaller failed to pack pikepdf
2022 welder (elementary) special operation certificate examination question bank and answers