我想将三组数据放到一个表里,这三组数据具有不同的日期和数值(可能存在重合),但是我的图表打印出来后,图表的X轴上的日期只显示了一个,坐标点也只有一个。图片在代码下面
import pyecharts.options as opts
from pyecharts.charts import Line
import requests
import re
import json
head={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36 Edg/95.0.1020.53'}
req=requests.get('http://money.finance.sina.com.cn/forex/api/jsonp.php/SINAREMOTECALLCALLBACK.CALLBACK_1637050185601883563512783069/FusionChart_Service.getForexChartInfo?country=%D6%D0%B9%FA&event=%B2%C6%D0%C2%D7%DB%BA%CFPMI&datefrom=2017-03-03&dateto=2021-11-0-3&allinfo=1&npp=20&page=1'
,headers=head)
freq=requests.get('http://money.finance.sina.com.cn/forex/api/jsonp.php/SINAREMOTECALLCALLBACK.CALLBACK_163737461216346743293146016707/FusionChart_Service.getForexChartInfo?country=%D6%D0%B9%FA&event=%B2%C6%D0%C2%B7%FE%CE%F1%D2%B5PMI&datefrom=2017-03-03&dateto=2021-11-0-3&allinfo=1&npp=20&page=1'
,headers=head)
zreq=requests.get('http://money.finance.sina.com.cn/forex/api/jsonp.php/SINAREMOTECALLCALLBACK.CALLBACK_1637374612163737673381537736465096858196/FusionChart_Service.getForexChartInfo?country=%D6%D0%B9%FA&event=%B2%C6%D0%C2%D6%C6%D4%EC%D2%B5PMI&datefrom=2017-03-03&dateto=2021-11-0-3&allinfo=1&npp=20&page=1',
headers=head)
req=req.text
freq=freq.text
zreq=zreq.text
x=req[118:2642]
f=freq[120:2700]
z=zreq[130:2712]
#print(f)
#print(x)
#print(z)
listx=json.loads(x)
listf=json.loads(f)
listz=json.loads(z)
#print(listx)
for i in listx:
riqi=i['date']
shuzhi=i['ifr_actual']
for o in listf:
friqi=o['date']
fshuzi=o['ifr_actual']
for t in listz:
zriqi=t['date']
zshuzhi=t['ifr_actual']
#以上为获取数据
x_data=[riqi]
y_data=[shuzhi]
fx_data=[friqi]
fy_data=[fshuzi]
zx_data=[zriqi]
zy_data=[zshuzhi]
以下为作图:
(
Line()
.add_xaxis(xaxis_data=x_data)
.add_yaxis(
series_name="中国财新综合PMI",
stack="总量",
y_axis=(y_data),
label_opts=opts.LabelOpts(is_show=False),
)
.add_xaxis(xaxis_data=fx_data)
.add_yaxis(
series_name="中国财新服务业PMI",
stack="总量",
y_axis=(fy_data),
label_opts=opts.LabelOpts(is_show=False),
)
.add_xaxis(xaxis_data=zx_data)
.add_yaxis(
series_name="财新制造业PMI",
stack="总量",
y_axis=(zy_data),
label_opts=opts.LabelOpts(is_show=False),
)
.set_global_opts(
title_opts=opts.TitleOpts(title="折线图堆叠"),
tooltip_opts=opts.TooltipOpts(trigger="axis"),
yaxis_opts=opts.AxisOpts(
type_="value",
axistick_opts=opts.AxisTickOpts(is_show=True),
splitline_opts=opts.SplitLineOpts(is_show=True),
),
xaxis_opts=opts.AxisOpts(type_="category", boundary_gap=False),
)
.render("stacked_line_chart.html")
)
没有报错,但是:
希望能把三组数据好好的显示出来。望指教。
你添加了3次x轴, 这里面只需要一个x轴吧