Example #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()
Example #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()
Example #3
0

@pytest.mark.parametrize('constructor,args,kwargs,res_cls', (
    (grid.unit, (1, 'cm'), {}, grid.Unit),
    (grid.unit, (), {
        'x': 1,
        'units': 'cm'
    }, grid.Unit),
    (grid.gpar, (), {
        'col': 'blue'
    }, grid.Gpar),
    (grid.grob, (), {
        'name': 'foo'
    }, grid.Grob),
    (grid.rect, (), {
        'x': grid.unit(0, 'cm')
    }, grid.Rect),
    (grid.lines, (), {
        'x': grid.unit(FloatVector([0, 1]), 'cm')
    }, grid.Lines),
    (grid.circle, (), {
        'x': 0
    }, grid.Circle),
    (grid.points, (), {}, grid.Points),
    (grid.text, ('t0', ), {}, grid.Text),
    (grid.GTree.gtree, (), {}, grid.GTree),
    (grid.GTree.grobtree, (), {}, grid.GTree),
    (grid.XAxis.xaxis, (), {}, grid.XAxis),
    (grid.YAxis.yaxis, (), {}, grid.YAxis),
    (grid.XAxis.xaxisgrob, (), {}, grid.XAxis),
    (grid.YAxis.yaxisgrob, (), {}, grid.YAxis),
Example #4
0
    # plot into the viewport
    pp.plot(vp=vp)

    # 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
Example #5
0
def test_lines():
    l = grid.lines(x=grid.unit(FloatVector([0, 1]), 'cm'))
Example #6
0
def test_rect():
    r = grid.rect(x=grid.unit(0, 'cm'))
Example #7
0
def test_unit():
    u = grid.unit(1, 'cm')
    u = grid.unit(x=1, units='cm')
Example #8
0
   # plot into the viewport
   pp.plot(vp = vp)

   # 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()
Example #9
0
        'axis.text':ggplot2.element_text(colour="black",size=15,family=FONTFAM),
        'axis.text.x': ggplot2.element_text(angle = 45, hjust=1, vjust=1,
                                            size=15,family=FONTFAM),
        'axis.title':ggplot2.element_text(face="bold",colour="black",
                                          size=15,family=FONTFAM),
        'plot.title':ggplot2.element_text(face="bold", size=20,
                                          colour="black",family=FONTFAM),
        'panel.grid.major':ggplot2.element_blank(),
        'panel.grid.minor':ggplot2.element_blank(),
        'legend.background':ggplot2.element_blank(),
        'legend.key':ggplot2.element_blank(),
        'legend.position':'top',
        'legend.title':ggplot2.element_text(face="bold",colour="black",
                                            size=15,family=FONTFAM),
        'legend.text':ggplot2.element_text(colour="black",size=15,family=FONTFAM),
        'plot.margin':grid.unit(robjects.IntVector([0,0,0,0]), "lines"),
        'axis.ticks':ggplot2.ggplot2.element_line(colour="black"),
        'strip.text.y':ggplot2.element_text(colour="black",face="bold",size=15,
                                            angle=-90,family=FONTFAM),
        'strip.text.x':ggplot2.element_text(colour="black",face="bold",
                                            size=15,family=FONTFAM),
        'text':ggplot2.element_text(colour="black",family=FONTFAM)
        }

sitefreqtheme = {
        'panel.background':ggplot2.element_rect(fill='white',colour='white'),
        'axis.text':ggplot2.element_text(colour="black",size=15,family=FONTFAM),
        'axis.text.x': ggplot2.element_text(angle = 45, hjust=1, vjust=1,
                                            size=15,family=FONTFAM),
        'axis.line':ggplot2.ggplot2.element_line(size = 1.2, colour="black"),
        'axis.title':ggplot2.element_text(face="bold",colour="black",