更新生成直方图代码功能, x轴上可以画出必要的折线
This commit is contained in:
parent
293c9919d9
commit
752db716f1
|
|
@ -20,6 +20,19 @@ class MyWindow(QWidget,Ui_Form):
|
||||||
for x in self.xlist:
|
for x in self.xlist:
|
||||||
output += f"({x},)[]\n"
|
output += f"({x},)[]\n"
|
||||||
self.plainTextEdit_yinfo.setPlainText(output)
|
self.plainTextEdit_yinfo.setPlainText(output)
|
||||||
|
def folding(self):
|
||||||
|
if self.xmin <= self.xwidth:
|
||||||
|
foldingstr = ""
|
||||||
|
else:
|
||||||
|
midpoint = 1/2 * (self.xstart + self.xmin)
|
||||||
|
dist = (midpoint - self.xstart) / 6
|
||||||
|
foldingstr = ""
|
||||||
|
height = 0.2/self.yscale
|
||||||
|
foldingstr += f" -- ({(self.xstart+dist*4):.2f},0)"
|
||||||
|
foldingstr += f" -- ({(self.xstart+dist*5):.2f},{height:.4f})"
|
||||||
|
foldingstr += f" -- ({(self.xstart+dist*7):.2f},{-height:.4f})"
|
||||||
|
foldingstr += f" -- ({(self.xstart+dist*8):.2f},0)"
|
||||||
|
return foldingstr
|
||||||
def exec(self):
|
def exec(self):
|
||||||
xlabel = self.lineEdit_xlabel.text()
|
xlabel = self.lineEdit_xlabel.text()
|
||||||
coordinateinfo = self.plainTextEdit_yinfo.toPlainText()
|
coordinateinfo = self.plainTextEdit_yinfo.toPlainText()
|
||||||
|
|
@ -29,8 +42,8 @@ class MyWindow(QWidget,Ui_Form):
|
||||||
self.xstart = self.xmin - self.xwidth
|
self.xstart = self.xmin - self.xwidth
|
||||||
self.xmax = self.xlist[-1] + self.xwidth
|
self.xmax = self.xlist[-1] + self.xwidth
|
||||||
self.xend = self.xmax + self.xwidth #计算x轴的终点坐标
|
self.xend = self.xmax + self.xwidth #计算x轴的终点坐标
|
||||||
xscale = 5/(self.xend-self.xstart) #计算x放缩比例
|
self.xscale = 5/(self.xend-self.xstart) #计算x放缩比例
|
||||||
# print(xscale)
|
# print(self.xscale)
|
||||||
self.coordinatelist = re.findall(r"\(([\d\.]+),([\d\.]+)\)\[([\S]*)\]",coordinateinfo) #计算坐标信息
|
self.coordinatelist = re.findall(r"\(([\d\.]+),([\d\.]+)\)\[([\S]*)\]",coordinateinfo) #计算坐标信息
|
||||||
for cindex in range(len(self.coordinatelist)):
|
for cindex in range(len(self.coordinatelist)):
|
||||||
x,y,label = self.coordinatelist[cindex]
|
x,y,label = self.coordinatelist[cindex]
|
||||||
|
|
@ -59,13 +72,13 @@ class MyWindow(QWidget,Ui_Form):
|
||||||
self.dashedstr = ",".join(self.dashedstr_raw)
|
self.dashedstr = ",".join(self.dashedstr_raw)
|
||||||
# print(self.dasheddict)
|
# print(self.dasheddict)
|
||||||
ymax = max([float(i) for i in self.dasheddict.keys()])
|
ymax = max([float(i) for i in self.dasheddict.keys()])
|
||||||
yscale = 3/ymax #3是y的长度, 计算y放缩比例
|
self.yscale = 3/ymax #3是y的长度, 计算y放缩比例
|
||||||
self.yend = ymax + 1/float(yscale)
|
self.yend = ymax + 1/float(self.yscale)
|
||||||
latexcode = f"""\\begin{{center}}
|
latexcode = f"""\\begin{{center}}
|
||||||
\\begin{{tikzpicture}}[>=latex, xscale = {xscale:.2f}, yscale = {yscale:.2f}]
|
\\begin{{tikzpicture}}[>=latex, xscale = {self.xscale:.4f}, yscale = {self.yscale:.4f}]
|
||||||
\\draw [->] ({self.xstart},0) -- ({self.xend},0) node [below right] {{{xlabel}}};
|
\\draw [->] ({self.xstart},0) {self.folding()}-- ({self.xend},0) node [below right] {{{xlabel}}};
|
||||||
\\draw [->] ({self.xstart},0) -- ({self.xstart},{self.yend:.2f}) node [left] {{$\\dfrac{{\\text{{频率}}}}{{\\text{{组距}}}}$}};
|
\\draw [->] ({self.xstart},0) -- ({self.xstart},{self.yend:.2f}) node [left] {{$\\dfrac{{\\text{{频率}}}}{{\\text{{组距}}}}$}};
|
||||||
\\draw ({self.xstart},0) node [below] {{${self.xstart}$}};
|
\\draw ({self.xstart},0) node [below] {{$0$}};
|
||||||
\\foreach \\i/\\j in {{{self.coordinatestr}}}
|
\\foreach \\i/\\j in {{{self.coordinatestr}}}
|
||||||
{{\\draw (\\i,0) node [below] {{$\\i$}} --++ (0,\\j) --++ ({self.xwidth},0) --++ (0,-\\j);}};
|
{{\\draw (\\i,0) node [below] {{$\\i$}} --++ (0,\\j) --++ ({self.xwidth},0) --++ (0,-\\j);}};
|
||||||
\\draw ({self.xmax},0) node [below] {{${self.xmax}$}};
|
\\draw ({self.xmax},0) node [below] {{${self.xmax}$}};
|
||||||
|
|
|
||||||
Reference in New Issue