siat 3.5.12__py3-none-any.whl → 3.6.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- siat/capm_beta2.py +49 -24
- siat/grafix.py +505 -26
- siat/option_china.py +1 -1
- siat/risk_adjusted_return2.py +91 -52
- siat/security_trend2.py +71 -15
- siat/stock.py +65 -17
- siat/translate.py +1 -1
- siat/valuation.py +28 -12
- {siat-3.5.12.dist-info → siat-3.6.6.dist-info}/METADATA +1 -1
- {siat-3.5.12.dist-info → siat-3.6.6.dist-info}/RECORD +13 -13
- {siat-3.5.12.dist-info → siat-3.6.6.dist-info}/LICENSE +0 -0
- {siat-3.5.12.dist-info → siat-3.6.6.dist-info}/WHEEL +0 -0
- {siat-3.5.12.dist-info → siat-3.6.6.dist-info}/top_level.txt +0 -0
siat/grafix.py
CHANGED
@@ -24,6 +24,11 @@ import matplotlib.pyplot as plt
|
|
24
24
|
import matplotlib.dates as mdate
|
25
25
|
#import matplotlib.font_manager as fm
|
26
26
|
#==============================================================================
|
27
|
+
|
28
|
+
#设置刻度线风格:in,out,inout
|
29
|
+
plt.rcParams['xtick.direction'] = 'inout' # 将x轴的刻度线方向设置向内
|
30
|
+
plt.rcParams['ytick.direction'] = 'inout' # 将y轴的刻度方向设置向内内
|
31
|
+
|
27
32
|
#统一设定绘制的图片大小:数值为英寸,1英寸=100像素
|
28
33
|
plt.rcParams['figure.figsize']=(12.8,7.2)
|
29
34
|
plt.rcParams['figure.dpi']=300
|
@@ -55,10 +60,6 @@ plt.rcParams['axes.grid']=False
|
|
55
60
|
#plt.rcParams['grid.linewidth']=0.5
|
56
61
|
|
57
62
|
|
58
|
-
#设置刻度线风格:in,out,inout
|
59
|
-
plt.rcParams['xtick.direction'] = 'in' # 将x轴的刻度线方向设置向内
|
60
|
-
plt.rcParams['ytick.direction'] = 'in' # 将y轴的刻度方向设置向内内
|
61
|
-
|
62
63
|
#设置x,y 的主刻度定位器
|
63
64
|
#from matplotlib.pyplot import MultipleLocator
|
64
65
|
|
@@ -115,7 +116,11 @@ if __name__ =="__main__":
|
|
115
116
|
plot_line(df0,colname,collabel,ylabeltxt,titletxt,footnote,mark_top=True,mark_bottom=True)
|
116
117
|
|
117
118
|
def plot_line(df0,colname,collabel,ylabeltxt,titletxt,footnote,datatag=False, \
|
118
|
-
power=0,zeroline=False,
|
119
|
+
power=0,zeroline=False, \
|
120
|
+
attention_value='',attention_value_area='', \
|
121
|
+
attention_point='',attention_point_area='', \
|
122
|
+
average_value=False, \
|
123
|
+
|
119
124
|
resample_freq='H',loc='best', \
|
120
125
|
date_range=False,date_freq=False,date_fmt='%Y-%m-%d', \
|
121
126
|
mark_top=True,mark_bottom=True,mark_end=True, \
|
@@ -249,12 +254,69 @@ def plot_line(df0,colname,collabel,ylabeltxt,titletxt,footnote,datatag=False, \
|
|
249
254
|
plt.axhline(y=hline,ls=":",c="black",linewidth=2,label='')
|
250
255
|
haveLegend=False
|
251
256
|
else:
|
257
|
+
#不在必要,被attention_value的逻辑替代
|
252
258
|
if isinstance(zeroline,float) or isinstance(zeroline,int):
|
253
259
|
hline=zeroline
|
254
260
|
plt.axhline(y=hline,ls=":",c="darkorange",linewidth=3,label=text_lang("关注值","Attention"))
|
255
261
|
haveLegend=True
|
256
262
|
footnote=footnote + text_lang(",关注值",", Attention ")+str(hline)
|
263
|
+
|
264
|
+
#用于关注值的颜色列表
|
265
|
+
atv_color_list=["lightgray","paleturquoise","wheat","khaki","lightsage"]
|
266
|
+
#用于关注点的颜色列表
|
267
|
+
atp_color_list=["crimson","dodgerblue","magenta","lightseagreen","chocolate"]
|
268
|
+
|
269
|
+
if not attention_value=='':
|
270
|
+
if isinstance(attention_value,int) or isinstance(attention_value,float):
|
271
|
+
atv_list=[attention_value]
|
272
|
+
elif isinstance(attention_value,list):
|
273
|
+
atv_list=attention_value
|
274
|
+
else:
|
275
|
+
atv_list=[]
|
276
|
+
if not atv_list==[] and not atv_list==['']:
|
277
|
+
for at in atv_list:
|
278
|
+
pos=atv_list.index(at)
|
279
|
+
color=atv_color_list[pos]
|
280
|
+
plt.axhline(y=at,ls=":",c=color,linewidth=2,label=text_lang("关注值","Attention value ")+str(at))
|
281
|
+
|
282
|
+
if not attention_value_area=='':
|
283
|
+
if isinstance(attention_value_area,list) and len(attention_value_area)>=2:
|
284
|
+
plt.fill_between(df.index,attention_value_area[0],attention_value_area[1],color='lightgray',alpha=0.5)
|
257
285
|
|
286
|
+
import pandas as pd
|
287
|
+
if not attention_point=='':
|
288
|
+
if isinstance(attention_point,str) or isinstance(attention_point,int) or isinstance(attention_point,float):
|
289
|
+
atp_list=[attention_point]
|
290
|
+
elif isinstance(attention_point,list):
|
291
|
+
atp_list=attention_point
|
292
|
+
else:
|
293
|
+
atp_list=[]
|
294
|
+
if not atp_list==[] and not atp_list==['']:
|
295
|
+
|
296
|
+
for at in atp_list:
|
297
|
+
pos=atp_list.index(at)
|
298
|
+
color=atp_color_list[pos]
|
299
|
+
|
300
|
+
#判断是否日期字符串
|
301
|
+
try:
|
302
|
+
atpd=pd.to_datetime(at)
|
303
|
+
except:
|
304
|
+
atpd=at
|
305
|
+
plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
|
306
|
+
|
307
|
+
if not attention_point_area=='':
|
308
|
+
if isinstance(attention_point_area,list) and len(attention_point_area)>=2:
|
309
|
+
apa_list=[]
|
310
|
+
for ap in attention_point_area:
|
311
|
+
try:
|
312
|
+
appd=pd.to_datetime(ap)
|
313
|
+
except:
|
314
|
+
appd=ap
|
315
|
+
apa_list=apa_list+[appd]
|
316
|
+
|
317
|
+
yaxis_data=plt.ylim()
|
318
|
+
plt.fill_betweenx(yaxis_data,apa_list[0],apa_list[1],color='powderblue',alpha=0.5)
|
319
|
+
|
258
320
|
if average_value:
|
259
321
|
av=df[colname].mean()
|
260
322
|
plt.axhline(y=av,ls="dashed",c="blueviolet",linewidth=2,label=text_lang("均值","Mean"))
|
@@ -300,6 +362,7 @@ def plot_line(df0,colname,collabel,ylabeltxt,titletxt,footnote,datatag=False, \
|
|
300
362
|
plt.xlabel(footnote,fontsize=xlabel_txt_size,ha='center')
|
301
363
|
plt.title(titletxt,fontweight='bold',fontsize=title_txt_size)
|
302
364
|
|
365
|
+
plt.legend()
|
303
366
|
plt.show()
|
304
367
|
plt.close()
|
305
368
|
|
@@ -322,7 +385,9 @@ def plot_line2(df1,ticker1,colname1,label1, \
|
|
322
385
|
df2,ticker2,colname2,label2, \
|
323
386
|
ylabeltxt,titletxt,footnote, \
|
324
387
|
power=0,datatag1=False,datatag2=False,yscalemax=5, \
|
325
|
-
zeroline=False,twinx=False,
|
388
|
+
zeroline=False,twinx=False, \
|
389
|
+
yline=999,attention_value_area='', \
|
390
|
+
xline=999,attention_point_area='', \
|
326
391
|
resample_freq='H',loc1='best',loc2='best', \
|
327
392
|
color1='red',color2='blue',facecolor='whitesmoke'):
|
328
393
|
"""
|
@@ -336,6 +401,8 @@ def plot_line2(df1,ticker1,colname1,label1, \
|
|
336
401
|
返回值:无
|
337
402
|
注意:需要日期类型作为df索引
|
338
403
|
"""
|
404
|
+
DEBUG=False
|
405
|
+
|
339
406
|
#空值判断
|
340
407
|
if len(df1) ==0:
|
341
408
|
print (" #Warning(plot_line2): no data to plot df1.")
|
@@ -344,11 +411,18 @@ def plot_line2(df1,ticker1,colname1,label1, \
|
|
344
411
|
if (len(df1) ==0) and (len(df2) ==0):
|
345
412
|
return
|
346
413
|
|
414
|
+
if DEBUG:
|
415
|
+
print("In plot_line2")
|
416
|
+
print("Going to plot_line2_coaxial")
|
417
|
+
print("yline=",yline,"; xline=",xline)
|
418
|
+
|
347
419
|
if not twinx:
|
348
420
|
plot_line2_coaxial(df1,ticker1,colname1,label1, \
|
349
421
|
df2,ticker2,colname2,label2, \
|
350
422
|
ylabeltxt,titletxt,footnote,power,datatag1,datatag2,zeroline, \
|
351
|
-
|
423
|
+
yline=yline,attention_value_area=attention_value_area, \
|
424
|
+
xline=xline,attention_point_area=attention_point_area, \
|
425
|
+
resample_freq=resample_freq, \
|
352
426
|
loc1=loc1,loc2=loc2, \
|
353
427
|
color1=color1,color2=color2,facecolor=facecolor)
|
354
428
|
else:
|
@@ -356,6 +430,7 @@ def plot_line2(df1,ticker1,colname1,label1, \
|
|
356
430
|
df2,ticker2,colname2,label2, \
|
357
431
|
titletxt,footnote,power,datatag1,datatag2, \
|
358
432
|
resample_freq=resample_freq, \
|
433
|
+
xline=xline,attention_point_area=attention_point_area, \
|
359
434
|
loc1=loc1,loc2=loc2, \
|
360
435
|
color1=color1,color2=color2,facecolor=facecolor)
|
361
436
|
return
|
@@ -366,7 +441,9 @@ def plot2_line2(df1,ticker1,colname1,label1, \
|
|
366
441
|
df2,ticker2,colname2,label2, \
|
367
442
|
ylabeltxt,titletxt,footnote, \
|
368
443
|
power=0,datatag1=False,datatag2=False,yscalemax=5, \
|
369
|
-
zeroline=False,twinx=False,
|
444
|
+
zeroline=False,twinx=False, \
|
445
|
+
yline=999,attention_value_area='', \
|
446
|
+
xline=999,attention_point_area='', \
|
370
447
|
resample_freq='H',loc1='best',loc2='best', \
|
371
448
|
date_range=False,date_freq=False,date_fmt='%Y-%m-%d', \
|
372
449
|
color1='red',color2='blue',facecolor='whitesmoke'):
|
@@ -401,9 +478,11 @@ def plot2_line2(df1,ticker1,colname1,label1, \
|
|
401
478
|
|
402
479
|
if not twinx:
|
403
480
|
plot_line2_coaxial2(df1,ticker1,colname1,label1, \
|
404
|
-
|
481
|
+
df2,ticker2,colname2,label2, \
|
405
482
|
ylabeltxt,titletxt,footnote,power,datatag1,datatag2,zeroline, \
|
406
|
-
|
483
|
+
yline=yline,attention_value_area=attention_value_area, \
|
484
|
+
xline=xline,attention_point_area=attention_point_area, \
|
485
|
+
resample_freq=resample_freq, \
|
407
486
|
loc1=loc1,loc2=loc2, \
|
408
487
|
date_range=date_range,date_freq=date_freq,date_fmt=date_fmt, \
|
409
488
|
color1=color1,color2=color2,facecolor=facecolor)
|
@@ -411,6 +490,7 @@ def plot2_line2(df1,ticker1,colname1,label1, \
|
|
411
490
|
plot_line2_twinx2(df1,ticker1,colname1,label1, \
|
412
491
|
df2,ticker2,colname2,label2, \
|
413
492
|
titletxt,footnote,power,datatag1,datatag2, \
|
493
|
+
xline,attention_point_area=attention_point_area, \
|
414
494
|
resample_freq=resample_freq, \
|
415
495
|
loc1=loc1,loc2=loc2, \
|
416
496
|
date_range=date_range,date_freq=date_freq,date_fmt=date_fmt, \
|
@@ -425,7 +505,9 @@ def plot_line2_coaxial(df01,ticker1,colname1,label1, \
|
|
425
505
|
df02,ticker2,colname2,label2, \
|
426
506
|
ylabeltxt,titletxt,footnote, \
|
427
507
|
power=0,datatag1=False,datatag2=False,zeroline=False, \
|
428
|
-
|
508
|
+
yline=999,attention_value_area='', \
|
509
|
+
xline=999,attention_point_area='', \
|
510
|
+
resample_freq='H', \
|
429
511
|
loc1='best',loc2='best', \
|
430
512
|
color1='red',color2='blue',facecolor='whitesmoke', \
|
431
513
|
ticker_type='auto'):
|
@@ -440,6 +522,7 @@ def plot_line2_coaxial(df01,ticker1,colname1,label1, \
|
|
440
522
|
返回值:无
|
441
523
|
注意:需要日期类型作为df索引
|
442
524
|
"""
|
525
|
+
DEBUG=False
|
443
526
|
|
444
527
|
#插值平滑
|
445
528
|
try:
|
@@ -487,13 +570,79 @@ def plot_line2_coaxial(df01,ticker1,colname1,label1, \
|
|
487
570
|
if zeroline:
|
488
571
|
plt.axhline(y=0,ls=":",c="black",linewidth=2)
|
489
572
|
|
573
|
+
if DEBUG:
|
574
|
+
print("In plot_line2_coaxial:")
|
575
|
+
print("yline=",yline,"; xline=",xline)
|
576
|
+
|
490
577
|
#是否绘制水平线
|
491
578
|
if yline != 999:
|
492
|
-
|
579
|
+
attention_value=yline
|
580
|
+
|
581
|
+
#用于关注值的颜色列表
|
582
|
+
atv_color_list=["lightgray","paleturquoise","wheat","khaki","lightsage"]
|
583
|
+
|
584
|
+
if isinstance(attention_value,int) or isinstance(attention_value,float):
|
585
|
+
atv_list=[attention_value]
|
586
|
+
elif isinstance(attention_value,list):
|
587
|
+
atv_list=attention_value
|
588
|
+
else:
|
589
|
+
atv_list=[]
|
590
|
+
|
591
|
+
if DEBUG:
|
592
|
+
print("atv_list=",atv_list)
|
593
|
+
|
594
|
+
if not atv_list==[] and not atv_list==['']:
|
595
|
+
for at in atv_list:
|
596
|
+
pos=atv_list.index(at)
|
597
|
+
color=atv_color_list[pos]
|
598
|
+
plt.axhline(y=at,ls=":",c=color,linewidth=2,label=text_lang("关注值","Attention value ")+str(at))
|
599
|
+
|
600
|
+
if not attention_value_area=='':
|
601
|
+
if isinstance(attention_value_area,list) and len(attention_value_area)>=2:
|
602
|
+
plt.fill_between(df1.index,attention_value_area[0],attention_value_area[1],color='lightgray',alpha=0.5)
|
493
603
|
|
494
604
|
#是否绘制垂直线
|
605
|
+
import pandas as pd
|
495
606
|
if xline != 999:
|
496
|
-
|
607
|
+
attention_point=xline
|
608
|
+
#用于关注点的颜色列表
|
609
|
+
atp_color_list=["crimson","dodgerblue","magenta","lightseagreen","chocolate"]
|
610
|
+
|
611
|
+
if isinstance(attention_point,str) or isinstance(attention_point,int) or isinstance(attention_point,float):
|
612
|
+
atp_list=[attention_point]
|
613
|
+
elif isinstance(attention_point,list):
|
614
|
+
atp_list=attention_point
|
615
|
+
else:
|
616
|
+
atp_list=[]
|
617
|
+
if not atp_list==[] and not atp_list==['']:
|
618
|
+
|
619
|
+
for at in atp_list:
|
620
|
+
pos=atp_list.index(at)
|
621
|
+
color=atp_color_list[pos]
|
622
|
+
|
623
|
+
#判断是否日期字符串
|
624
|
+
try:
|
625
|
+
atpd=pd.to_datetime(at)
|
626
|
+
except:
|
627
|
+
atpd=at
|
628
|
+
|
629
|
+
if DEBUG:
|
630
|
+
print("atpd=",atpd)
|
631
|
+
|
632
|
+
plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
|
633
|
+
|
634
|
+
if not attention_point_area=='':
|
635
|
+
if isinstance(attention_point_area,list) and len(attention_point_area)>=2:
|
636
|
+
apa_list=[]
|
637
|
+
for ap in attention_point_area:
|
638
|
+
try:
|
639
|
+
appd=pd.to_datetime(ap)
|
640
|
+
except:
|
641
|
+
appd=ap
|
642
|
+
apa_list=apa_list+[appd]
|
643
|
+
|
644
|
+
yaxis_data=plt.ylim()
|
645
|
+
plt.fill_betweenx(yaxis_data,apa_list[0],apa_list[1],color='powderblue',alpha=0.5)
|
497
646
|
|
498
647
|
#绘证券1:制趋势线
|
499
648
|
if power > 0:
|
@@ -599,7 +748,9 @@ def plot_line2_coaxial2(df01,ticker1,colname1,label1, \
|
|
599
748
|
df02,ticker2,colname2,label2, \
|
600
749
|
ylabeltxt,titletxt,footnote, \
|
601
750
|
power=0,datatag1=False,datatag2=False,zeroline=False, \
|
602
|
-
|
751
|
+
yline=999,attention_value_area='', \
|
752
|
+
xline=999,attention_point_area='', \
|
753
|
+
resample_freq='H', \
|
603
754
|
loc1='best',loc2='best', \
|
604
755
|
date_range=False,date_freq=False,date_fmt='%Y-%m-%d', \
|
605
756
|
color1='red',color2='blue',facecolor='whitesmoke', \
|
@@ -665,6 +816,7 @@ def plot_line2_coaxial2(df01,ticker1,colname1,label1, \
|
|
665
816
|
if zeroline and ((min(df1[colname1]) < 0) or (min(df2[colname2]) < 0)):
|
666
817
|
plt.axhline(y=0,ls=":",c="black",linewidth=2.5)
|
667
818
|
|
819
|
+
"""
|
668
820
|
#是否绘制水平线
|
669
821
|
if yline != 999:
|
670
822
|
plt.axhline(y=yline,ls=":",c="black",linewidth=2.5)
|
@@ -672,6 +824,77 @@ def plot_line2_coaxial2(df01,ticker1,colname1,label1, \
|
|
672
824
|
#是否绘制垂直线
|
673
825
|
if xline != 999:
|
674
826
|
plt.axvline(x=xline,ls=":",c="black",linewidth=2.5)
|
827
|
+
"""
|
828
|
+
#是否绘制水平线
|
829
|
+
if yline != 999:
|
830
|
+
attention_value=yline
|
831
|
+
|
832
|
+
#用于关注值的颜色列表
|
833
|
+
atv_color_list=["lightgray","paleturquoise","wheat","khaki","lightsage"]
|
834
|
+
|
835
|
+
if isinstance(attention_value,int) or isinstance(attention_value,float):
|
836
|
+
atv_list=[attention_value]
|
837
|
+
elif isinstance(attention_value,list):
|
838
|
+
atv_list=attention_value
|
839
|
+
else:
|
840
|
+
atv_list=[]
|
841
|
+
|
842
|
+
if DEBUG:
|
843
|
+
print("atv_list=",atv_list)
|
844
|
+
|
845
|
+
if not atv_list==[] and not atv_list==['']:
|
846
|
+
for at in atv_list:
|
847
|
+
pos=atv_list.index(at)
|
848
|
+
color=atv_color_list[pos]
|
849
|
+
plt.axhline(y=at,ls=":",c=color,linewidth=2,label=text_lang("关注值","Attention value ")+str(at))
|
850
|
+
|
851
|
+
if not attention_value_area=='':
|
852
|
+
if isinstance(attention_value_area,list) and len(attention_value_area)>=2:
|
853
|
+
plt.fill_between(df1.index,attention_value_area[0],attention_value_area[1],color='lightgray',alpha=0.5)
|
854
|
+
|
855
|
+
#是否绘制垂直线
|
856
|
+
import pandas as pd
|
857
|
+
if xline != 999:
|
858
|
+
attention_point=xline
|
859
|
+
#用于关注点的颜色列表
|
860
|
+
atp_color_list=["crimson","dodgerblue","magenta","lightseagreen","chocolate"]
|
861
|
+
|
862
|
+
if isinstance(attention_point,str) or isinstance(attention_point,int) or isinstance(attention_point,float):
|
863
|
+
atp_list=[attention_point]
|
864
|
+
elif isinstance(attention_point,list):
|
865
|
+
atp_list=attention_point
|
866
|
+
else:
|
867
|
+
atp_list=[]
|
868
|
+
if not atp_list==[] and not atp_list==['']:
|
869
|
+
|
870
|
+
for at in atp_list:
|
871
|
+
pos=atp_list.index(at)
|
872
|
+
color=atp_color_list[pos]
|
873
|
+
|
874
|
+
#判断是否日期字符串
|
875
|
+
try:
|
876
|
+
atpd=pd.to_datetime(at)
|
877
|
+
except:
|
878
|
+
atpd=at
|
879
|
+
|
880
|
+
if DEBUG:
|
881
|
+
print("atpd=",atpd)
|
882
|
+
|
883
|
+
plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
|
884
|
+
|
885
|
+
if not attention_point_area=='':
|
886
|
+
if isinstance(attention_point_area,list) and len(attention_point_area)>=2:
|
887
|
+
apa_list=[]
|
888
|
+
for ap in attention_point_area:
|
889
|
+
try:
|
890
|
+
appd=pd.to_datetime(ap)
|
891
|
+
except:
|
892
|
+
appd=ap
|
893
|
+
apa_list=apa_list+[appd]
|
894
|
+
|
895
|
+
yaxis_data=plt.ylim()
|
896
|
+
plt.fill_betweenx(yaxis_data,apa_list[0],apa_list[1],color='powderblue',alpha=0.5)
|
897
|
+
|
675
898
|
|
676
899
|
#绘证券1:制趋势线
|
677
900
|
if power > 0:
|
@@ -769,7 +992,9 @@ def plot_line2_coaxial2(df01,ticker1,colname1,label1, \
|
|
769
992
|
def plot_line2_twinx(df01,ticker1,colname1,label1, \
|
770
993
|
df02,ticker2,colname2,label2, \
|
771
994
|
titletxt,footnote,power=0,datatag1=False,datatag2=False, \
|
772
|
-
resample_freq='H',
|
995
|
+
resample_freq='H', \
|
996
|
+
xline=999,attention_point_area='', \
|
997
|
+
loc1='upper left',loc2='lower left', \
|
773
998
|
color1='red',color2='blue',facecolor='whitesmoke', \
|
774
999
|
ticker_type='auto'):
|
775
1000
|
"""
|
@@ -783,6 +1008,8 @@ def plot_line2_twinx(df01,ticker1,colname1,label1, \
|
|
783
1008
|
返回值:无
|
784
1009
|
注意:需要日期类型作为df索引
|
785
1010
|
"""
|
1011
|
+
DEBUG=False
|
1012
|
+
|
786
1013
|
#plt.rcParams['axes.grid']=False
|
787
1014
|
|
788
1015
|
#插值平滑
|
@@ -820,11 +1047,57 @@ def plot_line2_twinx(df01,ticker1,colname1,label1, \
|
|
820
1047
|
lwadjust=linewidth_adjust(df1)
|
821
1048
|
ax.plot(df1.index,df1[colname1],'-',label=label1txt, \
|
822
1049
|
linestyle='-',color=color1,linewidth=lwadjust)
|
1050
|
+
|
823
1051
|
#证券1:绘制数据标签
|
824
1052
|
if datatag1:
|
825
1053
|
for x, y in zip(df1.index, df1[colname1]):
|
826
1054
|
ax.text(x,y+0.1,'%.2f' % y,ha='center',va='bottom',color='black')
|
827
1055
|
|
1056
|
+
#绘制关注点
|
1057
|
+
import pandas as pd
|
1058
|
+
if xline != 999:
|
1059
|
+
attention_point=xline
|
1060
|
+
|
1061
|
+
#用于关注点的颜色列表
|
1062
|
+
atp_color_list=["crimson","dodgerblue","magenta","lightseagreen","chocolate"]
|
1063
|
+
|
1064
|
+
if isinstance(attention_point,str) or isinstance(attention_point,int) or isinstance(attention_point,float):
|
1065
|
+
atp_list=[attention_point]
|
1066
|
+
elif isinstance(attention_point,list):
|
1067
|
+
atp_list=attention_point
|
1068
|
+
else:
|
1069
|
+
atp_list=[]
|
1070
|
+
|
1071
|
+
if DEBUG:
|
1072
|
+
print("In plot_line2_twinx")
|
1073
|
+
print("atp_list=",atp_list)
|
1074
|
+
|
1075
|
+
if not atp_list==[] and not atp_list==['']:
|
1076
|
+
|
1077
|
+
for at in atp_list:
|
1078
|
+
pos=atp_list.index(at)
|
1079
|
+
color=atp_color_list[pos]
|
1080
|
+
|
1081
|
+
#判断是否日期字符串
|
1082
|
+
try:
|
1083
|
+
atpd=pd.to_datetime(at)
|
1084
|
+
except:
|
1085
|
+
atpd=at
|
1086
|
+
plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
|
1087
|
+
|
1088
|
+
if not attention_point_area=='':
|
1089
|
+
if isinstance(attention_point_area,list) and len(attention_point_area)>=2:
|
1090
|
+
apa_list=[]
|
1091
|
+
for ap in attention_point_area:
|
1092
|
+
try:
|
1093
|
+
appd=pd.to_datetime(ap)
|
1094
|
+
except:
|
1095
|
+
appd=ap
|
1096
|
+
apa_list=apa_list+[appd]
|
1097
|
+
|
1098
|
+
yaxis_data=plt.ylim()
|
1099
|
+
plt.fill_betweenx(yaxis_data,apa_list[0],apa_list[1],color='powderblue',alpha=0.5)
|
1100
|
+
|
828
1101
|
#绘证券1:制趋势线
|
829
1102
|
if power > 0:
|
830
1103
|
lang=check_language()
|
@@ -936,6 +1209,7 @@ if __name__ =="__main__":
|
|
936
1209
|
def plot_line2_twinx2(df01,ticker1,colname1,label1, \
|
937
1210
|
df02,ticker2,colname2,label2, \
|
938
1211
|
titletxt,footnote,power=0,datatag1=False,datatag2=False, \
|
1212
|
+
xline=999,attention_point_area='', \
|
939
1213
|
resample_freq='H',loc1='upper left',loc2='lower left', \
|
940
1214
|
date_range=False,date_freq=False,date_fmt='%Y-%m-%d', \
|
941
1215
|
color1='red',color2='blue',facecolor='whitesmoke', \
|
@@ -1007,6 +1281,52 @@ def plot_line2_twinx2(df01,ticker1,colname1,label1, \
|
|
1007
1281
|
for x, y in zip(df1.index, df1[colname1]):
|
1008
1282
|
ax.text(x,y+0.1,'%.2f' % y,ha='center',va='bottom',color='black')
|
1009
1283
|
|
1284
|
+
#绘制关注点
|
1285
|
+
import pandas as pd
|
1286
|
+
if xline != 999:
|
1287
|
+
attention_point=xline
|
1288
|
+
|
1289
|
+
#用于关注点的颜色列表
|
1290
|
+
atp_color_list=["crimson","dodgerblue","magenta","lightseagreen","chocolate"]
|
1291
|
+
|
1292
|
+
if isinstance(attention_point,str) or isinstance(attention_point,int) or isinstance(attention_point,float):
|
1293
|
+
atp_list=[attention_point]
|
1294
|
+
elif isinstance(attention_point,list):
|
1295
|
+
atp_list=attention_point
|
1296
|
+
else:
|
1297
|
+
atp_list=[]
|
1298
|
+
|
1299
|
+
if DEBUG:
|
1300
|
+
print("In plot_line2_twinx")
|
1301
|
+
print("atp_list=",atp_list)
|
1302
|
+
|
1303
|
+
if not atp_list==[] and not atp_list==['']:
|
1304
|
+
|
1305
|
+
for at in atp_list:
|
1306
|
+
pos=atp_list.index(at)
|
1307
|
+
color=atp_color_list[pos]
|
1308
|
+
|
1309
|
+
#判断是否日期字符串
|
1310
|
+
try:
|
1311
|
+
atpd=pd.to_datetime(at)
|
1312
|
+
except:
|
1313
|
+
atpd=at
|
1314
|
+
plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
|
1315
|
+
|
1316
|
+
if not attention_point_area=='':
|
1317
|
+
if isinstance(attention_point_area,list) and len(attention_point_area)>=2:
|
1318
|
+
apa_list=[]
|
1319
|
+
for ap in attention_point_area:
|
1320
|
+
try:
|
1321
|
+
appd=pd.to_datetime(ap)
|
1322
|
+
except:
|
1323
|
+
appd=ap
|
1324
|
+
apa_list=apa_list+[appd]
|
1325
|
+
|
1326
|
+
yaxis_data=plt.ylim()
|
1327
|
+
plt.fill_betweenx(yaxis_data,apa_list[0],apa_list[1],color='powderblue',alpha=0.5)
|
1328
|
+
|
1329
|
+
|
1010
1330
|
#绘证券1:制趋势线
|
1011
1331
|
if power > 0:
|
1012
1332
|
lang=check_language()
|
@@ -1117,6 +1437,8 @@ def plot_line2_twinx2(df01,ticker1,colname1,label1, \
|
|
1117
1437
|
def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
1118
1438
|
data_label=True,resample_freq='H',smooth=True,linewidth=1.5, \
|
1119
1439
|
loc='best',annotate=False,annotate_value=False,plus_sign=False, \
|
1440
|
+
attention_value='',attention_value_area='', \
|
1441
|
+
attention_point='',attention_point_area='', \
|
1120
1442
|
mark_top=False,mark_bottom=False,mark_end=False, \
|
1121
1443
|
ticker_type='auto',facecolor='whitesmoke'):
|
1122
1444
|
"""
|
@@ -1229,7 +1551,15 @@ def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1229
1551
|
#plt.plot(dfg,label=codetranslate(c),linewidth=linewidth,ls=lsc,marker=mkc,markersize=3)
|
1230
1552
|
plt.plot(dfg,label=c,linewidth=lwadjust,ls=lsc,marker=mkc,markersize=3)
|
1231
1553
|
"""
|
1232
|
-
|
1554
|
+
if not annotate or c in ["平均值","中位数"]:
|
1555
|
+
if c in ["平均值","中位数"]:
|
1556
|
+
clabel=c+str(round(dfg[c].values[0],2))
|
1557
|
+
else:
|
1558
|
+
clabel=c
|
1559
|
+
plt.plot(dfg,label=clabel,linewidth=lwadjust,ls=lsc,marker=mkc,markersize=3)
|
1560
|
+
else:
|
1561
|
+
plt.plot(dfg,linewidth=lwadjust,ls=lsc,marker=mkc,markersize=3)
|
1562
|
+
|
1233
1563
|
lines = plt.gca().lines
|
1234
1564
|
last_line_color = lines[-1].get_color()
|
1235
1565
|
|
@@ -1303,6 +1633,81 @@ def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1303
1633
|
xytext=(x_end, y_end),fontsize=annotate_size,
|
1304
1634
|
color=last_line_color)
|
1305
1635
|
|
1636
|
+
#用于关注值的颜色列表
|
1637
|
+
atv_color_list=["lightgray","paleturquoise","wheat","khaki","lightsage"]
|
1638
|
+
#用于关注点的颜色列表
|
1639
|
+
atp_color_list=["crimson","dodgerblue","magenta","lightseagreen","chocolate"]
|
1640
|
+
|
1641
|
+
if not attention_value=='':
|
1642
|
+
if isinstance(attention_value,int) or isinstance(attention_value,float):
|
1643
|
+
atv_list=[attention_value]
|
1644
|
+
elif isinstance(attention_value,list):
|
1645
|
+
atv_list=attention_value
|
1646
|
+
else:
|
1647
|
+
atv_list=[]
|
1648
|
+
if not atv_list==[] and not atv_list==['']:
|
1649
|
+
for at in atv_list:
|
1650
|
+
pos=atv_list.index(at)
|
1651
|
+
color=atv_color_list[pos]
|
1652
|
+
plt.axhline(y=at,ls=":",c=color,linewidth=2,label=text_lang("关注值","Attention value ")+str(at))
|
1653
|
+
|
1654
|
+
if not attention_value_area=='':
|
1655
|
+
if isinstance(attention_value_area,list) and len(attention_value_area)>=2:
|
1656
|
+
plt.fill_between(dfg.index,attention_value_area[0],attention_value_area[1],color='lightgray',alpha=0.5)
|
1657
|
+
|
1658
|
+
import pandas as pd
|
1659
|
+
if not attention_point=='':
|
1660
|
+
if isinstance(attention_point,str) or isinstance(attention_point,int) or isinstance(attention_point,float):
|
1661
|
+
atp_list=[attention_point]
|
1662
|
+
elif isinstance(attention_point,list):
|
1663
|
+
atp_list=attention_point
|
1664
|
+
else:
|
1665
|
+
atp_list=[]
|
1666
|
+
if not atp_list==[] and not atp_list==['']:
|
1667
|
+
|
1668
|
+
for at in atp_list:
|
1669
|
+
pos=atp_list.index(at)
|
1670
|
+
color=atp_color_list[pos]
|
1671
|
+
|
1672
|
+
#判断是否日期字符串
|
1673
|
+
try:
|
1674
|
+
atpd=pd.to_datetime(at)
|
1675
|
+
except:
|
1676
|
+
atpd=at
|
1677
|
+
|
1678
|
+
"""
|
1679
|
+
#纵轴最小值
|
1680
|
+
yaxis_min=plt.ylim()[0]
|
1681
|
+
arrow_dx=0
|
1682
|
+
#各曲线在关注点的最大值
|
1683
|
+
point_max=dfg.loc[atpd].max()
|
1684
|
+
arrow_dy=point_max - yaxis_min
|
1685
|
+
|
1686
|
+
if DEBUG:
|
1687
|
+
print("*** In draw_lines:")
|
1688
|
+
print("dfg.loc[atpd]",dfg.loc[atpd].values)
|
1689
|
+
print("yaxis_min=",yaxis_min)
|
1690
|
+
print("point_max=",point_max)
|
1691
|
+
print("arrow_dy=",arrow_dy)
|
1692
|
+
|
1693
|
+
plt.arrow(atpd,yaxis_min,arrow_dx,arrow_dy,ls=':',lw=2,fc=color,ec=color,alpha=0.5,shape='full', \
|
1694
|
+
width=0.05,length_includes_head=True)
|
1695
|
+
"""
|
1696
|
+
plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
|
1697
|
+
|
1698
|
+
if not attention_point_area=='':
|
1699
|
+
if isinstance(attention_point_area,list) and len(attention_point_area)>=2:
|
1700
|
+
apa_list=[]
|
1701
|
+
for ap in attention_point_area:
|
1702
|
+
try:
|
1703
|
+
appd=pd.to_datetime(ap)
|
1704
|
+
except:
|
1705
|
+
appd=ap
|
1706
|
+
apa_list=apa_list+[appd]
|
1707
|
+
|
1708
|
+
yaxis_data=plt.ylim()
|
1709
|
+
plt.fill_betweenx(yaxis_data,apa_list[0],apa_list[1],color='powderblue',alpha=0.5)
|
1710
|
+
|
1306
1711
|
#绘制水平辅助线
|
1307
1712
|
if axhline_label !="":
|
1308
1713
|
if '零线' in axhline_label:
|
@@ -1328,8 +1733,8 @@ def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1328
1733
|
plt.gca().set_facecolor("whitesmoke")
|
1329
1734
|
|
1330
1735
|
# 若不绘制annotate,则绘制图例
|
1331
|
-
if not annotate:
|
1332
|
-
|
1736
|
+
#if not annotate:
|
1737
|
+
plt.legend(loc=loc,fontsize=legend_txt_size)
|
1333
1738
|
|
1334
1739
|
if plus_sign:
|
1335
1740
|
# 尝试改变纵轴刻度格式:给正数添加正号+,以便突出显示增减幅度
|
@@ -1352,7 +1757,15 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1352
1757
|
data_label=False,resample_freq='6H',smooth=True, \
|
1353
1758
|
date_range=False,date_freq=False,date_fmt='%Y-%m-%d', \
|
1354
1759
|
colorlist=[],lslist=[],lwlist=[], \
|
1355
|
-
|
1760
|
+
#指定纵轴两个变量之间的区域
|
1761
|
+
band_area='',loc='best', \
|
1762
|
+
attention_value='', \
|
1763
|
+
#指定纵轴两个数值之间的区域
|
1764
|
+
attention_value_area='', \
|
1765
|
+
attention_point='', \
|
1766
|
+
#指定两个横轴之间的区域
|
1767
|
+
attention_point_area='', \
|
1768
|
+
annotate=False,annotate_value=False, \
|
1356
1769
|
mark_top=False,mark_bottom=False,mark_end=False, \
|
1357
1770
|
facecolor='whitesmoke'):
|
1358
1771
|
"""
|
@@ -1444,11 +1857,20 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1444
1857
|
llw=linewidth_adjust(df)
|
1445
1858
|
|
1446
1859
|
if (lcolor !='') and (lls !=''):
|
1447
|
-
|
1860
|
+
if not annotate:
|
1861
|
+
plt.plot(df[c],label=c,linewidth=llw,ls=lls,color=lcolor)
|
1862
|
+
else:
|
1863
|
+
plt.plot(df[c],linewidth=llw,ls=lls,color=lcolor)
|
1448
1864
|
elif (lcolor !=''):
|
1449
|
-
|
1865
|
+
if not annotate:
|
1866
|
+
plt.plot(df[c],label=c,linewidth=llw,color=lcolor)
|
1867
|
+
else:
|
1868
|
+
plt.plot(df[c],linewidth=llw,color=lcolor)
|
1450
1869
|
else:
|
1451
|
-
|
1870
|
+
if not annotate:
|
1871
|
+
plt.plot(df[c],label=c,linewidth=llw)
|
1872
|
+
else:
|
1873
|
+
plt.plot(df[c],linewidth=llw)
|
1452
1874
|
|
1453
1875
|
lines = plt.gca().lines; last_line_color = lines[-1].get_color()
|
1454
1876
|
|
@@ -1539,8 +1961,10 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1539
1961
|
plt.fill_between(df.index,df[upper_line],df[lower_line],color='moccasin',alpha=0.5,label='',where=df[upper_line]>=df[lower_line])
|
1540
1962
|
plt.fill_between(df.index,df[upper_line],df[lower_line],color='aquamarine',alpha=0.5,label='',where=df[upper_line]<=df[lower_line])
|
1541
1963
|
"""
|
1542
|
-
plt.fill_between(df.index,df[upper_line],df[lower_line],color='aquamarine',alpha=0.5,label='')
|
1543
|
-
|
1964
|
+
#plt.fill_between(df.index,df[upper_line],df[lower_line],color='aquamarine',alpha=0.5,label='')
|
1965
|
+
plt.fill_between(df.index,df[upper_line],df[lower_line],df[upper_line] > df[lower_line],color='aquamarine',alpha=0.5,label='',interpolate=True)
|
1966
|
+
plt.fill_between(df.index,df[upper_line],df[lower_line],df[upper_line] < df[lower_line],color='lightcoral',alpha=0.5,label='',interpolate=True)
|
1967
|
+
#plt.fill_between(df.index,df[upper_line],df[lower_line],df[upper_line] == df[lower_line],color='lightgray',alpha=0.5,label='')
|
1544
1968
|
|
1545
1969
|
#绘制水平辅助线
|
1546
1970
|
if axhline_label !="":
|
@@ -1551,6 +1975,61 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1551
1975
|
plt.axhline(y=axhline_value,color='black',linestyle='--',linewidth=2)
|
1552
1976
|
else:
|
1553
1977
|
plt.axhline(y=axhline_value,label=axhline_label,color='black',linestyle='--',linewidth=2)
|
1978
|
+
|
1979
|
+
#用于关注值的颜色列表
|
1980
|
+
atv_color_list=["lightgray","paleturquoise","wheat","khaki","lightsage"]
|
1981
|
+
#用于关注点的颜色列表
|
1982
|
+
atp_color_list=["crimson","dodgerblue","magenta","lightseagreen","chocolate"]
|
1983
|
+
|
1984
|
+
if not attention_value=='':
|
1985
|
+
if isinstance(attention_value,int) or isinstance(attention_value,float):
|
1986
|
+
atv_list=[attention_value]
|
1987
|
+
elif isinstance(attention_value,list):
|
1988
|
+
atv_list=attention_value
|
1989
|
+
else:
|
1990
|
+
atv_list=[]
|
1991
|
+
if not atv_list==[] and not atv_list==['']:
|
1992
|
+
for at in atv_list:
|
1993
|
+
pos=atv_list.index(at)
|
1994
|
+
color=atv_color_list[pos]
|
1995
|
+
plt.axhline(y=at,ls=":",c=color,linewidth=2,label=text_lang("关注值","Attention value ")+str(at))
|
1996
|
+
|
1997
|
+
if not attention_value_area=='':
|
1998
|
+
if isinstance(attention_value_area,list) and len(attention_value_area)>=2:
|
1999
|
+
plt.fill_between(df.index,attention_value_area[0],attention_value_area[1],color='lightgray',alpha=0.5)
|
2000
|
+
|
2001
|
+
import pandas as pd
|
2002
|
+
if not attention_point=='':
|
2003
|
+
if isinstance(attention_point,str) or isinstance(attention_point,int) or isinstance(attention_point,float):
|
2004
|
+
atp_list=[attention_point]
|
2005
|
+
elif isinstance(attention_point,list):
|
2006
|
+
atp_list=attention_point
|
2007
|
+
else:
|
2008
|
+
atp_list=[]
|
2009
|
+
if not atp_list==[] and not atp_list==['']:
|
2010
|
+
for at in atp_list:
|
2011
|
+
pos=atp_list.index(at)
|
2012
|
+
color=atp_color_list[pos]
|
2013
|
+
|
2014
|
+
#判断是否日期字符串
|
2015
|
+
try:
|
2016
|
+
atpd=pd.to_datetime(at)
|
2017
|
+
except:
|
2018
|
+
atpd=at
|
2019
|
+
plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
|
2020
|
+
|
2021
|
+
if not attention_point_area=='':
|
2022
|
+
if isinstance(attention_point_area,list) and len(attention_point_area)>=2:
|
2023
|
+
apa_list=[]
|
2024
|
+
for ap in attention_point_area:
|
2025
|
+
try:
|
2026
|
+
appd=pd.to_datetime(ap)
|
2027
|
+
except:
|
2028
|
+
appd=ap
|
2029
|
+
apa_list=apa_list+[appd]
|
2030
|
+
|
2031
|
+
yaxis_data=plt.ylim()
|
2032
|
+
plt.fill_betweenx(yaxis_data,apa_list[0],apa_list[1],color='powderblue',alpha=0.5)
|
1554
2033
|
|
1555
2034
|
#坐标轴标记
|
1556
2035
|
plt.ylabel(y_label,fontweight='bold',fontsize=ylabel_txt_size)
|
@@ -1565,8 +2044,8 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
|
|
1565
2044
|
print(" #Warning(draw_lines2): color",facecolor,"is unsupported, changed to default setting")
|
1566
2045
|
plt.gca().set_facecolor("whitesmoke")
|
1567
2046
|
|
1568
|
-
if not annotate:
|
1569
|
-
|
2047
|
+
#if not annotate:
|
2048
|
+
plt.legend(loc=loc,fontsize=legend_txt_size)
|
1570
2049
|
|
1571
2050
|
#设置绘图风格:关闭网格虚线
|
1572
2051
|
plt.rcParams['axes.grid']=False
|