diff --git a/工具v2/生成直方图代码.py b/工具v2/生成直方图代码.py index e858e646..c3bbe062 100644 --- a/工具v2/生成直方图代码.py +++ b/工具v2/生成直方图代码.py @@ -20,6 +20,19 @@ class MyWindow(QWidget,Ui_Form): for x in self.xlist: output += f"({x},)[]\n" 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): xlabel = self.lineEdit_xlabel.text() coordinateinfo = self.plainTextEdit_yinfo.toPlainText() @@ -29,8 +42,8 @@ class MyWindow(QWidget,Ui_Form): self.xstart = self.xmin - self.xwidth self.xmax = self.xlist[-1] + self.xwidth self.xend = self.xmax + self.xwidth #计算x轴的终点坐标 - xscale = 5/(self.xend-self.xstart) #计算x放缩比例 - # print(xscale) + self.xscale = 5/(self.xend-self.xstart) #计算x放缩比例 + # print(self.xscale) self.coordinatelist = re.findall(r"\(([\d\.]+),([\d\.]+)\)\[([\S]*)\]",coordinateinfo) #计算坐标信息 for cindex in range(len(self.coordinatelist)): x,y,label = self.coordinatelist[cindex] @@ -59,13 +72,13 @@ class MyWindow(QWidget,Ui_Form): self.dashedstr = ",".join(self.dashedstr_raw) # print(self.dasheddict) ymax = max([float(i) for i in self.dasheddict.keys()]) - yscale = 3/ymax #3是y的长度, 计算y放缩比例 - self.yend = ymax + 1/float(yscale) + self.yscale = 3/ymax #3是y的长度, 计算y放缩比例 + self.yend = ymax + 1/float(self.yscale) latexcode = f"""\\begin{{center}} - \\begin{{tikzpicture}}[>=latex, xscale = {xscale:.2f}, yscale = {yscale:.2f}] - \\draw [->] ({self.xstart},0) -- ({self.xend},0) node [below right] {{{xlabel}}}; + \\begin{{tikzpicture}}[>=latex, xscale = {self.xscale:.4f}, yscale = {self.yscale:.4f}] + \\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) node [below] {{${self.xstart}$}}; + \\draw ({self.xstart},0) node [below] {{$0$}}; \\foreach \\i/\\j in {{{self.coordinatestr}}} {{\\draw (\\i,0) node [below] {{$\\i$}} --++ (0,\\j) --++ ({self.xwidth},0) --++ (0,-\\j);}}; \\draw ({self.xmax},0) node [below] {{${self.xmax}$}};