Example #1
0
    def setWindow(self, xmin, xmax, ymin, ymax):
        res = PlotAxes.setWindow(self, xmin, xmax, ymin, ymax)

        # use 2 ** n for tickmarks

        def tick(amin, amax):
            if amin > amax:
                amax, amin = amin, amax
            # calculate next (lower) power of two (2**n) for the
            # full range [amax - amin] and divide this:
            #
            #           ld(amax - amin)  :  number of powers of two => exponent
            #       int(        "      ) :  integral part
            #                               (cut off fractions => floor)
            # 2 ** (  "         "       ):  next lower power of two (2**n)
            # 2 ** (   int( ... ) - 4)  ):  - 4 => divided by 2 ** 4
            return 2**(int(math.log(max(amax - amin, 0.1), 2)) - 4)

        if self.xdual:
            self.xtick = tick(xmin, xmax)
            self.majorx = 4
        if self.ydual:
            self.ytick = tick(ymin, ymax)
            self.majory = 4
        return res
Example #2
0
 def setWindow(self, xmin, xmax, ymin, ymax):
     if xmin < 1:
         xmin = 1
     if ymin < 1:
         ymin = 1
     return PlotAxes.setWindow(self, xmin, xmax, ymin, ymax)
Example #3
0
 def setWindow(self, xmin, xmax, ymin, ymax):
     if ymin < 0:
         ymin = 0
     PlotAxes.setWindow(self, xmin, xmax, ymin, ymax)
Example #4
0
 def setWindow(self, xmin, xmax, ymin, ymax):
     if xmin < 1:
         xmin = 1
     if ymin < 1:
         ymin = 1
     return PlotAxes.setWindow(self, xmin, xmax, ymin, ymax)
Example #5
0
from gr.pygr import Plot, PlotAxes, PlotCurve, Text

tx, ty = 0, -20
x = [-3.3 + t * .1 for t in range(66)]
y = [t**5 - 13 * t**3 + 36 * t for t in x]
txtfmt = "Text drawn on\n(%g, %g) with\nhalign left, valign top"

plt = Plot((.1, .95, .1, .88))
plt.title = "Text on Axes Example"
plt.subTitle = "Show usage of gr.pygr.Text"
plt.xlabel = "x"
plt.ylabel = "y"

curve = PlotCurve(x, y, legend="foo bar")
axes = PlotAxes(plt.viewport).addCurves(curve)
axes.setWindow(-4.0, 4.0, -60.0, 40.0)
text = Text(tx, -ty, txtfmt % (tx, -ty), axes, .02)
plt.addAxes(axes)
text2 = Text(tx, ty, txtfmt % (tx, ty), axes, .02)
tbx, tby = text2.getBoundingBox()

plt.drawGR()
text.drawGR()
text2.drawGR()

# set viewport and window accordingly to draw in NDC space
gr.setviewport(0, axes.sizex, 0, axes.sizey)
gr.setwindow(0, axes.sizex, 0, axes.sizey)
gr.fillarea(tbx, tby)
gr.updatews()
Example #6
0
from gr.pygr import Plot, PlotAxes, PlotCurve, Text

if __name__ == "__main__":
    tx, ty = 0, -20
    x = [-3.3 + t * 0.1 for t in range(66)]
    y = [t ** 5 - 13 * t ** 3 + 36 * t for t in x]
    txtfmt = "Text drawn on\n(%g, %g) with\nhalign left, valign top"

    plt = Plot((0.1, 0.95, 0.1, 0.88))
    plt.title = "Text on Axes Example"
    plt.subTitle = "Show usage of gr.pygr.Text"
    plt.xlabel = "x"
    plt.ylabel = "y"

    curve = PlotCurve(x, y, legend="foo bar")
    axes = PlotAxes(plt.viewport).addCurves(curve)
    axes.setWindow(-4.0, 4.0, -60.0, 40.0)
    text = Text(tx, -ty, txtfmt % (tx, -ty), axes, 0.02)
    plt.addAxes(axes)
    text2 = Text(tx, ty, txtfmt % (tx, ty), axes, 0.02)
    tbx, tby = text2.getBoundingBox()

    plt.drawGR()
    text.drawGR()
    text2.drawGR()

    # set viewport and window accordingly to draw in NDC space
    gr.setviewport(0, axes.sizex, 0, axes.sizey)
    gr.setwindow(0, axes.sizex, 0, axes.sizey)
    gr.fillarea(tbx, tby)