def draw(self): # Draw the corner boxes self.draw_rectangle( Rectangle(self.llcorner + Point(-25, 0), self.llcorner + Point(-2, 22))) self.draw_rectangle( Rectangle(self.lrcorner + Point(2, 0), self.lrcorner + Point(25, 22))) p = self.lrcorner + Point(13.5, 16) self.draw_label(Label(p, text="CHART NUMBER", fontsize="footnotesize")) p = self.lrcorner + Point(13.5, 0) self.draw_label( Label(p, text=f"\\textbf{{{self.chart_number}}}", fontsize="HUGE"))
def test_pythagoras(self): t = Tikz("tikz_test3") with TikzPicture(t, Point(20, 20), Point(190, 277)) as p: p1 = Point(55, 98.5) p2 = Point(115, 98.5) p3 = Point(55, 128.5) p.draw_polygon([p1, p2, p3], cycle=True) p.draw_rectangle(Rectangle(p1, p1 + Point(60, -60))) p.draw_rectangle(Rectangle(p1, p1 + Point(-30, 30))) p4 = p3.rotate(-90, p2) p5 = p2.rotate(90, p3) p.draw_polygon([p2, p4, p5, p3]) t.render()
def test_picture(self): t = Tikz("tizk_test1") p = TikzPicture(t, Point(20, 20), Point(190, 277)) p.draw_circle(Circle(Point(85, 128.5), 30)) p.draw_rectangle(Rectangle(Point(55, 98.5), Point(115, 158.5))) p.draw_circle(Circle(Point(85, 128.5), 95)) t.render()
def test_multiple_pictures(self): t = Tikz("tikz_test2") p1 = TikzPicture(t, Point(20, 20), Point(190, 138.5)) p1.draw_circle(Circle(Point(85, 59.25), 30)) p1.draw_rectangle(Rectangle(Point(55, 29.25), Point(115, 89.25))) p2 = TikzPicture(t, Point(20, 158.5), Point(95, 277)) p2.draw_circle(Circle(Point(37.5, 59.25), 30)) p2.draw_rectangle(Rectangle(Point(7.5, 29.25), Point(67.5, 89.25))) with p2.clip(): p2.draw_circle(Circle(Point(37.5, 59.25), 40)) p3 = TikzPicture(t, Point(115, 158.5), Point(190, 277)) p3.draw_circle(Circle(Point(37.5, 59.25), 30)) p3.draw_rectangle(Rectangle(Point(7.5, 29.25), Point(67.5, 89.25))) t.render()
def set_origin(self, origin): self.origin = origin self.minx = self.p1.x - self.origin.x self.maxx = self.p2.x - self.origin.x self.miny = self.p1.y - self.origin.y self.maxy = self.p2.y - self.origin.y self.bounding_box = Rectangle(Point(self.minx, self.miny), Point(self.maxx, self.maxy))
def draw(self): if self.outer_border: old_linewidth = self.linewidth self.linewidth = self.config.outer_border_linewidth self.draw_rectangle( Rectangle(self.outer_llcorner, self.outer_urcorner)) self.linewidth = old_linewidth if self.config.clipbox is not None: with self.clip(self.config.clipbox): self.draw_grid() else: self.draw_grid()
def set_origin(self, origin): """ Sets the location of the origin of the coordinate system for the picture. The minimum and maximum x and y values for the picture, as well as the bounding box, are determined as well. Args: origin (skymap.geometry.Point): the location in absolute paper coordinates """ self.origin = origin self.minx = self.p1.x - self.origin.x self.maxx = self.p2.x - self.origin.x self.miny = self.p1.y - self.origin.y self.maxy = self.p2.y - self.origin.y self.bounding_box = Rectangle(Point(self.minx, self.miny), Point(self.maxx, self.maxy))
return f, m if __name__ == "__main__": if not os.path.exists(OUTPUT_FOLDER): os.makedirs(OUTPUT_FOLDER) chart_number = 1 # North azimuthal maps # Left page f, m = azimuthal_map(chart_number, 'left', True) p1 = Point(-PAPERSIZE[0], -PAPERSIZE[1]) p2 = Point(m.map_box.p2.x, PAPERSIZE[1]) with m.clip(Rectangle(p1, p2).path): m.draw_meridians(origin_offsets=AZIMUTHAL_OFFSETS) m.draw_parallels() with m.clip(m.clipping_path): m.draw_constellations(linewidth=0.3) m.draw_ecliptic(linewidth=ECLIPTIC_LINEWIDTH, tickinterval=1, dashed=ECLIPTIC_DASH_PATTERN, poles=True) m.draw_galactic(linewidth=GALACTIC_LINEWIDTH, tickinterval=1, dashed=GALACTIC_DASH_PATTERN, poles=True) # Legend
def margin_box(self): bb = self.bounding_box return Rectangle(Point(bb.p1.x - self.margin, bb.p1.y - self.margin), Point(bb.p2.x + self.margin, bb.p2.y + self.margin))
def margin_box_pos(self, pos): bb = self.bounding_box_pos(pos) return Rectangle(Point(bb.p1.x - self.margin, bb.p1.y - self.margin), Point(bb.p2.x + self.margin, bb.p2.y + self.margin))
def bounding_box_pos(self, pos): index = self.positions.index(pos) p1 = self.point + self.bb_vectors[index] return Rectangle(p1, p1 + Point(self.size))
def __init__(self, p1, p2, origin=None, hmargin=0, vmargin=0, box=True): if origin is None: origin = 0.5 * (p1 + p2) DrawingArea.__init__(self, p1, p2, origin, box) # Total map self.map_hmargin = hmargin self.map_vmargin = vmargin # Central map area self.map_width = float(self.width - 2 * self.map_hmargin) self.map_height = float(self.height - 2 * self.map_vmargin) self.map_minx = self.p1.x + self.map_hmargin - self.origin.x self.map_maxx = self.map_minx + self.map_width self.map_miny = self.p1.y + self.map_vmargin - self.origin.y self.map_maxy = self.map_miny + self.map_height self.map_llcorner = Point(self.map_minx, self.map_miny) self.map_lrcorner = Point(self.map_maxx, self.map_miny) self.map_urcorner = Point(self.map_maxx, self.map_maxy) self.map_ulcorner = Point(self.map_minx, self.map_maxy) self.map_bottom_border = Line(self.map_llcorner, self.map_lrcorner) self.map_right_border = Line(self.map_lrcorner, self.map_urcorner) self.map_top_border = Line(self.map_urcorner, self.map_ulcorner) self.map_left_border = Line(self.map_ulcorner, self.map_llcorner) self.map_box = Rectangle(self.map_llcorner, self.map_urcorner) self.projection = UnitProjection() # Longitude/latitude ranges self.min_longitude = None self.max_longitude = None self.min_latitude = None self.max_latitude = None self.bordered = True # Longitude/latitude grid self.gridline_factory = GridLineFactory() self.gridline_factory.marked_ticksize = 1.0 self.gridline_factory.unmarked_ticksize = 0.5 self.gridline_factory.meridian_line_interval = 15 # 1 hour self.gridline_factory.meridian_marked_tick_interval = 5 # 20 minutes self.gridline_factory.meridian_tick_interval = 1.25 # 5 minutes self.gridline_factory.parallel_line_interval = 10 self.gridline_factory.parallel_marked_tick_interval = 10 self.gridline_factory.parallel_tick_interval = 1 self.parallel_ticks = { 'left': True, 'right': True, 'bottom': False, 'top': False } self.meridian_ticks = { 'left': False, 'right': False, 'bottom': True, 'top': True }
mc.coordinate_grid_config.meridian_line_interval = 15 mc.coordinate_grid_config.meridian_marked_tick_interval = 15 mc.coordinate_grid_config.meridian_tick_interval = 15 mc.coordinate_grid_config.meridian_tick_borders = ["bottom"] mc.coordinate_grid_config.parallel_tick_borders = ["internal"] mc.coordinate_grid_config.parallel_internal_labels = True mc.coordinate_grid_config.internal_label_longitude = 0 mc.coordinate_grid_config.meridian_labeltextfunc = ( azimuthal_meridian_label) mc.coordinate_grid_config.flip_meridian_labels = False if left: mc.clipbox = Rectangle( Point(-PAPERSIZE.width, -PAPERSIZE.height), Point( 4 * MM_PER_DEGREE + 0.2 * mc.coordinate_grid_config.linewidth, PAPERSIZE.height, ), ).path mc.llcorner = p.llcorner + Point(7, LEGEND_HEIGHT + 23) mc.origin = mc.llcorner + Point( 6 * MM_PER_DEGREE, 0.5 * mc.latitude_range * MM_PER_DEGREE) else: mc.clipbox = Rectangle( Point( -4 * MM_PER_DEGREE - 0.2 * mc.coordinate_grid_config.linewidth, -PAPERSIZE.height, ), Point(PAPERSIZE.width, PAPERSIZE.height),
# Open log file with open(os.path.join(TEX_OUTPUT_FOLDER, self.name + ".log"), "r") as fp: output = fp.read() if xelatex_error: self.logger.debug(output) raise xelatex_error # Move output file if filepath: folder = os.path.dirname(filepath) if folder and not os.path.exists(folder): os.makedirs(folder) shutil.move(os.path.join(TEX_OUTPUT_FOLDER, f"{self.name}.pdf"), filepath) if open_pdf: subprocess.Popen(["open", filepath]).wait() return output if __name__ == "__main__": from skymap.tikz import TikzPicture from skymap.geometry import Circle, Rectangle, Point t = Tikz("tizk_test1") with TikzPicture(t, Point(20, 20), Point(190, 277)) as p: p.draw_circle(Circle(Point(85, 128.5), 30)) p.draw_rectangle(Rectangle(Point(55, 98.5), Point(115, 158.5))) t.render(verbose=True)