Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 16658
%auto import pandas as pd import numpy as np import matplotlib.pyplot as plt %default_mode python %typeset_mode True import matplotlib matplotlib.style.use('ggplot')
ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000)) ts = ts.cumsum() ts.plot()
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list('ABCD')) df = df.cumsum() df.plot()
df3 = pd.DataFrame(np.random.randn(1000, 2), columns=['B', 'C']).cumsum() df3['A'] = pd.Series(list(range(len(df)))) df3.plot(x='A', y='B')
df.ix[5].plot(kind='bar')
df2 = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd']) df2.plot.bar()
df2.plot.bar(stacked=True)
df2.plot.barh(stacked=True)
df4 = pd.DataFrame({'a': np.random.randn(1000) + 1, 'b': np.random.randn(1000), 'c': np.random.randn(1000) - 1}, columns=['a', 'b', 'c']) df4.plot.hist(alpha=0.5)
df4.plot.hist(stacked=True, bins=20)
df4['a'].plot.hist(orientation='horizontal', cumulative=True)
df['A'].diff().hist()
# Hmm... doesn't work yet in Sagew worksheet. z = df.diff().hist(color='k', alpha=0.5, bins=50); z
[[<matplotlib.axes._subplots.AxesSubplot object at 0x7f171262f050> <matplotlib.axes._subplots.AxesSubplot object at 0x7f17188caf50>] [<matplotlib.axes._subplots.AxesSubplot object at 0x7f17187d6ed0> <matplotlib.axes._subplots.AxesSubplot object at 0x7f17187e9ed0>]]
# doesn't work. data = pd.Series(np.random.randn(1000)) data.hist(by=np.random.randint(0, 4, 1000), figsize=(6, 4))
[[<matplotlib.axes._subplots.AxesSubplot object at 0x7f1718a9fcd0> <matplotlib.axes._subplots.AxesSubplot object at 0x7f1715f88e50>] [<matplotlib.axes._subplots.AxesSubplot object at 0x7f171876c510> <matplotlib.axes._subplots.AxesSubplot object at 0x7f17188ccb90>]]
df = pd.DataFrame(np.random.rand(10, 5), columns=['A', 'B', 'C', 'D', 'E']) df.plot.box()
color = dict(boxes='DarkGreen', whiskers='DarkOrange', medians='DarkBlue', caps='Gray') df.plot.box(color=color, sym='r+')
df.plot.box(vert=False, positions=[1, 4, 5, 6, 8])
df = pd.DataFrame(np.random.rand(10,2), columns=['Col1', 'Col2'] ) df['X'] = pd.Series(['A','A','A','A','A','B','B','B','B','B']) bp = df.boxplot(by='X') bp # TODO: doesn't work
[<matplotlib.axes._subplots.AxesSubplot object at 0x7f17189ed850> <matplotlib.axes._subplots.AxesSubplot object at 0x7f171895d990>]
df = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd']) df.plot.area()
df.plot.area(stacked=False)
df = pd.DataFrame(np.random.rand(100, 4), columns=['a', 'b', 'c', 'd']) df.plot.scatter(x='a', y='b')
ax = df.plot.scatter(x='a', y='b', color='DarkBlue', label='Group 1') df.plot.scatter(x='c', y='d', color='DarkGreen', label='Group 2', ax=ax)
df.plot.scatter(x='a', y='b', c='c', s=50)
df.plot.scatter(x='a', y='b', s=df['c']*200)
df = pd.DataFrame(np.random.randn(1000, 2), columns=['a', 'b']) df['b'] = df['b'] + np.arange(1000) df.plot.hexbin(x='a', y='b', gridsize=25)
df = pd.DataFrame(np.random.randn(1000, 2), columns=['a', 'b']) df['b'] = df['b'] = df['b'] + np.arange(1000) df['z'] = np.random.uniform(0, 3, 1000) df.plot.hexbin(x='a', y='b', C='z', reduce_C_function=np.max, gridsize=25)
series = pd.Series(3 * np.random.rand(4), index=['a', 'b', 'c', 'd'], name='series') series.plot.pie(figsize=(6, 6))