In [2]:
plt.plot(np.arange(10))
Out[2]:
In [19]:
fig = plt.figure(figsize=(10,8))
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,3)
ax1.plot(np.random.randn(50).cumsum())
ax2.plot(np.random.randn(50).cumsum())
ax3.plot(np.random.randn(50).cumsum())
Out[19]:
In [10]:
plt.plot(np.random.randn(50).cumsum(), 'k--')
Out[10]:
In [20]:
np.random.randn(50).cumsum()
Out[20]:
In [21]:
np.random.randn(50)
Out[21]:
In [29]:
plt.plot(np.random.randn(30), "og--")
Out[29]:
In [32]:
plt.plot(np.random.randn(30),color = "green", linestyle = "--", marker = "o")
Out[32]:
In [33]:
data = np.random.randn(30).cumsum()
In [37]:
plt.plot(data, 'k--', label='Default')
plt.plot(data, 'k-', drawstyle='steps-post', label='steps-post')
plt.legend(loc='best')
Out[37]:
In [38]:
from numpy.random import randn
In [48]:
fig = plt.figure(figsize=(10,8)); ax = fig.add_subplot(1, 1, 1)
ax.plot(randn(1000).cumsum(), 'g', label='one')
ax.plot(randn(1000).cumsum(), 'r--', label='two')
ax.plot(randn(1000).cumsum(), 'k.', label='three')
ax.legend(loc='best')
Out[48]:
Annotate¶
In [79]:
from datetime import datetime
fig = plt.figure(figsize=(18,10))
ax = fig.add_subplot(1, 1, 1)
data = pd.read_csv('examples/spx.csv', index_col=0, parse_dates=True)
spx = data['SPX']
#spx.plot(ax=ax, style='k-')
ax.plot(spx, "k-")
crisis_data = [
(datetime(2007, 10, 11), 'Peak of bull market'),
(datetime(2008, 3, 12), 'Bear Stearns Fails'),
(datetime(2008, 9, 15), 'Lehman Bankruptcy')
]
for date, label in crisis_data:
ax.annotate(label, xy=(date, spx.asof(date) + 50),
xytext=(date, spx.asof(date) + 200),
arrowprops=dict(facecolor='red'),
horizontalalignment='left', verticalalignment='top')
# Zoom in on 2007-2010
ax.set_xlim(['1/1/2007', '1/1/2011'])
ax.set_ylim([600, 1800])
ax.set_title('Important dates in 2008-2009 financial crisis')
Out[79]:
Bar plots¶
In [62]:
fig = plt.figure(figsize=(10,8))
ax1 = fig.add_subplot(2,1,1)
ax2 = fig.add_subplot(2,1,2)
data = pd.Series(np.random.rand(16), index=list('abcdefghijklmnop'))
data.plot.bar(ax=ax1, color='k', alpha=0.7)
data.plot.barh(ax=ax2, color='k', alpha=0.7)
Out[62]:
In [65]:
df = pd.DataFrame(np.random.rand(6, 4), index=['one', 'two', 'three', 'four', 'five', 'six'], \
columns=pd.Index(['A', 'B', 'C', 'D'], name='Genus'))
In [66]:
df
Out[66]:
In [69]:
df.plot(kind = 'bar', figsize=(10,8))
Out[69]:
In [71]:
df.plot.barh(stacked=True, alpha=0.5, figsize = (10,8))
Out[71]:
In [72]:
comp1 = np.random.normal(0, 1, size=200) # Normal(0, 1)
comp2 = np.random.normal(10, 2, size=200) # Normal(10, 2)
In [73]:
values = pd.Series(np.concatenate([comp1, comp2]))
In [74]:
sns.distplot(values, bins=100, color='k')
Out[74]:
In [ ]:
No comments :
Post a Comment