月K线图
from pyecharts.charts import Kline
import pyecharts.options as opts
import pandas as pd
df = pd.read_csv("stocks.csv",header=None)
df['Date'] = pd.to_datetime(df[0])
data = df[(df['Date']>=pd.Timestamp('2017-01-01'))&(df['Date']<=pd.Timestamp('2019-12-31'))]
data['年月'] = data[0].apply(lambda string:string[:-3])
def get_open(frame):
index = frame[frame[0]==frame[0].min()].index[0]
return frame.loc[index,1]
def get_close(frame):
index = frame[frame[0]==frame[0].max()].index[0]
return frame.loc[index,4]
def get_min(frame):
return frame[3].min()
def get_high(frame):
return frame[2].max()
monthFrame = pd.concat([data.groupby('年月').apply(get_open),data.groupby('年月').apply(get_close),
data.groupby('年月').apply(get_min),data.groupby('年月').apply(get_high)],axis=1).reset_index()
monthFrame.columns = ['month','开盘','收盘','最低','最高']
x = list(monthFrame['month'])
y = []
for i in range(len(x)):
y.append([monthFrame.loc[i,'开盘'],monthFrame.loc[i,'收盘'],monthFrame.loc[i,'最低'],monthFrame.loc[i,'最高']])
kl = (
Kline()
.add_xaxis(x)
.add_yaxis('股票价格走势(月线)',y)
.set_global_opts(title_opts=opts.TitleOpts(title='股票价格趋势分析',
subtitle='2017年1月至2019年12月'))
)
kl.render_notebook()
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210628162713594.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQyODM5ODkz,size_16,color_FFFFFF,t_70)
日历图
import random
from pyecharts.charts import Calendar
import datetime
date = pd.date_range("2020-01-01","2020-12-31",freq="D")
steps = [random.randint(3000,30000) for i in range(len(date))]
def time2str(time):
return datetime.datetime.strftime(time, "%Y-%m-%d")
data2 = list(zip(list(map(time2str,date)),steps))
c = (
Calendar(init_opts=opts.InitOpts(
theme='light',
width='720px',
height='240px'
)
)
.add('',data2,calendar_opts=opts.CalendarOpts(
range_=['2020-01-01','2020-12-31'],
daylabel_opts=opts.CalendarDayLabelOpts(name_map="cn"),
monthlabel_opts=opts.CalendarMonthLabelOpts(name_map="cn")
))
.set_global_opts(
title_opts=opts.TitleOpts(title='每天微信步数',subtitle='2020年1月至2020年12月'),
visualmap_opts=opts.VisualMapOpts(
min_=3000,
max_=30000,
orient='horizontal',
is_piecewise=True,
pos_left='center',
pos_top=210)
)
)
c.render_notebook()
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210628162723153.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQyODM5ODkz,size_16,color_FFFFFF,t_70)