Merge pull request #6 from Redsandyg/Redsandyg-patch-2
Update CoreDraw.py
This commit is contained in:
commit
02c928bf27
@ -71,22 +71,46 @@ class corePlt():
|
|||||||
self.row=params['row']
|
self.row=params['row']
|
||||||
self.col=params['col']
|
self.col=params['col']
|
||||||
self.name=params['name']
|
self.name=params['name']
|
||||||
|
if 'colorType' in params.keys():
|
||||||
|
self.colorType=params['colorType']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class coreDraw():
|
class coreDraw():
|
||||||
def __init__(self, data=[], needShow=False,subplot_titles={}):
|
def __init__(self, data=[],needShow=False):
|
||||||
self.data=self.getPlts(data)
|
self.data=self.getPlts(data)
|
||||||
self.needShow=needShow
|
self.needShow=needShow
|
||||||
self.subplot_titles=subplot_titles
|
|
||||||
self.ans=self.getAns()
|
self.ans=self.getAns()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def getBarColorList(self,l,colorType):
|
||||||
|
if colorType=='diffAbs':
|
||||||
|
ans=['green']
|
||||||
|
for i in range(1,len(l)):
|
||||||
|
if abs(l[i])>abs(l[i-1]):
|
||||||
|
ans.append('green')
|
||||||
|
else:
|
||||||
|
ans.append('red')
|
||||||
|
elif colorType=='diff':
|
||||||
|
ans=['green']
|
||||||
|
for i in range(1,len(l)):
|
||||||
|
if (l[i])>(l[i-1]):
|
||||||
|
ans.append('green')
|
||||||
|
else:
|
||||||
|
ans.append('red')
|
||||||
|
elif colorType=='normal':
|
||||||
|
ans=[]
|
||||||
|
for i in range(len(l)):
|
||||||
|
ans.append('gray')
|
||||||
|
return ans
|
||||||
|
|
||||||
def getPlts(self, data):
|
def getPlts(self, data):
|
||||||
ans=None
|
ans=None
|
||||||
|
|
||||||
@ -132,17 +156,16 @@ class coreDraw():
|
|||||||
rows=maxRow,
|
rows=maxRow,
|
||||||
cols=maxCol,
|
cols=maxCol,
|
||||||
shared_xaxes=True,
|
shared_xaxes=True,
|
||||||
#vertical_spacing=0.2,
|
vertical_spacing=0.02,
|
||||||
shared_yaxes=True,
|
shared_yaxes=True,
|
||||||
#horizontal_spacing=0.2,
|
horizontal_spacing=0.02,
|
||||||
#column_widths=[]
|
#column_widths=[]
|
||||||
subplot_titles=self.subplot_titles
|
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
fig.update_layout(xaxis_rangeslider_visible=False)
|
fig.update_layout(xaxis_rangeslider_visible=False)
|
||||||
|
fig.update_layout(barmode='relative')
|
||||||
|
|
||||||
for i in self.data:
|
for i in self.data:
|
||||||
if i.vtype=='Scatter':
|
if i.vtype=='Scatter':
|
||||||
@ -157,6 +180,16 @@ class coreDraw():
|
|||||||
name=i.name),
|
name=i.name),
|
||||||
row=i.row, col=i.col
|
row=i.row, col=i.col
|
||||||
)
|
)
|
||||||
|
elif i.vtype=='Bars':
|
||||||
|
for j in i.df.keys():
|
||||||
|
if j!='date':
|
||||||
|
try:
|
||||||
|
colorType=i.colorType
|
||||||
|
except:
|
||||||
|
colorType='normal'
|
||||||
|
colors=self.getBarColorList(i.df[j],colorType)
|
||||||
|
fig.add_trace(go.Bar(x=i.df['date'], y=i.df[j],name=j,marker_color=colors))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -164,7 +197,3 @@ class coreDraw():
|
|||||||
if self.needShow:
|
if self.needShow:
|
||||||
plotly.offline.iplot(fig)
|
plotly.offline.iplot(fig)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user