目录
运行情况:
代码:
承接 【python_PyQt5开发验证K线视觉想法工具V1.0】 博文
https://blog.csdn.net/m0_37967652/article/details/131966298
运行情况:
添加线段数据在K线图中用线段绘制出来
代码:
1 线段标记的数据格式:
[[[x0,y0],[x1,y1]],[[x0,y0],[x1,y1]],...]
[x0,y0]和[x1,y1]是线段两个端点的坐标
2 在 Graph_Widget类中 add_marks 方法修改为
def add_marks(self,data:List):
# 点,曲线,区间
# '标题','规则','形状','颜色','数据'
self.del_marks()
for row in data:
try:
rule_str = row[1]
shape_str = row[2]
color_str = row[3]
data_str = row[4]
data_json = json.loads(data_str)
if rule_str == '点':
for node in data_json:
targetItem = pg.TargetItem(
pos=node,
size=20,
symbol=self.pointshape_map[shape_str],
pen=color_str,
brush=color_str,
movable=False
)
self.pw.addItem(targetItem)
self.add_items_list.append(targetItem)
pass
if rule_str == '线段':
for node in data_json:
targetItem = pg.LineSegmentROI(positions=(node[0],node[1]),
pen={'color':color_str,'width':2},
movable=False)
self.pw.addItem(targetItem)
self.add_items_list.append(targetItem)
pass
pass
if rule_str == '连线':
for node in data_json:
targetItem = pg.PlotCurveItem(
x=node[0],
y=node[1],
pen=color_str,
symbol=self.pointshape_map[shape_str]
)
self.pw.addItem(targetItem)
self.add_items_list.append(targetItem)
pass
pass
if rule_str == '区间':
for node in data_json:
targetItem = pg.LinearRegionItem(
values=node,
pen=color_str,
movable=False
)
self.pw.addItem(targetItem)
self.add_items_list.append(targetItem)
pass
pass
except Exception as e:
print(e)
continue
pass
pass
3 在SettingMarksWidget 类中
init_data 方法
def init_data(self):
self.please_select_str: str = '-- 请选择 --'
self.rule_map: Dict = {
'点':'数据格式提示:[[x,y],[x,y],...]',
'线段':'[[(x0,y0),(x1,y1)],[(x0,y0),(x1,y1)],...]',
'连线':'数据格式提示:[[x_list,y_list],...]',
'区间':'数据格式提示:[[x0,x1],[x0,x1],...]'
}
self.no_pointshape_rules_list: List = ['线段','区间']
self.pointshape_map: Dict = {
'圆':'o',
'三角形':'t',
'星形':'star',
'正方形':'s',
'菱形':'d',
'加号':'+',
'向下箭头':'arrow_down',
'向左箭头':'arrow_left',
'向上箭头':'arrow_up',
'向右箭头':'arrow_right'
}
pass
rule_combox_currentTextChanged 方法
def rule_combox_currentTextChanged(self,txt:str):
cur_txt = self.rule_combox.currentText()
if not cur_txt or cur_txt == self.please_select_str:
self.rule_label.setText('')
return
self.rule_label.setText(self.rule_map[cur_txt])
if cur_txt in self.no_pointshape_rules_list:
self.pointshape_combox.setCurrentText(self.please_select_str)
self.pointshape_combox.setDisabled(True)
else:
self.pointshape_combox.setDisabled(False)
pass