嵌套列表的计数问题; matplotlib如何平铺图像
将IBM收盘价序列分为5个长度一段(共400段),利用可见图算法将生成每段图,并统计400段中重复出现次数最多的一个图。
import networkx as nx import pandas as pd
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
djitt = pd.read_csv('DJITT.csv')
pd.options.display.max_columns = None
ibm = djitt["IBM"].to_list()
ibm = ibm[:2000]
ibm_sliced = [ibm[i:i + 5] for i in range(0, len(ibm), 5)]
def vg(series):
temp=np.zeros(shape=(100,2))
n=len(series)
for i in range(2,n+1):
temp[i-1,0]=i-1
temp[i-1,1]=i
nnn1=n-1
for i in range(1,n-1):
for j in range(i+2,n+1):
poke=1
slope0=float((series[j-1]-series[i-1]))/(j-i)
for k in range(i+1,j):
if float((series[k-1]-series[i-1]))/(k-i)<slope0:
poke=poke*1
else:
poke=poke*0
if poke==1:
nnn1=nnn1+1
temp[nnn1,0]=i
temp[nnn1,1]=j
return temp
for series in ibm_sliced:
Re=vg(series)
Re=pd.DataFrame(Re)
Re=Re.loc[~(Re==0).all(axis=1), :] # 删了全为0的行
g1.append(Re)
Re=np.array(Re)
gg1=list(Re)
G=nx.Graph(gg1)
nx.draw_networkx(G,node_size = 400)
首先,画出来的图像都堆在一起,要如何将400张图分成比如10x40的分布状;
其次,要如何统计相同结果图出现的次数呢?
以上是 嵌套列表的计数问题; matplotlib如何平铺图像 的全部内容, 来源链接: utcz.com/p/937979.html