siat 3.5.11__py3-none-any.whl → 3.6.1__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/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,12 @@ 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,average_value=False, \
119
+ power=0,zeroline=False, \
120
+ attention_value='', \
121
+ attention_point='', \
122
+
123
+ average_value=False, \
124
+
119
125
  resample_freq='H',loc='best', \
120
126
  date_range=False,date_freq=False,date_fmt='%Y-%m-%d', \
121
127
  mark_top=True,mark_bottom=True,mark_end=True, \
@@ -209,7 +215,7 @@ def plot_line(df0,colname,collabel,ylabeltxt,titletxt,footnote,datatag=False, \
209
215
  #y1=round(y+high_low*0.01,2)
210
216
  y1=y+high_low*0.01
211
217
  #s='%.0f' if y >= 100 else '%.2f'
212
- s='%.2f' if abs(y) >= 100 else '%.2f' if abs(y) >= 10 else '%.3f'
218
+ s='%.2f' if abs(y) >= 100 else '%.2f' if abs(y) >= 10 else '%.4f'
213
219
  plt.text(x,y1,s % y,ha='right',va='bottom',color='red')
214
220
  """
215
221
  s='%.0f' if y >= 100 else '%.2f'
@@ -224,7 +230,7 @@ def plot_line(df0,colname,collabel,ylabeltxt,titletxt,footnote,datatag=False, \
224
230
  #y1=round(y-high_low*0.055,2) #标记位置对应y1的底部
225
231
  y1=y-high_low*0.050 #标记位置对应y1的底部
226
232
  #s='%.0f' if y >= 100 else '%.2f'
227
- s='%.2f' if abs(y) >= 100 else '%.2f' if abs(y) >= 10 else '%.3f'
233
+ s='%.2f' if abs(y) >= 100 else '%.2f' if abs(y) >= 10 else '%.4f'
228
234
  #plt.text(x,y1,s % y,ha='center',va='bottom',color='seagreen')
229
235
  plt.text(x,y1,s % y,ha='right',va='bottom',color='seagreen')
230
236
  plt.scatter(x,y, color='seagreen',marker='8',s=70)
@@ -236,7 +242,7 @@ def plot_line(df0,colname,collabel,ylabeltxt,titletxt,footnote,datatag=False, \
236
242
  x_end = df_end[colname].idxmin() # 末端值的x坐标
237
243
 
238
244
  #y1=str(int(y_end)) if y_end >= 100 else str(round(y_end,2))
239
- y1=str(round(y_end,2)) if abs(y_end) >= 100 else str(round(y_end,2)) if abs(y_end) >= 10 else str(round(y_end,3))
245
+ y1=str(round(y_end,2)) if abs(y_end) >= 100 else str(round(y_end,2)) if abs(y_end) >= 10 else str(round(y_end,4))
240
246
  plt.annotate(text=' '+y1,
241
247
  xy=(x_end, y_end),
242
248
  xytext=(x_end, y_end),fontsize=annotate_size)
@@ -249,12 +255,51 @@ def plot_line(df0,colname,collabel,ylabeltxt,titletxt,footnote,datatag=False, \
249
255
  plt.axhline(y=hline,ls=":",c="black",linewidth=2,label='')
250
256
  haveLegend=False
251
257
  else:
258
+ #不在必要,被attention_value的逻辑替代
252
259
  if isinstance(zeroline,float) or isinstance(zeroline,int):
253
260
  hline=zeroline
254
261
  plt.axhline(y=hline,ls=":",c="darkorange",linewidth=3,label=text_lang("关注值","Attention"))
255
262
  haveLegend=True
256
263
  footnote=footnote + text_lang(",关注值",", Attention ")+str(hline)
257
-
264
+
265
+ #用于关注值的颜色列表
266
+ atv_color_list=["lightgray","paleturquoise","wheat","khaki","lightsage"]
267
+ #用于关注点的颜色列表
268
+ atp_color_list=["slateblue","lightsteelblue","lightcyan","beige","thistle"]
269
+
270
+ if not attention_value=='':
271
+ if isinstance(attention_value,int) or isinstance(attention_value,float):
272
+ atv_list=[attention_value]
273
+ elif isinstance(attention_value,list):
274
+ atv_list=attention_value
275
+ else:
276
+ atv_list=[]
277
+ if not atv_list==[] and not atv_list==['']:
278
+ for at in atv_list:
279
+ pos=atv_list.index(at)
280
+ color=atv_color_list[pos]
281
+ plt.axhline(y=at,ls=":",c=color,linewidth=2,label=text_lang("关注值","Attention value ")+str(at))
282
+
283
+ if not attention_point=='':
284
+ if isinstance(attention_point,str) or isinstance(attention_point,int) or isinstance(attention_point,float):
285
+ atp_list=[attention_point]
286
+ elif isinstance(attention_point,list):
287
+ atp_list=attention_point
288
+ else:
289
+ atp_list=[]
290
+ if not atp_list==[] and not atp_list==['']:
291
+ import pandas as pd
292
+ for at in atp_list:
293
+ pos=atp_list.index(at)
294
+ color=atp_color_list[pos]
295
+
296
+ #判断是否日期字符串
297
+ try:
298
+ atpd=pd.to_datetime(at)
299
+ except:
300
+ atpd=at
301
+ plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
302
+
258
303
  if average_value:
259
304
  av=df[colname].mean()
260
305
  plt.axhline(y=av,ls="dashed",c="blueviolet",linewidth=2,label=text_lang("均值","Mean"))
@@ -300,6 +345,7 @@ def plot_line(df0,colname,collabel,ylabeltxt,titletxt,footnote,datatag=False, \
300
345
  plt.xlabel(footnote,fontsize=xlabel_txt_size,ha='center')
301
346
  plt.title(titletxt,fontweight='bold',fontsize=title_txt_size)
302
347
 
348
+ plt.legend()
303
349
  plt.show()
304
350
  plt.close()
305
351
 
@@ -322,7 +368,8 @@ def plot_line2(df1,ticker1,colname1,label1, \
322
368
  df2,ticker2,colname2,label2, \
323
369
  ylabeltxt,titletxt,footnote, \
324
370
  power=0,datatag1=False,datatag2=False,yscalemax=5, \
325
- zeroline=False,twinx=False,yline=999,xline=999, \
371
+ zeroline=False,twinx=False, \
372
+ yline=999,xline=999, \
326
373
  resample_freq='H',loc1='best',loc2='best', \
327
374
  color1='red',color2='blue',facecolor='whitesmoke'):
328
375
  """
@@ -336,6 +383,8 @@ def plot_line2(df1,ticker1,colname1,label1, \
336
383
  返回值:无
337
384
  注意:需要日期类型作为df索引
338
385
  """
386
+ DEBUG=False
387
+
339
388
  #空值判断
340
389
  if len(df1) ==0:
341
390
  print (" #Warning(plot_line2): no data to plot df1.")
@@ -344,11 +393,16 @@ def plot_line2(df1,ticker1,colname1,label1, \
344
393
  if (len(df1) ==0) and (len(df2) ==0):
345
394
  return
346
395
 
396
+ if DEBUG:
397
+ print("In plot_line2")
398
+ print("Going to plot_line2_coaxial")
399
+ print("yline=",yline,"; xline=",xline)
400
+
347
401
  if not twinx:
348
402
  plot_line2_coaxial(df1,ticker1,colname1,label1, \
349
403
  df2,ticker2,colname2,label2, \
350
404
  ylabeltxt,titletxt,footnote,power,datatag1,datatag2,zeroline, \
351
- yline,xline,resample_freq=resample_freq, \
405
+ yline=yline,xline=xline,resample_freq=resample_freq, \
352
406
  loc1=loc1,loc2=loc2, \
353
407
  color1=color1,color2=color2,facecolor=facecolor)
354
408
  else:
@@ -356,6 +410,7 @@ def plot_line2(df1,ticker1,colname1,label1, \
356
410
  df2,ticker2,colname2,label2, \
357
411
  titletxt,footnote,power,datatag1,datatag2, \
358
412
  resample_freq=resample_freq, \
413
+ xline=xline, \
359
414
  loc1=loc1,loc2=loc2, \
360
415
  color1=color1,color2=color2,facecolor=facecolor)
361
416
  return
@@ -440,6 +495,7 @@ def plot_line2_coaxial(df01,ticker1,colname1,label1, \
440
495
  返回值:无
441
496
  注意:需要日期类型作为df索引
442
497
  """
498
+ DEBUG=False
443
499
 
444
500
  #插值平滑
445
501
  try:
@@ -487,13 +543,61 @@ def plot_line2_coaxial(df01,ticker1,colname1,label1, \
487
543
  if zeroline:
488
544
  plt.axhline(y=0,ls=":",c="black",linewidth=2)
489
545
 
546
+ if DEBUG:
547
+ print("In plot_line2_coaxial:")
548
+ print("yline=",yline,"; xline=",xline)
549
+
490
550
  #是否绘制水平线
491
551
  if yline != 999:
492
- plt.axhline(y=yline,ls=":",c="black",linewidth=2)
552
+ attention_value=yline
553
+
554
+ #用于关注值的颜色列表
555
+ atv_color_list=["lightgray","paleturquoise","wheat","khaki","lightsage"]
556
+
557
+ if isinstance(attention_value,int) or isinstance(attention_value,float):
558
+ atv_list=[attention_value]
559
+ elif isinstance(attention_value,list):
560
+ atv_list=attention_value
561
+ else:
562
+ atv_list=[]
563
+
564
+ if DEBUG:
565
+ print("atv_list=",atv_list)
566
+
567
+ if not atv_list==[] and not atv_list==['']:
568
+ for at in atv_list:
569
+ pos=atv_list.index(at)
570
+ color=atv_color_list[pos]
571
+ plt.axhline(y=at,ls=":",c=color,linewidth=2,label=text_lang("关注值","Attention value ")+str(at))
493
572
 
494
573
  #是否绘制垂直线
495
574
  if xline != 999:
496
- plt.axvline(x=xline,ls=":",c="black",linewidth=1)
575
+ attention_point=xline
576
+ #用于关注点的颜色列表
577
+ atp_color_list=["slateblue","thistle","lightsteelblue","lightcyan","beige"]
578
+
579
+ if isinstance(attention_point,str) or isinstance(attention_point,int) or isinstance(attention_point,float):
580
+ atp_list=[attention_point]
581
+ elif isinstance(attention_point,list):
582
+ atp_list=attention_point
583
+ else:
584
+ atp_list=[]
585
+ if not atp_list==[] and not atp_list==['']:
586
+ import pandas as pd
587
+ for at in atp_list:
588
+ pos=atp_list.index(at)
589
+ color=atp_color_list[pos]
590
+
591
+ #判断是否日期字符串
592
+ try:
593
+ atpd=pd.to_datetime(at)
594
+ except:
595
+ atpd=at
596
+
597
+ if DEBUG:
598
+ print("atpd=",atpd)
599
+
600
+ plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
497
601
 
498
602
  #绘证券1:制趋势线
499
603
  if power > 0:
@@ -769,7 +873,9 @@ def plot_line2_coaxial2(df01,ticker1,colname1,label1, \
769
873
  def plot_line2_twinx(df01,ticker1,colname1,label1, \
770
874
  df02,ticker2,colname2,label2, \
771
875
  titletxt,footnote,power=0,datatag1=False,datatag2=False, \
772
- resample_freq='H',loc1='upper left',loc2='lower left', \
876
+ resample_freq='H', \
877
+ xline=999, \
878
+ loc1='upper left',loc2='lower left', \
773
879
  color1='red',color2='blue',facecolor='whitesmoke', \
774
880
  ticker_type='auto'):
775
881
  """
@@ -783,6 +889,8 @@ def plot_line2_twinx(df01,ticker1,colname1,label1, \
783
889
  返回值:无
784
890
  注意:需要日期类型作为df索引
785
891
  """
892
+ DEBUG=False
893
+
786
894
  #plt.rcParams['axes.grid']=False
787
895
 
788
896
  #插值平滑
@@ -825,6 +933,37 @@ def plot_line2_twinx(df01,ticker1,colname1,label1, \
825
933
  for x, y in zip(df1.index, df1[colname1]):
826
934
  ax.text(x,y+0.1,'%.2f' % y,ha='center',va='bottom',color='black')
827
935
 
936
+ #绘制关注点
937
+ if xline != 999:
938
+ attention_point=xline
939
+
940
+ #用于关注点的颜色列表
941
+ atp_color_list=["slateblue","thistle","lightsteelblue","lightcyan","beige"]
942
+
943
+ if isinstance(attention_point,str) or isinstance(attention_point,int) or isinstance(attention_point,float):
944
+ atp_list=[attention_point]
945
+ elif isinstance(attention_point,list):
946
+ atp_list=attention_point
947
+ else:
948
+ atp_list=[]
949
+
950
+ if DEBUG:
951
+ print("In plot_line2_twinx")
952
+ print("atp_list=",atp_list)
953
+
954
+ if not atp_list==[] and not atp_list==['']:
955
+ import pandas as pd
956
+ for at in atp_list:
957
+ pos=atp_list.index(at)
958
+ color=atp_color_list[pos]
959
+
960
+ #判断是否日期字符串
961
+ try:
962
+ atpd=pd.to_datetime(at)
963
+ except:
964
+ atpd=at
965
+ plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
966
+
828
967
  #绘证券1:制趋势线
829
968
  if power > 0:
830
969
  lang=check_language()
@@ -1117,6 +1256,8 @@ def plot_line2_twinx2(df01,ticker1,colname1,label1, \
1117
1256
  def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
1118
1257
  data_label=True,resample_freq='H',smooth=True,linewidth=1.5, \
1119
1258
  loc='best',annotate=False,annotate_value=False,plus_sign=False, \
1259
+ attention_value='', \
1260
+ attention_point='', \
1120
1261
  mark_top=False,mark_bottom=False,mark_end=False, \
1121
1262
  ticker_type='auto',facecolor='whitesmoke'):
1122
1263
  """
@@ -1229,7 +1370,15 @@ def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
1229
1370
  #plt.plot(dfg,label=codetranslate(c),linewidth=linewidth,ls=lsc,marker=mkc,markersize=3)
1230
1371
  plt.plot(dfg,label=c,linewidth=lwadjust,ls=lsc,marker=mkc,markersize=3)
1231
1372
  """
1232
- plt.plot(dfg,label=c,linewidth=lwadjust,ls=lsc,marker=mkc,markersize=3)
1373
+ if not annotate or c in ["平均值","中位数"]:
1374
+ if c in ["平均值","中位数"]:
1375
+ clabel=c+str(round(dfg[c].values[0],2))
1376
+ else:
1377
+ clabel=c
1378
+ plt.plot(dfg,label=clabel,linewidth=lwadjust,ls=lsc,marker=mkc,markersize=3)
1379
+ else:
1380
+ plt.plot(dfg,linewidth=lwadjust,ls=lsc,marker=mkc,markersize=3)
1381
+
1233
1382
  lines = plt.gca().lines
1234
1383
  last_line_color = lines[-1].get_color()
1235
1384
 
@@ -1274,7 +1423,7 @@ def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
1274
1423
  #y1=round(y+high_low*0.01,2)
1275
1424
  y1=y+high_low*0.01
1276
1425
  #s='%.0f' if y >= 100 else '%.2f'
1277
- s='%.2f' if abs(y) >= 100 else '%.2f' if abs(y) >= 10 else '%.3f'
1426
+ s='%.2f' if abs(y) >= 100 else '%.2f' if abs(y) >= 10 else '%.4f'
1278
1427
  #plt.text(x,y1,s % y,ha='center',va='bottom',color='red')
1279
1428
  plt.text(x,y1,s % y,ha='right',va='bottom',color=last_line_color)
1280
1429
  plt.scatter(x,y, color='red',marker='8',s=70)
@@ -1285,7 +1434,7 @@ def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
1285
1434
  #y1=round(y-high_low*0.055,2) #标记位置对应y1的底部
1286
1435
  y1=y-high_low*0.050 #标记位置对应y1的底部
1287
1436
  #s='%.0f' if y >= 100 else '%.2f'
1288
- s='%.2f' if abs(y) >= 100 else '%.2f' if abs(y) >= 10 else '%.3f'
1437
+ s='%.2f' if abs(y) >= 100 else '%.2f' if abs(y) >= 10 else '%.4f'
1289
1438
  #plt.text(x,y1,s % y,ha='center',va='bottom',color='seagreen')
1290
1439
  plt.text(x,y1,s % y,ha='right',va='bottom',color=last_line_color)
1291
1440
  plt.scatter(x,y, color='seagreen',marker='8',s=70)
@@ -1297,12 +1446,69 @@ def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
1297
1446
  x_end = df_end[c].idxmin() # 末端值的x坐标
1298
1447
 
1299
1448
  #y1=str(int(y_end)) if y_end >= 100 else str(round(y_end,2))
1300
- y1=str(round(y_end,2)) if abs(y_end) >= 100 else str(round(y_end,2)) if abs(y_end) >= 10 else str(round(y_end,3))
1449
+ y1=str(round(y_end,2)) if abs(y_end) >= 100 else str(round(y_end,2)) if abs(y_end) >= 10 else str(round(y_end,4))
1301
1450
  plt.annotate(text=' '+y1,
1302
1451
  xy=(x_end, y_end),
1303
1452
  xytext=(x_end, y_end),fontsize=annotate_size,
1304
1453
  color=last_line_color)
1305
1454
 
1455
+ #用于关注值的颜色列表
1456
+ atv_color_list=["lightgray","paleturquoise","wheat","khaki","lightsage"]
1457
+ #用于关注点的颜色列表
1458
+ atp_color_list=["slateblue","thistle","lightsteelblue","lightcyan","beige"]
1459
+
1460
+ if not attention_value=='':
1461
+ if isinstance(attention_value,int) or isinstance(attention_value,float):
1462
+ atv_list=[attention_value]
1463
+ elif isinstance(attention_value,list):
1464
+ atv_list=attention_value
1465
+ else:
1466
+ atv_list=[]
1467
+ if not atv_list==[] and not atv_list==['']:
1468
+ for at in atv_list:
1469
+ pos=atv_list.index(at)
1470
+ color=atv_color_list[pos]
1471
+ plt.axhline(y=at,ls=":",c=color,linewidth=2,label=text_lang("关注值","Attention value ")+str(at))
1472
+
1473
+ if not attention_point=='':
1474
+ if isinstance(attention_point,str) or isinstance(attention_point,int) or isinstance(attention_point,float):
1475
+ atp_list=[attention_point]
1476
+ elif isinstance(attention_point,list):
1477
+ atp_list=attention_point
1478
+ else:
1479
+ atp_list=[]
1480
+ if not atp_list==[] and not atp_list==['']:
1481
+ import pandas as pd
1482
+ for at in atp_list:
1483
+ pos=atp_list.index(at)
1484
+ color=atp_color_list[pos]
1485
+
1486
+ #判断是否日期字符串
1487
+ try:
1488
+ atpd=pd.to_datetime(at)
1489
+ except:
1490
+ atpd=at
1491
+
1492
+ """
1493
+ #纵轴最小值
1494
+ yaxis_min=plt.ylim()[0]
1495
+ arrow_dx=0
1496
+ #各曲线在关注点的最大值
1497
+ point_max=dfg.loc[atpd].max()
1498
+ arrow_dy=point_max - yaxis_min
1499
+
1500
+ if DEBUG:
1501
+ print("*** In draw_lines:")
1502
+ print("dfg.loc[atpd]",dfg.loc[atpd].values)
1503
+ print("yaxis_min=",yaxis_min)
1504
+ print("point_max=",point_max)
1505
+ print("arrow_dy=",arrow_dy)
1506
+
1507
+ plt.arrow(atpd,yaxis_min,arrow_dx,arrow_dy,ls=':',lw=2,fc=color,ec=color,alpha=0.5,shape='full', \
1508
+ width=0.05,length_includes_head=True)
1509
+ """
1510
+ plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
1511
+
1306
1512
  #绘制水平辅助线
1307
1513
  if axhline_label !="":
1308
1514
  if '零线' in axhline_label:
@@ -1328,8 +1534,8 @@ def draw_lines(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
1328
1534
  plt.gca().set_facecolor("whitesmoke")
1329
1535
 
1330
1536
  # 若不绘制annotate,则绘制图例
1331
- if not annotate:
1332
- plt.legend(loc=loc,fontsize=legend_txt_size)
1537
+ #if not annotate:
1538
+ plt.legend(loc=loc,fontsize=legend_txt_size)
1333
1539
 
1334
1540
  if plus_sign:
1335
1541
  # 尝试改变纵轴刻度格式:给正数添加正号+,以便突出显示增减幅度
@@ -1352,7 +1558,10 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
1352
1558
  data_label=False,resample_freq='6H',smooth=True, \
1353
1559
  date_range=False,date_freq=False,date_fmt='%Y-%m-%d', \
1354
1560
  colorlist=[],lslist=[],lwlist=[], \
1355
- band_area='',loc='best',annotate=False,annotate_value=False, \
1561
+ band_area='',loc='best', \
1562
+ attention_value='', \
1563
+ attention_point='', \
1564
+ annotate=False,annotate_value=False, \
1356
1565
  mark_top=False,mark_bottom=False,mark_end=False, \
1357
1566
  facecolor='whitesmoke'):
1358
1567
  """
@@ -1444,11 +1653,20 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
1444
1653
  llw=linewidth_adjust(df)
1445
1654
 
1446
1655
  if (lcolor !='') and (lls !=''):
1447
- plt.plot(df[c],label=c,linewidth=llw,ls=lls,color=lcolor)
1656
+ if not annotate:
1657
+ plt.plot(df[c],label=c,linewidth=llw,ls=lls,color=lcolor)
1658
+ else:
1659
+ plt.plot(df[c],linewidth=llw,ls=lls,color=lcolor)
1448
1660
  elif (lcolor !=''):
1449
- plt.plot(df[c],label=c,linewidth=llw,color=lcolor)
1661
+ if not annotate:
1662
+ plt.plot(df[c],label=c,linewidth=llw,color=lcolor)
1663
+ else:
1664
+ plt.plot(df[c],linewidth=llw,color=lcolor)
1450
1665
  else:
1451
- plt.plot(df[c],label=c,linewidth=llw)
1666
+ if not annotate:
1667
+ plt.plot(df[c],label=c,linewidth=llw)
1668
+ else:
1669
+ plt.plot(df[c],linewidth=llw)
1452
1670
 
1453
1671
  lines = plt.gca().lines; last_line_color = lines[-1].get_color()
1454
1672
 
@@ -1471,7 +1689,7 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
1471
1689
  #y1=round(y+high_low*0.01,2)
1472
1690
  y1=y+high_low*0.01
1473
1691
  #s='%.0f' if y >= 100 else '%.2f'
1474
- s='%.2f' if abs(y) >= 100 else '%.2f' if abs(y) >= 10 else '%.3f'
1692
+ s='%.2f' if abs(y) >= 100 else '%.2f' if abs(y) >= 10 else '%.4f'
1475
1693
  #plt.text(x,y1,s % y,ha='center',va='bottom',color='red')
1476
1694
  plt.text(x,y1,s % y,ha='right',va='bottom',color=last_line_color)
1477
1695
  plt.scatter(x,y, color='red',marker='8',s=70)
@@ -1482,7 +1700,7 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
1482
1700
  #y1=round(y-high_low*0.055,2) #标记位置对应y1的底部
1483
1701
  y1=y-high_low*0.050 #标记位置对应y1的底部
1484
1702
  #s='%.0f' if y >= 100 else '%.2f'
1485
- s='%.2f' if abs(y) >= 100 else '%.2f' if abs(y) >= 10 else '%.3f'
1703
+ s='%.2f' if abs(y) >= 100 else '%.2f' if abs(y) >= 10 else '%.4f'
1486
1704
  #plt.text(x,y1,s % y,ha='center',va='bottom',color='seagreen')
1487
1705
  plt.text(x,y1,s % y,ha='right',va='bottom',color=last_line_color)
1488
1706
  plt.scatter(x,y, color='seagreen',marker='8',s=70)
@@ -1495,7 +1713,7 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
1495
1713
 
1496
1714
  if annotate_value: #在标记曲线名称的同时标记其末端数值
1497
1715
  #y1=str(int(y_end)) if y_end >= 100 else str(round(y_end,2))
1498
- y1=str(int(y_end)) if abs(y_end) >= 100 else str(round(y_end,2)) if abs(y_end) >= 10 else str(round(y_end,3))
1716
+ y1=str(int(y_end)) if abs(y_end) >= 100 else str(round(y_end,2)) if abs(y_end) >= 10 else str(round(y_end,4))
1499
1717
  plt.annotate(text=c+':'+y1,
1500
1718
  xy=(x_end, y_end),
1501
1719
  xytext=(x_end, y_end),fontsize=annotate_size,
@@ -1551,6 +1769,44 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
1551
1769
  plt.axhline(y=axhline_value,color='black',linestyle='--',linewidth=2)
1552
1770
  else:
1553
1771
  plt.axhline(y=axhline_value,label=axhline_label,color='black',linestyle='--',linewidth=2)
1772
+
1773
+ #用于关注值的颜色列表
1774
+ atv_color_list=["lightgray","paleturquoise","wheat","khaki","lightsage"]
1775
+ #用于关注点的颜色列表
1776
+ atp_color_list=["slateblue","thistle","lightsteelblue","lightcyan","beige"]
1777
+
1778
+ if not attention_value=='':
1779
+ if isinstance(attention_value,int) or isinstance(attention_value,float):
1780
+ atv_list=[attention_value]
1781
+ elif isinstance(attention_value,list):
1782
+ atv_list=attention_value
1783
+ else:
1784
+ atv_list=[]
1785
+ if not atv_list==[] and not atv_list==['']:
1786
+ for at in atv_list:
1787
+ pos=atv_list.index(at)
1788
+ color=atv_color_list[pos]
1789
+ plt.axhline(y=at,ls=":",c=color,linewidth=2,label=text_lang("关注值","Attention value ")+str(at))
1790
+
1791
+ if not attention_point=='':
1792
+ if isinstance(attention_point,str) or isinstance(attention_point,int) or isinstance(attention_point,float):
1793
+ atp_list=[attention_point]
1794
+ elif isinstance(attention_point,list):
1795
+ atp_list=attention_point
1796
+ else:
1797
+ atp_list=[]
1798
+ if not atp_list==[] and not atp_list==['']:
1799
+ import pandas as pd
1800
+ for at in atp_list:
1801
+ pos=atp_list.index(at)
1802
+ color=atp_color_list[pos]
1803
+
1804
+ #判断是否日期字符串
1805
+ try:
1806
+ atpd=pd.to_datetime(at)
1807
+ except:
1808
+ atpd=at
1809
+ plt.axvline(x=atpd,ls=":",c=color,linewidth=1.5,label=text_lang("关注点","Attention point ")+str(at))
1554
1810
 
1555
1811
  #坐标轴标记
1556
1812
  plt.ylabel(y_label,fontweight='bold',fontsize=ylabel_txt_size)
@@ -1565,8 +1821,8 @@ def draw_lines2(df0,y_label,x_label,axhline_value,axhline_label,title_txt, \
1565
1821
  print(" #Warning(draw_lines2): color",facecolor,"is unsupported, changed to default setting")
1566
1822
  plt.gca().set_facecolor("whitesmoke")
1567
1823
 
1568
- if not annotate:
1569
- plt.legend(loc=loc,fontsize=legend_txt_size)
1824
+ #if not annotate:
1825
+ plt.legend(loc=loc,fontsize=legend_txt_size)
1570
1826
 
1571
1827
  #设置绘图风格:关闭网格虚线
1572
1828
  plt.rcParams['axes.grid']=False
siat/option_china.py CHANGED
@@ -2457,7 +2457,7 @@ def fin_option_maturity_risk_sse(option,exercise,trade_date, \
2457
2457
  #label2=measure
2458
2458
  #ylabeltxt="风险指标"
2459
2459
  ylabeltxt=ectranslate(measure)
2460
- titletxt='希腊值风险趋势:'+option+'期权,到期时间对'+ylabeltxt+"的影响"
2460
+ titletxt='希腊值风险趋势:'+option+'期权,到期期限对'+ylabeltxt+"的影响"
2461
2461
 
2462
2462
  footnote0="到期时间(不同期权)\n"
2463
2463
  footnote1=option+"期权"+",行权股指点位"+str(exercise)+",交易日"+trade_date