Example #1
0
 def testGGStatementsToR(self):
     """Test that GGStatement converts to R properly"""
     self.check_me(pygg.geom_point(), "geom_point()")
     self.check_me(pygg.geom_bar(), "geom_bar()")
     self.check_me(pygg.geom_point() + pygg.geom_bar(),
                   "geom_point()+geom_bar()")
     self.check_me(pygg.geom_bar() + pygg.geom_point(),
                   "geom_bar()+geom_point()")
Example #2
0
 def testGGStatementsToR(self):
     """Test that GGStatement converts to R properly"""
     self.check_me(pygg.geom_point(), "geom_point()")
     self.check_me(pygg.geom_bar(), "geom_bar()")
     self.check_me(pygg.geom_point() + pygg.geom_bar(),
                   "geom_point()+geom_bar()")
     self.check_me(pygg.geom_bar() + pygg.geom_point(),
                   "geom_bar()+geom_point()")
Example #3
0
 def testLibs(self):
     p = pygg.ggplot('diamonds', pygg.aes(x='carat', y='price'))
     p += pygg.geom_point()
     tmpfile = tempfile.NamedTemporaryFile(suffix='.pdf').name
     pygg.ggsave(tmpfile, p, data=None, libs=['grid'], quiet=True)
     self.assertTrue(os.path.exists(tmpfile))
     self.assertTrue(os.path.getsize(tmpfile) > 0)
Example #4
0
 def testLibs(self):
     p = pygg.ggplot('diamonds', pygg.aes(x='carat', y='price'))
     p += pygg.geom_point()
     tmpfile = tempfile.NamedTemporaryFile(suffix='.pdf').name
     pygg.ggsave(tmpfile, p, data=None, libs=['grid'], quiet=True)
     self.assertTrue(os.path.exists(tmpfile))
     self.assertTrue(os.path.getsize(tmpfile) > 0)
Example #5
0
 def testBasicDataggplot(self):
     data = [dict(x=x, y=y) for x, y in zip(range(10), range(10))]
     p = pygg.ggplot(data, pygg.aes(x='x', y='y'))
     p += pygg.geom_point()
     p += pygg.geom_smooth()
     p += pygg.ggtitle(pygg.esc('Test title'))
     self.check_ggsave(p)
Example #6
0
 def testBasicDataggplot(self):
     data = [dict(x=x, y=y) for x, y in zip(range(10), range(10))]
     p = pygg.ggplot(data, pygg.aes(x='x', y='y'))
     p += pygg.geom_point()
     p += pygg.geom_smooth()
     p += pygg.ggtitle(pygg.esc('Test title'))
     self.check_ggsave(p)
Example #7
0
 def testPandasDFggplot(self):
     data = pandas.read_csv(StringIO.StringIO(IRIS_DATA_CSV))
     self.assertIsInstance(data, pandas.DataFrame)
     p = pygg.ggplot(
         data, pygg.aes(x='SepalLength', y='PetalLength', color='Name'))
     p += pygg.geom_point()
     p += pygg.geom_smooth()
     p += pygg.ggtitle(pygg.esc('Test title'))
     self.check_ggsave(p)
Example #8
0
 def testPandasDF(self):
     data = pandas.read_csv(StringIO.StringIO(IRIS_DATA_CSV))
     self.assertIsInstance(data, pandas.DataFrame)
     p = pygg.ggplot('data',
                     pygg.aes(x='SepalLength', y='PetalLength', color='Name'))
     p += pygg.geom_point()
     p += pygg.geom_smooth()
     p += pygg.ggtitle(pygg.esc('Test title'))
     self.check_ggsave(p, data)
Example #9
0
    def testE2E(self):
        """Test end-to-end creation of figures with outputs to pdf and png"""
        p = pygg.ggplot('diamonds', pygg.aes(x='carat', y='price', color='clarity'))
        p += pygg.geom_point(alpha=0.5, size = .75)
        p += pygg.scale_x_log10()
        p += pygg.theme_bw()

        self.check_ggsave(p, None, ext=".pdf")
        self.check_ggsave(p, None, ext=".png")
        self.check_ggsave(p, None, ext=".jpg")
Example #10
0
    def testE2E(self):
        """Test end-to-end creation of figures with outputs to pdf and png"""
        p = pygg.ggplot('diamonds',
                        pygg.aes(x='carat', y='price', color='clarity'))
        p += pygg.geom_point(alpha=0.5, size=.75)
        p += pygg.scale_x_log10()
        p += pygg.theme_bw()

        self.check_ggsave(p, None, ext=".pdf")
        self.check_ggsave(p, None, ext=".png")
        self.check_ggsave(p, None, ext=".jpg")
Example #11
0
 def testPython2RStringEsc(self):
     """Test GGStatement escapes strings properly"""
     self.check_me(pygg.geom_point(a="b"), 'geom_point(a=b)')
     self.check_me(pygg.geom_point(a='b'), 'geom_point(a=b)')
     self.check_me(pygg.geom_point(a="'b'"), 'geom_point(a=\'b\')')
     self.check_me(pygg.geom_point(a='"b"'), 'geom_point(a="b")')
     self.check_me(pygg.geom_point(a={'k': pygg.esc("v")}),
                                   'geom_point(a=list(k="v"))')
     self.check_me(pygg.geom_point(a=[pygg.esc("a"), pygg.esc("b")]),
                                   'geom_point(a=c("a","b"))')
Example #12
0
 def testPython2RStringEsc(self):
     """Test GGStatement escapes strings properly"""
     self.check_me(pygg.geom_point(a="b"), 'geom_point(a=b)')
     self.check_me(pygg.geom_point(a='b'), 'geom_point(a=b)')
     self.check_me(pygg.geom_point(a="'b'"), 'geom_point(a=\'b\')')
     self.check_me(pygg.geom_point(a='"b"'), 'geom_point(a="b")')
     self.check_me(pygg.geom_point(a={'k': pygg.esc("v")}),
                   'geom_point(a=list(k="v"))')
     self.check_me(
         pygg.geom_point(a=[pygg.esc("a"), pygg.esc("b")]),
         'geom_point(a=c("a","b"))')
Example #13
0
    def testIPython(self):
        """Test that gg_ipython returns a IPython formatted Image"""
        p = pygg.ggplot('diamonds', pygg.aes(x='carat', y='price'))
        p += pygg.geom_point()
        img = pygg.gg_ipython(p, data=None)
        self.assertIsNotNone(img.data)
        self.assertEqual(img.format, "jpeg")
        self.assertEqual(img.width, pygg.IPYTHON_IMAGE_SIZE)
        self.assertEqual(img.height, pygg.IPYTHON_IMAGE_SIZE)

        img = pygg.gg_ipython(p, data=None, width=600, height=400)
        self.assertEqual(img.width, 600)
        self.assertEqual(img.height, 400)

        img = pygg.gg_ipython(p, data=None, width=600)
        self.assertEqual(img.width, 600)
        self.assertEqual(img.height, 600)
Example #14
0
    def testIPython(self):
        """Test that gg_ipython returns a IPython formatted Image"""
        p = pygg.ggplot('diamonds', pygg.aes(x='carat', y='price'))
        p += pygg.geom_point()
        img = pygg.gg_ipython(p, data=None)
        self.assertIsNotNone(img.data)
        self.assertEqual(img.format, "jpeg")
        self.assertEqual(img.width, pygg.IPYTHON_IMAGE_SIZE)
        self.assertEqual(img.height, pygg.IPYTHON_IMAGE_SIZE)

        img = pygg.gg_ipython(p, data=None, width=600, height=400)
        self.assertEqual(img.width, 600)
        self.assertEqual(img.height, 400)

        img = pygg.gg_ipython(p, data=None, width=600)
        self.assertEqual(img.width, 600)
        self.assertEqual(img.height, 600)
Example #15
0
 def testGGStatementToR(self):
     """Test that GGStatement converts to R properly"""
     self.check_me(pygg.geom_point(), "geom_point()")
     self.check_me(pygg.geom_point(size=1.0), "geom_point(size=1.0)")
     self.check_me(pygg.geom_point(size=1.0, alpha=2.0),
                   "geom_point(alpha=2.0,size=1.0)")
Example #16
0
 def testFacets2(self):
     p = pygg.ggplot('diamonds', pygg.aes(x='carat', y='price'))
     p += pygg.geom_point()
     p += pygg.facet_wrap("~clarity")
     self.check_ggsave(p, None)
Example #17
0
 def testBadGGPlotFails(self):
     p = pygg.ggplot('diamonds', pygg.aes(x='MISSING')) + pygg.geom_point()
     with self.assertRaises(ValueError):
         tmpfile = tempfile.NamedTemporaryFile(suffix=".png").name
         pygg.ggsave(tmpfile, p, data=None, quiet=True)
Example #18
0
 def testPython2RTypes(self):
     """Test GGStatement converts many python types properly"""
     self.check_me(pygg.geom_point(a=1), "geom_point(a=1)")
     self.check_me(pygg.geom_point(a=None), "geom_point(a=NA)")
     self.check_me(pygg.geom_point(a=1.0), "geom_point(a=1.0)")
     self.check_me(pygg.geom_point(a=1e-2), "geom_point(a=0.01)")
     self.check_me(pygg.geom_point(a="foo"), 'geom_point(a=foo)')
     self.check_me(pygg.geom_point(a=pygg.esc("foo")),
                   'geom_point(a="foo")')
     self.check_me(pygg.geom_point(a=True), 'geom_point(a=TRUE)')
     self.check_me(pygg.geom_point(a=False), 'geom_point(a=FALSE)')
     self.check_me(pygg.geom_point(a=[1, 2]), 'geom_point(a=c(1,2))')
     self.check_me(pygg.geom_point(a={
         'list1': 1,
         'list2': 2
     }), 'geom_point(a=list(list1=1,list2=2))')
     self.check_me(
         pygg.geom_point(1,
                         a=2.0,
                         b=[3, 4],
                         c={
                             'list1': pygg.esc('s1'),
                             'list2': 2
                         }),
         'geom_point(1,a=2.0,b=c(3,4),c=list(list1="s1",list2=2))')
Example #19
0
 def testLimits(self):
     p = pygg.ggplot('diamonds', pygg.aes(x='carat', y='price', color='clarity'))
     p += pygg.geom_point(alpha=0.5, size = .75)
     p += pygg.scale_x_log10(limits=[1, 2])
     self.check_ggsave(p, None)
Example #20
0
 def testFacets2(self):
     p = pygg.ggplot('diamonds', pygg.aes(x='carat', y='price'))
     p += pygg.geom_point()
     p += pygg.facet_wrap("~clarity")
     self.check_ggsave(p, None)
Example #21
0
 def testLimits(self):
     p = pygg.ggplot('diamonds',
                     pygg.aes(x='carat', y='price', color='clarity'))
     p += pygg.geom_point(alpha=0.5, size=.75)
     p += pygg.scale_x_log10(limits=[1, 2])
     self.check_ggsave(p, None)
Example #22
0
 def testPython2RTypes(self):
     """Test GGStatement converts many python types properly"""
     self.check_me(pygg.geom_point(a=1), "geom_point(a=1)")
     self.check_me(pygg.geom_point(a=None), "geom_point(a=NA)")
     self.check_me(pygg.geom_point(a=1.0), "geom_point(a=1.0)")
     self.check_me(pygg.geom_point(a=1e-2), "geom_point(a=0.01)")
     self.check_me(pygg.geom_point(a="foo"), 'geom_point(a=foo)')
     self.check_me(pygg.geom_point(a=pygg.esc("foo")), 'geom_point(a="foo")')
     self.check_me(pygg.geom_point(a=True), 'geom_point(a=TRUE)')
     self.check_me(pygg.geom_point(a=False), 'geom_point(a=FALSE)')
     self.check_me(pygg.geom_point(a=[1, 2]), 'geom_point(a=c(1,2))')
     self.check_me(pygg.geom_point(a={'list1': 1, 'list2': 2}),
                   'geom_point(a=list(list1=1,list2=2))')
     self.check_me(pygg.geom_point(1, a=2.0, b=[3, 4],
                                   c={'list1': pygg.esc('s1'), 'list2': 2}),
                   'geom_point(1,a=2.0,b=c(3,4),c=list(list1="s1",list2=2))')
Example #23
0
 def testNativeRDataset(self):
     p = pygg.ggplot('diamonds', pygg.aes(x='carat',
                                          y='carat')) + pygg.geom_point()
     self.check_ggsave(p, None)
Example #24
0
 def testGGStatementToR(self):
     """Test that GGStatement converts to R properly"""
     self.check_me(pygg.geom_point(), "geom_point()")
     self.check_me(pygg.geom_point(size=1.0), "geom_point(size=1.0)")
     self.check_me(pygg.geom_point(size=1.0, alpha=2.0),
                   "geom_point(alpha=2.0,size=1.0)")
Example #25
0
 def testNativeRDataset(self):
     p = pygg.ggplot('diamonds', pygg.aes(x='carat', y='carat')) + pygg.geom_point()
     self.check_ggsave(p, None)
Example #26
0
 def testBadGGPlotFails(self):
     p = pygg.ggplot('diamonds', pygg.aes(x='MISSING')) + pygg.geom_point()
     with self.assertRaises(ValueError):
         tmpfile = tempfile.NamedTemporaryFile(suffix=".png").name
         pygg.ggsave(tmpfile, p, data=None, quiet=True)