In [1]:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

%matplotlib inline
In [13]:
import matplotlib as mpl

mpl.rcParams['figure.figsize'] = (13,6)
In [14]:
# Series
ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2016', periods=1000))
#suma skumulowana
ts = ts.cumsum()
ts.plot()
Out[14]:
<matplotlib.axes._subplots.AxesSubplot at 0x176f6a74630>
In [15]:
# DateFrame
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list('ABCD'))
df = df.cumsum()
plt.figure(); df.plot();
<matplotlib.figure.Figure at 0x176f5243278>
In [18]:
plt.figure();
df.iloc[5].plot.bar(); plt.axhline(0)
Out[18]:
<matplotlib.lines.Line2D at 0x176f77b9cf8>
In [17]:
df2 = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
df2.plot.bar()
Out[17]:
<matplotlib.axes._subplots.AxesSubplot at 0x176f739f4e0>
In [19]:
df2.plot.bar(stacked=True)
Out[19]:
<matplotlib.axes._subplots.AxesSubplot at 0x176f78867f0>
In [20]:
df2.plot.barh(stacked=True);
In [21]:
df4 = pd.DataFrame({'a': np.random.randn(1000) + 1, 'b': np.random.randn(1000),
                    'c': np.random.randn(1000) - 1}, columns=['a', 'b', 'c'])
plt.figure()
df4.plot.hist(alpha=0.5)
Out[21]:
<matplotlib.axes._subplots.AxesSubplot at 0x176f7bd76a0>
<matplotlib.figure.Figure at 0x176f7b612b0>
In [22]:
plt.figure()
df['A'].diff().hist()
Out[22]:
<matplotlib.axes._subplots.AxesSubplot at 0x176f7c76ef0>
In [23]:
plt.figure()
df.diff().hist(color='k', alpha=0.5, bins=50)
Out[23]:
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x00000176F7BFFC18>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x00000176F6A58EF0>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x00000176F67726A0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x00000176F79B95C0>]], dtype=object)
<matplotlib.figure.Figure at 0x176f7bd30b8>
In [24]:
df = pd.DataFrame(np.random.rand(10, 5), columns=['A', 'B', 'C', 'D', 'E'])
df.plot.box()
Out[24]:
<matplotlib.axes._subplots.AxesSubplot at 0x176f948e358>
In [26]:
color = dict(boxes='DarkGreen', whiskers='DarkOrange',
              medians='DarkBlue', caps='Gray')
df.plot.box(color=color)
Out[26]:
<matplotlib.axes._subplots.AxesSubplot at 0x176f96f9be0>
In [27]:
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'])
plt.figure()
bp = df.boxplot(by='X')
<matplotlib.figure.Figure at 0x176f95309e8>
In [28]:
df = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
df.plot.area()
Out[28]:
<matplotlib.axes._subplots.AxesSubplot at 0x176f9a4af60>
In [29]:
df.plot.area(stacked=False)
Out[29]:
<matplotlib.axes._subplots.AxesSubplot at 0x176f9af1b00>
In [30]:
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)
Out[30]:
<matplotlib.axes._subplots.AxesSubplot at 0x176f9b7fb00>
In [32]:
from pandas.tools.plotting import scatter_matrix
df = pd.DataFrame(np.random.randn(1000, 4), columns=['a', 'b', 'c', 'd'])
scatter_matrix(df, alpha=0.2, figsize=(6, 6), diagonal='kde')
Out[32]:
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x00000176FA2ED828>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x00000176FA3375C0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x00000176FA2F9C50>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x00000176FA3A2048>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x00000176FA3ECEF0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x00000176FA42AF60>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x00000176FA4802B0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x00000176FA4BDCC0>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x00000176FA50BCF8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x00000176FA5546A0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x00000176FA59FAC8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x00000176FA5E4D68>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x00000176FA6352B0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x00000176FA674BA8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x00000176FA6C80F0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x00000176FA7069E8>]], dtype=object)
In [33]:
from pandas.tools.plotting import andrews_curves
data = pd.read_csv('iris.csv')
plt.figure()
andrews_curves(data, 'Name')
Out[33]:
<matplotlib.axes._subplots.AxesSubplot at 0x176fbf68588>
In [35]:
from pandas.tools.plotting import parallel_coordinates
plt.figure()
parallel_coordinates(data, 'Name')
Out[35]:
<matplotlib.axes._subplots.AxesSubplot at 0x176fc7530f0>
In [36]:
from pandas.tools.plotting import lag_plot
plt.figure()
data = pd.Series(0.1 * np.random.rand(1000) +
     0.9 * np.sin(np.linspace(-99 * np.pi, 99 * np.pi, num=1000)))
lag_plot(data)
Out[36]:
<matplotlib.axes._subplots.AxesSubplot at 0x176fcb729b0>
In [37]:
plt.figure()
data = pd.Series(np.random.rand(1000))
lag_plot(data)
Out[37]:
<matplotlib.axes._subplots.AxesSubplot at 0x176fcbcaf60>
In [38]:
from pandas.tools.plotting import autocorrelation_plot
plt.figure()
data = pd.Series(0.7 * np.random.rand(1000) +
    0.3 * np.sin(np.linspace(-9 * np.pi, 9 * np.pi, num=1000)))
autocorrelation_plot(data)
Out[38]:
<matplotlib.axes._subplots.AxesSubplot at 0x176fcb9e898>
In [39]:
from pandas.tools.plotting import radviz
data = pd.read_csv('iris.csv')
plt.figure()
radviz(data, 'Name')
Out[39]:
<matplotlib.axes._subplots.AxesSubplot at 0x176fcea9eb8>
In [42]:
import seaborn as sns
import random

df = pd.DataFrame()

df['x'] = random.sample(range(1, 100), 25)
df['y'] = random.sample(range(1, 100), 25)

sns.kdeplot(df.y, df.x)
Out[42]:
<matplotlib.axes._subplots.AxesSubplot at 0x176fbf75438>
In [43]:
sns.violinplot([df.y, df.x])
Out[43]:
<matplotlib.axes._subplots.AxesSubplot at 0x176fbfb9198>
In [45]:
sns.heatmap([df.y, df.x], fmt="d")
Out[45]:
<matplotlib.axes._subplots.AxesSubplot at 0x176fe4fbcc0>
In [ ]: