예제 #1
0
    def draw(self, clear=None, update=None):
        # obsolete kwargs clear, update (unused) just kept for compatibility
        GRWidget.draw(self, clear, update)
        gr.setwsviewport(0, self.mwidth, 0, self.mheight)
        gr.setwswindow(0, self.sizex, 0, self.sizey)

        for plot in self._lstPlot:
            plot.sizex, plot.sizey = self.sizex, self.sizey
            plot.drawGR()
            # logDomainCheck
            logXinDomain = plot.logXinDomain()
            logYinDomain = plot.logYinDomain()
            if logXinDomain != self._logXinDomain:
                self._logXinDomain = logXinDomain
                self.logXinDomain.emit(self._logXinDomain)
            if logYinDomain != self._logYinDomain:
                self._logYinDomain = logYinDomain
                self.logYinDomain.emit(self._logYinDomain)

        if self._pickEvent:
            event = self._pickEvent
            gr.setviewport(*event.viewportscaled)
            wcPoint = event.getWC(event.viewport)
            window = gr.inqwindow()
            gr.setwindow(*event.getWindow())
            gr.setmarkertype(gr.MARKERTYPE_PLUS)
            gr.polymarker([wcPoint.x], [wcPoint.y])
            gr.setwindow(*window)
예제 #2
0
    def draw(self, clear=None, update=None):
        # obsolete kwargs clear, update (unused) just kept for compatibility
        GRWidget.draw(self, clear, update)
        gr.setwsviewport(0, self.mwidth, 0, self.mheight)
        gr.setwswindow(0, self.sizex, 0, self.sizey)

        for plot in self._lstPlot:
            plot.sizex, plot.sizey = self.sizex, self.sizey
            plot.drawGR()
            # logDomainCheck
            logXinDomain = plot.logXinDomain()
            logYinDomain = plot.logYinDomain()
            if logXinDomain != self._logXinDomain:
                self._logXinDomain = logXinDomain
                self.logXinDomain.emit(self._logXinDomain)
            if logYinDomain != self._logYinDomain:
                self._logYinDomain = logYinDomain
                self.logYinDomain.emit(self._logYinDomain)

        if self._pickEvent:
            event = self._pickEvent
            gr.setviewport(*event.viewport)
            wcPoint = event.getWC(event.viewport)
            window = gr.inqwindow()
            gr.setwindow(*event.getWindow())
            gr.setmarkertype(gr.MARKERTYPE_PLUS)
            gr.polymarker([wcPoint.x], [wcPoint.y])
            gr.setwindow(*window)
예제 #3
0
파일: __init__.py 프로젝트: faroit/gr
    def draw(self, clear=False, update=True):
        if clear:
            gr.clearws()
        gr.setwsviewport(0, self.mwidth, 0, self.mheight)
        gr.setwswindow(0, self.sizex, 0, self.sizey)

        for plot in self._lstPlot:
            plot.sizex, plot.sizey = self.sizex, self.sizey
            plot.drawGR()
            # logDomainCheck
            logXinDomain = plot.logXinDomain()
            logYinDomain = plot.logYinDomain()
            if logXinDomain != self._logXinDomain:
                self._logXinDomain = logXinDomain
                self.logXinDomain.emit(self._logXinDomain)
            if logYinDomain != self._logYinDomain:
                self._logYinDomain = logYinDomain
                self.logYinDomain.emit(self._logYinDomain)

        if self._pickEvent:
            event = self._pickEvent
            gr.setviewport(*event.viewport)
            wcPoint = event.getWC(event.viewport)
            window = gr.inqwindow()
            gr.setwindow(*event.getWindow())
            gr.setmarkertype(gr.MARKERTYPE_PLUS)
            gr.polymarker([wcPoint.x], [wcPoint.y])
            gr.setwindow(*window)
예제 #4
0
    def draw(self, clear=False, update=True):
        if clear:
            gr.clearws()
        gr.setwsviewport(0, self.mwidth, 0, self.mheight)
        gr.setwswindow(0, self.sizex, 0, self.sizey)

        for plot in self._lstPlot:
            plot.sizex, plot.sizey = self.sizex, self.sizey
            plot.drawGR()
            # logDomainCheck
            logXinDomain = plot.logXinDomain()
            logYinDomain = plot.logYinDomain()
            if logXinDomain != self._logXinDomain:
                self._logXinDomain = logXinDomain
                self.logXinDomain.emit(self._logXinDomain)
            if logYinDomain != self._logYinDomain:
                self._logYinDomain = logYinDomain
                self.logYinDomain.emit(self._logYinDomain)

        if self._pickEvent:
            event = self._pickEvent
            wcPoint = event.getWC(event.viewport)
            window = gr.inqwindow()
            gr.setwindow(*event.getWindow())
            gr.setmarkertype(gr.MARKERTYPE_PLUS)
            gr.polymarker([wcPoint.x], [wcPoint.y])
            gr.setwindow(*window)
예제 #5
0
 def getHTML(self):
     if not self.enabled:
         return ''
     if not self.data or not self.curves:
         return '<span>No data or curves found</span>'
     with self.lock:
         for i, (d, c) in enumerate(zip(self.data, self.curves)):
             try:
                 # add a point "current value" at "right now" to avoid curves
                 # not updating if the value doesn't change
                 now = currenttime()
                 if d[0][-1] < now - 10:
                     self.updatevalues(i, now, d[1][-1])
                 c.x, c.y = self.maybeDownsamplePlotdata(d)
             except IndexError:
                 # no data (yet)
                 pass
     c = self.axes.getCurves()
     self.axes.setWindow(c.xmin, c.xmax, c.ymin, c.ymax)
     if os.path.isfile(self.tempfile):
         os.unlink(self.tempfile)
     gr.beginprint(self.tempfile)
     gr.setwsviewport(0, self.width * 0.0022, 0, self.height * 0.0022)
     try:
         self.plot.drawGR()
     except Exception as err:
         return html.escape('Error generating plot: %s' % err)
     finally:
         gr.endprint()
         gr.clearws()
     with open(self.tempfile, 'rb') as fp:
         imgbytes = fp.read()
     return ('<img src="data:image/svg+xml;base64,%s" '
             'style="width: %sex; height: %sex">' %
             (b64encode(imgbytes).decode(), self.width, self.height))
예제 #6
0
파일: mlab.py 프로젝트: j-fu/gr
def _set_viewport(kind, subplot):
    global _plt
    metric_width, metric_height, pixel_width, pixel_height = gr.inqdspsize()
    if 'figsize' in _plt.kwargs:
        horizontal_pixels_per_inch = pixel_width * 0.0254 / metric_width
        vertical_pixels_per_inch = pixel_height * 0.0254 / metric_height
        width = _plt.kwargs['figsize'][0] * horizontal_pixels_per_inch
        height = _plt.kwargs['figsize'][1] * vertical_pixels_per_inch
    else:
        width, height = _plt.kwargs['size']

    viewport = [0, 0, 0, 0]
    vp = subplot[:]
    if width > height:
        aspect_ratio = height/width
        metric_size = metric_width * width / pixel_width
        gr.setwsviewport(0, metric_size, 0, metric_size*aspect_ratio)
        gr.setwswindow(0, 1, 0, aspect_ratio)
        vp[2] *= aspect_ratio
        vp[3] *= aspect_ratio
    else:
        aspect_ratio = width/ height
        metric_size = metric_height * height / pixel_height
        gr.setwsviewport(0, metric_size * aspect_ratio, 0, metric_size)
        gr.setwswindow(0, aspect_ratio, 0, 1)
        vp[0] *= aspect_ratio
        vp[1] *= aspect_ratio
    viewport[0] = vp[0] + 0.125 * (vp[1]-vp[0])
    viewport[1] = vp[0] + 0.925 * (vp[1]-vp[0])
    viewport[2] = vp[2] + 0.125 * (vp[3]-vp[2])
    viewport[3] = vp[2] + 0.925 * (vp[3]-vp[2])

    if width > height:
        viewport[2] += (1 - (subplot[3] - subplot[2])**2) * 0.02
    if kind in ('wireframe', 'surface', 'plot3', 'scatter3'):
        viewport[1] -= 0.0525
    if kind in ('contour', 'contourf', 'surface'):
        viewport[1] -= 0.1
    gr.setviewport(*viewport)
    _plt.kwargs['viewport'] = viewport
    _plt.kwargs['vp'] = vp
    _plt.kwargs['ratio'] = aspect_ratio

    if 'backgroundcolor' in _plt.kwargs:
        gr.savestate()
        gr.selntran(0)
        gr.setfillintstyle(gr.INTSTYLE_SOLID)
        gr.setfillcolorind(_plt.kwargs['backgroundcolor'])
        if width > height:
            gr.fillrect(subplot[0], subplot[1],
                        subplot[2] * aspect_ratio, subplot[3] * aspect_ratio)
        else:
            gr.fillrect(subplot[0] * aspect_ratio, subplot[1] * aspect_ratio,
                        subplot[2], subplot[3])
        gr.selntran(1)
        gr.restorestate()
예제 #7
0
 def __init__(self, dpi):
     self.dpi = dpi
     self.width = 640.0 * dpi / 80
     self.height = 480.0 * dpi / 80
     mwidth, mheight, width, height = gr.inqdspsize()
     if (width / (mwidth / 0.0256) < 200):
         mwidth *= self.width / width
         gr.setwsviewport(0, mwidth, 0, mwidth * 0.75)
     else:
         gr.setwsviewport(0, 0.192, 0, 0.144)
     gr.setwswindow(0, 1, 0, 0.75)
     gr.setviewport(0, 1, 0, 0.75)
     gr.setwindow(0, self.width, 0, self.height)
     self.mathtext_parser = MathTextParser('agg')
     self.texmanager = TexManager()
예제 #8
0
파일: backend_gr.py 프로젝트: Juanlu001/gr
 def configure(self):
     aspect_ratio = self.width / self.height
     if aspect_ratio > 1:
         rect = np.array([0, 1, 0, 1.0 / aspect_ratio])
         self.size = self.width
     else:
         rect = np.array([0, aspect_ratio, 0, 1])
         self.size = self.height
     mwidth, mheight, width, height = gr.inqdspsize()
     if width / (mwidth / 0.0256) < 200:
         mwidth *= self.width / width
         gr.setwsviewport(*rect * mwidth)
     else:
         gr.setwsviewport(*rect * 0.192)
     gr.setwswindow(*rect)
     gr.setviewport(*rect)
     gr.setwindow(0, self.width, 0, self.height)
예제 #9
0
 def configure(self):
     aspect_ratio = self.width / self.height
     if aspect_ratio > 1:
         rect = np.array([0, 1, 0, 1.0 / aspect_ratio])
         self.size = self.width
     else:
         rect = np.array([0, aspect_ratio, 0, 1])
         self.size = self.height
     mwidth, mheight, width, height = gr.inqdspsize()
     if width / (mwidth / 0.0256) < 200:
         mwidth *= self.width / width
         gr.setwsviewport(*rect * mwidth)
     else:
         gr.setwsviewport(*rect * 0.192)
     gr.setwswindow(*rect)
     gr.setviewport(*rect)
     gr.setwindow(0, self.width, 0, self.height)
예제 #10
0
    def draw(self, wsviewport=None):
        if self.xvalues is not None and self.widths is not None:
            maxidx = np.argmax(self.xvalues)
            rangex = (self.xvalues.min(),
                      self.xvalues[maxidx] + self.widths[maxidx])
        else:
            rangex = (0.0, 100.0)
        if self.yvalues is not None:
            rangey = gr.adjustrange(0.0, self.yvalues.max())
        else:
            rangey = (0.0, 8.0)

        if wsviewport is None:
            gr.setwsviewport(0, self.mwidth, 0, self.mheight)
        else:
            gr.setwsviewport(*wsviewport)
        gr.setwswindow(0, self.sizex, 0, self.sizey)
        gr.setviewport(0.075 * self.sizex, 0.95 * self.sizex,
                       0.075 * self.sizey, 0.95 * self.sizey)
        gr.setwindow(rangex[0], rangex[1], rangey[0], rangey[1])
        gr.setcharheight(0.012)

        gr.setfillintstyle(1)
        gr.setfillcolorind(0)
        gr.fillrect(rangex[0], rangex[1], rangey[0], rangey[1])

        if self.xvalues is not None and self.yvalues is not None \
                and self.widths is not None:
            gr.setfillintstyle(1)
            gr.setfillcolorind(2)
            for i in range(self.xvalues.size):
                gr.fillrect(self.xvalues[i],
                            self.xvalues[i] + self.widths[i] * 0.8,
                            0.0, self.yvalues[i])
        else:
            gr.text(0.45 * self.sizex, 0.5 * self.sizey, "no data")

        gr.setlinecolorind(1)
        xtick = floor(0.02 * (rangex[1] - rangey[0]) * 100.0) / 100.0
        ytick = floor(0.04 * (rangey[1] - rangey[0]) * 50.0) / 50.0
        gr.axes(xtick, ytick, rangex[0], rangey[0], 10, 5, 0.0075)
        gr.axes(xtick, ytick, rangex[1], rangey[1], -10, -5, -0.0075)

        if self.title is not None:
            gr.text(0.8 * self.sizex, 0.9 * self.sizey, self.title)
예제 #11
0
    def draw(self, wsviewport=None):
        if self.xvalues is not None and self.widths is not None:
            maxidx = np.argmax(self.xvalues)
            rangex = (self.xvalues.min(),
                      self.xvalues[maxidx] + self.widths[maxidx])
        else:
            rangex = (0.0, 100.0)
        if self.yvalues is not None:
            rangey = gr.adjustrange(0.0, self.yvalues.max())
        else:
            rangey = (0.0, 8.0)

        if wsviewport is None:
            gr.setwsviewport(0, self.mwidth, 0, self.mheight)
        else:
            gr.setwsviewport(*wsviewport)
        gr.setwswindow(0, self.sizex, 0, self.sizey)
        gr.setviewport(0.075 * self.sizex, 0.95 * self.sizex,
                       0.075 * self.sizey, 0.95 * self.sizey)
        gr.setwindow(rangex[0], rangex[1], rangey[0], rangey[1])
        gr.setcharheight(0.012)

        gr.setfillintstyle(1)
        gr.setfillcolorind(0)
        gr.fillrect(rangex[0], rangex[1], rangey[0], rangey[1])

        if self.xvalues is not None and self.yvalues is not None \
                and self.widths is not None:
            gr.setfillintstyle(1)
            gr.setfillcolorind(2)
            for i in range(self.xvalues.size):
                gr.fillrect(self.xvalues[i],
                            self.xvalues[i] + self.widths[i] * 0.8,
                            0.0, self.yvalues[i])
        else:
            gr.text(0.45 * self.sizex, 0.5 * self.sizey, "no data")

        gr.setlinecolorind(1)
        xtick = floor(0.02 * (rangex[1] - rangey[0]) * 100.0) / 100.0
        ytick = floor(0.04 * (rangey[1] - rangey[0]) * 50.0) / 50.0
        gr.axes(xtick, ytick, rangex[0], rangey[0], 10, 5, 0.0075)
        gr.axes(xtick, ytick, rangex[1], rangey[1], -10, -5, -0.0075)

        if self.title is not None:
            gr.text(0.8 * self.sizex, 0.9 * self.sizey, self.title)
예제 #12
0
    def write(self, image, device_pixel_ratio=1):
        height, width = image.shape[:2]
        gr.clearws()
        if width > height:
            xmax = 1.0
            ymax = 1.0*height/width
        else:
            xmax = 1.0*width/height
            ymax = 1.0

        metric_width, metric_height, pixel_width, pixel_height = gr.inqdspsize()
        meter_per_horizontal_pixel = metric_width/pixel_width
        meter_per_vertical_pixel = metric_height/pixel_height
        gr.setwsviewport(0, meter_per_horizontal_pixel*width*device_pixel_ratio, 0,
                         meter_per_vertical_pixel*height*device_pixel_ratio)
        gr.setwswindow(0, xmax, 0, ymax)
        gr.setviewport(0, xmax, 0, ymax)
        gr.setwindow(0, xmax, 0, ymax)
        gr.drawimage(0, xmax, 0, ymax, width*device_pixel_ratio, height*device_pixel_ratio, image.view('uint32'))
        gr.updatews()
예제 #13
0
    def draw(self, wsviewport=None):
        if self.xvalues is not None:
            rangex = (self.xvalues.min(), self.xvalues.max())
        else:
            rangex = (0, 10)
        if self.yvalues is not None:
            rangey = gr.adjustrange(self.yvalues.min(), self.yvalues.max())
        else:
            rangey = (0, 4)

        if wsviewport is None:
            gr.setwsviewport(0, self.mwidth, 0, self.mheight)
        else:
            gr.setwsviewport(*wsviewport)
        gr.setwswindow(0, self.sizex, 0, self.sizey)
        gr.setviewport(0.075 * self.sizex, 0.95 * self.sizex,
                       0.075 * self.sizey, 0.95 * self.sizey)
        gr.setwindow(rangex[0], rangex[1], rangey[0], rangey[1])
        gr.setcharheight(0.012)

        gr.setfillintstyle(1)
        gr.setfillcolorind(0)
        gr.fillrect(rangex[0], rangex[1], rangey[0], rangey[1])

        if self.xvalues is not None and self.yvalues is not None:
            gr.setlinecolorind(2)
            gr.polyline(self.xvalues, self.yvalues)
        else:
            gr.text(0.4 * self.sizex, 0.5 * self.sizey, "no elements selected")

        gr.setlinecolorind(1)
        gr.axes(0.2, 0.2, rangex[0], rangey[0], 5, 5, 0.0075)
        gr.axes(0.2, 0.2, rangex[1], rangey[1], -5, -5, -0.0075)

        if self.title is not None:
            gr.text(0.8 * self.sizex, 0.9 * self.sizey, self.title)
예제 #14
0
    def draw(self, wsviewport=None):
        if self.xvalues is not None:
            rangex = (self.xvalues.min(), self.xvalues.max())
        else:
            rangex = (0, 10)
        if self.yvalues is not None:
            rangey = gr.adjustrange(self.yvalues.min(), self.yvalues.max())
        else:
            rangey = (0, 4)

        if wsviewport is None:
            gr.setwsviewport(0, self.mwidth, 0, self.mheight)
        else:
            gr.setwsviewport(*wsviewport)
        gr.setwswindow(0, self.sizex, 0, self.sizey)
        gr.setviewport(0.075 * self.sizex, 0.95 * self.sizex,
                       0.075 * self.sizey, 0.95 * self.sizey)
        gr.setwindow(rangex[0], rangex[1], rangey[0], rangey[1])
        gr.setcharheight(0.012)

        gr.setfillintstyle(1)
        gr.setfillcolorind(0)
        gr.fillrect(rangex[0], rangex[1], rangey[0], rangey[1])

        if self.xvalues is not None and self.yvalues is not None:
            gr.setlinecolorind(2)
            gr.polyline(self.xvalues, self.yvalues)
        else:
            gr.text(0.4 * self.sizex, 0.5 * self.sizey, "no elements selected")

        gr.setlinecolorind(1)
        gr.axes(0.2, 0.2, rangex[0], rangey[0], 5, 5, 0.0075)
        gr.axes(0.2, 0.2, rangex[1], rangey[1], -5, -5, -0.0075)

        if self.title is not None:
            gr.text(0.8 * self.sizex, 0.9 * self.sizey, self.title)
예제 #15
0
    def write(self, image, device_pixel_ratio=1):
        height, width = image.shape[:2]
        gr.clearws()
        if width > height:
            xmax = 1.0
            ymax = 1.0 * height / width
        else:
            xmax = 1.0 * width / height
            ymax = 1.0

        metric_width, metric_height, pixel_width, pixel_height = gr.inqdspsize()
        meter_per_horizontal_pixel = metric_width / pixel_width
        meter_per_vertical_pixel = metric_height / pixel_height
        gr.setwsviewport(
            0,
            meter_per_horizontal_pixel * width * device_pixel_ratio,
            0,
            meter_per_vertical_pixel * height * device_pixel_ratio,
        )
        gr.setwswindow(0, xmax, 0, ymax)
        gr.setviewport(0, xmax, 0, ymax)
        gr.setwindow(0, xmax, 0, ymax)
        gr.drawimage(0, xmax, 0, ymax, width * device_pixel_ratio, height * device_pixel_ratio, image.view("uint32"))
        gr.updatews()
예제 #16
0
from __future__ import print_function
from __future__ import unicode_literals

import sys
import os
import numpy as np
import gr

sys.path.insert(0, os.path.abspath('../src'))
from statistics.rdf import Kernels

x = np.linspace(-1.25, 1.25, 500)
for name in dir(Kernels):
    if name.startswith('_') or name == 'bandwidth':
        continue
    kernel = getattr(Kernels, name)
    y = kernel(x)
    gr.beginprint(name.lower()+'.svg')
    gr.clearws()
    gr.setwsviewport(0, 0.1, 0, 0.06)
    gr.setviewport(0, 1, 0, 1)
    gr.setwindow(-1.25, 1.25, -0.25, 1.25)
    gr.grid(0.1, 0.1, 0, 0, 5, 5)
    gr.axes(0.1, 0.1, 0, 0, 5, 5, -0.01)
    gr.setlinewidth(2)
    gr.setlinecolorind(2)
    gr.polyline(x, y)
    gr.setlinecolorind(1)
    gr.setlinewidth(1)
    gr.updatews()
    gr.endprint()
예제 #17
0
def init_plot_window(xmin, xmax, ymin, ymax):
    gr.clearws()
    gr.setwsviewport(0.0, 0.25, 0.0, 0.25)  # Desktop window extents in meters
    gr.setviewport(0.15, 0.95, 0.15, 0.95)
    gr.setwindow(xmin, xmax, ymin, ymax)
예제 #18
0
def _set_viewport(kind, subplot):
    global _plt
    metric_width, metric_height, pixel_width, pixel_height = gr.inqdspsize()
    if 'figsize' in _plt.kwargs:
        horizontal_pixels_per_inch = pixel_width * 0.0254 / metric_width
        vertical_pixels_per_inch = pixel_height * 0.0254 / metric_height
        width = _plt.kwargs['figsize'][0] * horizontal_pixels_per_inch
        height = _plt.kwargs['figsize'][1] * vertical_pixels_per_inch
    else:
        dpi = pixel_width / metric_width * 0.0254
        if dpi > 200:
            width, height = tuple(x * dpi / 100 for x in _plt.kwargs['size'])
        else:
            width, height = _plt.kwargs['size']

    viewport = [0, 0, 0, 0]
    vp = subplot[:]
    if width > height:
        aspect_ratio = height/width
        metric_size = metric_width * width / pixel_width
        gr.setwsviewport(0, metric_size, 0, metric_size*aspect_ratio)
        gr.setwswindow(0, 1, 0, aspect_ratio)
        vp[2] *= aspect_ratio
        vp[3] *= aspect_ratio
    else:
        aspect_ratio = width/ height
        metric_size = metric_height * height / pixel_height
        gr.setwsviewport(0, metric_size * aspect_ratio, 0, metric_size)
        gr.setwswindow(0, aspect_ratio, 0, 1)
        vp[0] *= aspect_ratio
        vp[1] *= aspect_ratio
    viewport[0] = vp[0] + 0.125 * (vp[1]-vp[0])
    viewport[1] = vp[0] + 0.925 * (vp[1]-vp[0])
    viewport[2] = vp[2] + 0.125 * (vp[3]-vp[2])
    viewport[3] = vp[2] + 0.925 * (vp[3]-vp[2])

    if width > height:
        viewport[2] += (1 - (subplot[3] - subplot[2])**2) * 0.02
    if kind in ('wireframe', 'surface', 'plot3', 'scatter3', 'trisurf'):
        viewport[1] -= 0.0525
    if kind in ('contour', 'contourf', 'surface', 'trisurf', 'heatmap', 'hexbin'):
        viewport[1] -= 0.1
    gr.setviewport(*viewport)
    _plt.kwargs['viewport'] = viewport
    _plt.kwargs['vp'] = vp
    _plt.kwargs['ratio'] = aspect_ratio

    if 'backgroundcolor' in _plt.kwargs:
        gr.savestate()
        gr.selntran(0)
        gr.setfillintstyle(gr.INTSTYLE_SOLID)
        gr.setfillcolorind(_plt.kwargs['backgroundcolor'])
        if width > height:
            gr.fillrect(subplot[0], subplot[1],
                        subplot[2] * aspect_ratio, subplot[3] * aspect_ratio)
        else:
            gr.fillrect(subplot[0] * aspect_ratio, subplot[1] * aspect_ratio,
                        subplot[2], subplot[3])
        gr.selntran(1)
        gr.restorestate()

    if kind == 'polar':
        x_min, x_max, y_min, y_max = viewport
        x_center = 0.5 * (x_min + x_max)
        y_center = 0.5 * (y_min + y_max)
        r = 0.5 * min(x_max - x_min, y_max - y_min)
        gr.setviewport(x_center - r, x_center + r, y_center - r, y_center + r)