def get_latex_question(self, question): latex_question = TikZ() with latex_question.create(Axis(options=question.axis_options)) as ax: ax.append( Plot(options=question.plot_options, coordinates=question.coords)) # TODO: check for class type better if hasattr(question, 'small_left_node_text'): # MatrixFivePoints ax.append( self.node(at=('axis cs: 0', question.small_node_y), options=question.small_node_options, text=question.small_left_node_text)) ax.append( self.node(at=('axis cs: 6', question.small_node_y), options=question.small_node_options, text=question.small_right_node_text)) latex_question.append( self.node(at=question.question_node_at, text=question.question_title, options=question.node_options)) return latex_question
(-3.55556, 347.84069), (-2.33333, 22.58953), (-1.11111, -493.50066), (0.11111, 46.66082), (1.33333, -205.56286), (2.55556, -341.40638), (3.77778, -1169.24780), (5.00000, -3269.56775), ] plot2 = Plot(name='estimate', coordinates=coordinates) axis.append(plot1) axis.append(plot2) tikz.append(axis) plot_section = Subsection('Random graph', data=[tikz]) section.append(plot_section) doc.append(section) doc.generate_pdf() ########NEW FILE######## __FILENAME__ = numpy_ex #!/usr/bin/python import numpy as np
def _grid(self, pic: pylatex.TikZ): l = self.params["left"] r = self.params["right"] t = self.params["top"] b = self.params["bottom"] h = b # cm w = l # cm W = A4_W - (l + r) # cm H = A4_H - (t + b) # cm if self.params["title"] is not None: xy = pylatex.TikZCoordinate( 0.5 * A4_W, A4_H - 0.5 * t, ) pic.append(pylatex.Command('Huge')) pic.append(pylatex.TikZNode(at=xy, text=self.params["title"])) pic.append(pylatex.Command('normalsize')) if self.params["subtitle"] is not None: xy = pylatex.TikZCoordinate( 0.5 * A4_W, A4_H - 0.7 * t, ) pic.append(pylatex.Command('Large')) pic.append(pylatex.TikZNode(at=xy, text=self.params["subtitle"])) pic.append(pylatex.Command('normalsize')) if self.params["logo"] is not None: lw = self.params["logo-width"] xy = pylatex.TikZCoordinate( w + 0.5 * lw, A4_H - 0.5 * t, ) tx = pylatex.Command("includegraphics", arguments=[self.params["logo"]], options=[f"width={lw:.2f}cm"]) pic.append(pylatex.TikZNode(at=xy, text=tx.dumps())) pic.append( pylatex.TikZDraw(["(0, 0)", "rectangle", f"({A4_W}, {A4_H})"])) M = WEEK_DAYS N = self.params["hours"] S = self.params["start"] WEEK_MAP = self.WEEK_MAP[self.params['lang']] dx = (W / (M + 1)) dy = (H / (N + 1)) # -*- Vertical Lines and Day Names -*- for i in range(1, M + 1): x = w + i * dx y = h + H Y = h pic.append( pylatex.TikZDraw( [f"({x:.2f}, {y:.2f})", "--", f"({x:.2f}, {Y:.2f})"])) xx = x + 0.5 * dx yy = y - 0.5 * dy xy = pylatex.TikZCoordinate(round(xx, 2), round(yy, 2)) pic.append(pylatex.TikZNode(at=xy, text=WEEK_MAP[i - 1])) # -*- Finish Grid -*- x = w + W y = h Y = h + H pic.append( pylatex.TikZDraw( [f"({x:.2f}, {y:.2f})", "--", f"({x:.2f}, {Y:.2f})"])) # -*- Close Hours Section -*- x = w y = h Y = h + H - dy pic.append( pylatex.TikZDraw( [f"({x:.2f}, {y:.2f})", "--", f"({x:.2f}, {Y:.2f})"])) # -*- Horizontal Lines and Hourly Times -*- for j in range(1, N + 1): x = w X = w + W y = h + H - j * dy - dy xx = x + 0.5 * dx yy = y + 0.5 * dy xy = pylatex.TikZCoordinate(xx, yy) pic.append(pylatex.TikZNode(at=xy, text=f"{S+j-1:02d}:00")) pic.append( pylatex.TikZDraw( [f"({x:.2f}, {y:.2f})", "--", f"({X:.2f}, {y:.2f})"])) # -*- Finish Grid -*- x = w X = w + W y = h + H - dy pic.append( pylatex.TikZDraw( [f"({x:.2f}, {y:.2f})", "--", f"({X:.2f}, {y:.2f})"])) # -*- Close Days Section -*- x = w + dx X = w + W y = h + H pic.append( pylatex.TikZDraw( [f"({x:.2f}, {y:.2f})", "--", f"({X:.2f}, {y:.2f})"])) # -*- Place Events -*- for root in self.roots: while True: if root.a != root.b: # -*- Draw Something -*- x = w + dx * (root.d + 1) X = w + dx * (root.D + 1) y = h + H - dy * ((root.h - S + root.m / HOUR_MINS) + 1) Y = h + H - dy * ((root.H - S + root.M / HOUR_MINS) + 1) fill = self.pallete(root.label) # opts = pylatex.TikZOptions(fill=fill) pic.append( pylatex.NoEscape( f"\\draw [text width={abs(X-x):.2f}cm, align=center, fill={fill}] ({x:.2f}, {y:.2f}) rectangle ({X:.2f}, {Y:.2f}) node[midway] {{{root.label}}};" )) # xx = 0.5 * (x + X) # yy = 0.5 * (y + Y) # xy = pylatex.TikZCoordinate(xx, yy) # pic.append(pylatex.TikZNode(at=xy, text=root.label)) if root._down is not None: root = root._down else: break
tikz = TikZ() axis = Axis(options='height=6cm, width=6cm, grid=major') plot1 = Plot(name='model', func='-x^5 - 242') coordinates = [ (-4.77778, 2027.60977), (-3.55556, 347.84069), (-2.33333, 22.58953), (-1.11111, -493.50066), (0.11111, 46.66082), (1.33333, -205.56286), (2.55556, -341.40638), (3.77778, -1169.24780), (5.00000, -3269.56775), ] plot2 = Plot(name='estimate', coordinates=coordinates) axis.append(plot1) axis.append(plot2) tikz.append(axis) plot_section = Subsection('Random graph', data=[tikz]) section.append(plot_section) doc.append(section) doc.generate_pdf()