Esempio n. 1
0
def makeImage(rates):
    out = tempfile.NamedTemporaryFile(suffix='.png')

    grdevices = importr('grDevices')
    grdevices.png(file=out.name, width=512, height=512)
    try:
        grid.newpage()
        lt = grid.layout(1, 1)
        vp = grid.viewport(layout=lt)
        vp.push()

        vp = grid.viewport(**{'layout.pos.col': 1, 'layout.pos.row': 1})

        for row, (year, count) in enumerate(sorted(rates['byYear'].items())):
            grid.rect(x=grid.unit(.5, "npc"),
                      y=grid.unit(row / len(rates['byYear']), "npc"),
                      width=grid.unit(count / 15000, "npc"),
                      height=grid.unit(.95 / len(rates['byYear']), "npc"),
                      vp=vp).draw()

    finally:
        grdevices.dev_off()
    return open(out.name).read()
Esempio n. 2
0
def makeImage(rates):
    out = tempfile.NamedTemporaryFile(suffix='.png')

    grdevices = importr('grDevices')
    grdevices.png(file=out.name, width=512, height=512)
    try:
        grid.newpage()
        lt = grid.layout(1, 1)
        vp = grid.viewport(layout = lt)
        vp.push()

        vp = grid.viewport(**{'layout.pos.col':1, 'layout.pos.row': 1})

        for row, (year, count) in enumerate(sorted(rates['byYear'].items())):
            grid.rect(x=grid.unit(.5, "npc"),
                      y=grid.unit(row / len(rates['byYear']), "npc"),
                      width=grid.unit(count / 15000, "npc"),
                      height=grid.unit(.95 / len(rates['byYear']), "npc"),
                      vp = vp).draw()
        
    finally:
        grdevices.dev_off()
    return open(out.name).read()
Esempio n. 3
0
    # fetch viewport at position col_i+1 on the second row
    vp = grid.viewport(**{'layout.pos.col': col_i + 1, 'layout.pos.row': 2})
    pp = gp + \
        ggplot2.aes_string(x='%s(carat)' % trans, y='%s(price)' % trans) + \
        ggplot2.geom_point(alpha = 0.1, size = 1) + \
        ggplot2.ggtitle("%s(<variable>)" % trans)
    pp.plot(vp=vp)

#-- ggplot2mtcarscoordtrans-end

#-- ggplot2mtcarscoordtransannot-begin
vp = grid.viewport(**{'layout.pos.col': 2, 'layout.pos.row': 1})
grid.rect(x=grid.unit(0.7, "npc"),
          y=grid.unit(0.2, "npc"),
          width=grid.unit(0.1, "npc"),
          height=grid.unit(0.1, "npc"),
          gp=grid.gpar(fill="red"),
          vp=vp).draw()
#-- ggplot2mtcarscoordtransannot-end

grdevices.dev_off()

grdevices.png('../../_static/graphics_grid.png',
              width=612,
              height=612,
              antialias="subpixel",
              type="cairo")
#-- grid-begin
grid.newpage()
# create a rows/columns layout
lt = grid.layout(2, 3)
Esempio n. 4
0
def test_rect():
    r = grid.rect(x=grid.unit(0, 'cm'))
Esempio n. 5
0

grdevices.png('../../_static/graphics_grid.png',
              width = 612, height = 612, antialias="subpixel", type="cairo")
#-- grid-begin
grid.newpage()
# create a rows/columns layout
lt = grid.layout(2, 3)
vp = grid.viewport(layout = lt)
# push it the plotting stack
vp.push()

# create a viewport located at (1,1) in the layout
vp = grid.viewport(**{'layout.pos.col':1, 'layout.pos.row': 1})
# create a (unit) rectangle in that viewport
grid.rect(vp = vp).draw()

vp = grid.viewport(**{'layout.pos.col':2, 'layout.pos.row': 2})
# create text in the viewport at (1,2)
grid.text("foo", vp = vp).draw()

vp = grid.viewport(**{'layout.pos.col':3, 'layout.pos.row': 1})
# create a (unit) circle in the viewport (1,3)
grid.circle(vp = vp).draw()

#-- grid-end
grdevices.dev_off()



grdevices.png('../../_static/graphics_ggplot2withgrid.png',
Esempio n. 6
0
   # fetch viewport at position col_i+1 on the second row
   vp = grid.viewport(**{'layout.pos.col':col_i+1, 'layout.pos.row': 2})
   pp = gp + \
       ggplot2.aes_string(x='%s(carat)' % trans, y='%s(price)' % trans) + \
       ggplot2.geom_point(alpha = 0.1, size = 1) + \
       ggplot2.ggtitle("%s(<variable>)" % trans)   
   pp.plot(vp = vp)

#-- ggplot2mtcarscoordtrans-end

#-- ggplot2mtcarscoordtransannot-begin
vp = grid.viewport(**{'layout.pos.col':2, 'layout.pos.row': 1})
grid.rect(x = grid.unit(0.7, "npc"),
          y = grid.unit(0.2, "npc"),
          width = grid.unit(0.1, "npc"),
          height = grid.unit(0.1, "npc"),
          gp = grid.gpar(fill = "red"),
          vp = vp).draw()
#-- ggplot2mtcarscoordtransannot-end

grdevices.dev_off()



grdevices.png('../../_static/graphics_grid.png',
              width = 612, height = 612, antialias="subpixel", type="cairo")
#-- grid-begin
grid.newpage()
# create a rows/columns layout
lt = grid.layout(2, 3)
vp = grid.viewport(layout = lt)