Beispiel #1
0
 def test_rplot3(self):
     path = os.path.join(curpath(), 'data/tips.csv')
     plt.figure()
     self.data = read_csv(path, sep=',')
     self.plot = rplot.RPlot(self.data, x='tip', y='total_bill')
     self.plot.add(rplot.TrellisGrid(['sex', '.']))
     self.plot.add(
         rplot.GeomPoint(colour=rplot.ScaleRandomColour('day'),
                         shape=rplot.ScaleShape('size')))
     self.fig = plt.gcf()
     self.plot.render(self.fig)
Beispiel #2
0
 def setUp(self):
     path = os.path.join(curpath(), 'data/tips.csv')
     self.data = read_csv(path, sep=',')
     layer1 = rplot.Layer(self.data)
     layer2 = rplot.GeomPoint(x='total_bill', y='tip')
     layer3 = rplot.GeomPolyFit(2)
     self.layers = rplot.sequence_layers([layer1, layer2, layer3])
     self.trellis1 = rplot.TrellisGrid(['sex', 'smoker'])
     self.trellis2 = rplot.TrellisGrid(['sex', '.'])
     self.trellis3 = rplot.TrellisGrid(['.', 'smoker'])
     self.trellised1 = self.trellis1.trellis(self.layers)
     self.trellised2 = self.trellis2.trellis(self.layers)
     self.trellised3 = self.trellis3.trellis(self.layers)
 def test_sequence_layers(self):
     layer1 = rplot.Layer(self.data)
     layer2 = rplot.GeomPoint(x='SepalLength', y='SepalWidth',
                              size=rplot.ScaleSize('PetalLength'))
     layer3 = rplot.GeomPolyFit(2)
     result = rplot.sequence_layers([layer1, layer2, layer3])
     self.assertEqual(len(result), 3)
     last = result[-1]
     self.assertEqual(last.aes['x'], 'SepalLength')
     self.assertEqual(last.aes['y'], 'SepalWidth')
     self.assertTrue(isinstance(last.aes['size'], rplot.ScaleSize))
     self.assertTrue(self.data is last.data)
     self.assertTrue(rplot.sequence_layers([layer1])[0] is layer1)
 def test_rplot_iris(self):
     import matplotlib.pyplot as plt
     path = os.path.join(curpath(), 'data/iris.csv')
     plt.figure()
     self.data = read_csv(path, sep=',')
     plot = rplot.RPlot(self.data, x='SepalLength', y='SepalWidth')
     plot.add(rplot.GeomPoint(
         colour=rplot.ScaleGradient('PetalLength',
                                    colour1=(0.0, 1.0, 0.5),
                                    colour2=(1.0, 0.0, 0.5)),
         size=rplot.ScaleSize('PetalWidth', min_size=10.0,
                              max_size=200.0),
         shape=rplot.ScaleShape('Name')))
     self.fig = plt.gcf()
     plot.render(self.fig)
Beispiel #5
0
# **A nonlinear classifier could separate the north from Sardinia!**

# We use the really ugly trellis rplot interface in Pandas to do some hierarchical digging. We plot oleic against linoleic. **We can split Sardinia. We might be able to split East Liguria out but there could be significant misclassification.**

# In[49]:

import pandas.tools.rplot as rplot
dfcopy = df.copy()
dfcopy['region'] = dfcopy['region'].map(rmap)
imap = {e[0]: e[1] for e in zip(df.area.unique(), df.areastring.unique())}
#dfcopy['area']=dfcopy['area'].map(imap)
plot = rplot.RPlot(dfcopy, x='linoleic', y='oleic')
plot.add(rplot.TrellisGrid(['region', '.']))
plot.add(
    rplot.GeomPoint(size=40.0,
                    alpha=0.3,
                    colour=rplot.ScaleRandomColour('area')))

fig = plot.render()
print df.areastring.unique()

# ### YOUR TURN NOW (10 minutes)

# Plot palmitoleic against palimitic. **What can you separate?** Use the `dfcopy` dataframe.

# In[52]:

#your code here
plot = rplot.RPlot(dfcopy, x='palmitic', y='palmitoleic')
plot.add(rplot.TrellisGrid(['region', '.']))
plot.add(