In [1]:
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
%matplotlib inline
x1_values = [2012, 2013, 2014, 2015]
y1_values = [4.3, 2.5, 3.5, 4.5]
x2_values = [2012, 2013, 2014, 2015]
y2_values = [2.4, 4.4, 1.8, 2.8]
x3_values = [2012, 2013, 2014, 2015]
y3_values = [2, 2, 3, 5]
In [7]:
plt.figure()
plt.plot(x1_values, y1_values, label='Python')
plt.plot(x2_values, y2_values, label='JavaScript')
plt.plot(x3_values, y3_values, label='R')
plt.xlim(2012, 2015)
plt.ylim(0, 6)
plt.xticks([2012, 2013, 2014, 2015], ['2012', '2013', '2014', '2015'])
plt.yticks([1, 2, 3, 4, 5])
plt.xlabel('')
plt.ylabel('Web Searches')
plt.legend(loc='upper center', ncol=3)
plt.grid(True)
plt.savefig('web-searches.png', dpi=150)
In [8]:
column_data = np.random.normal(42, 3, 1000)
plt.figure()
plt.hist(column_data)
Out[8]:
(array([ 12., 25., 115., 197., 237., 218., 130., 50., 11., 5.]), array([ 33.47322037, 35.3363003 , 37.19938024, 39.06246018, 40.92554011, 42.78862005, 44.65169999, 46.51477992, 48.37785986, 50.2409398 , 52.10401973]), <a list of 10 Patch objects>)
In [12]:
sns.distplot(column_data)
Out[12]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fbdab50cac8>
In [13]:
two_columns_data = [np.random.normal(57, 3, 1000),
np.random.normal(42, 7, 1000)]
plt.boxplot(two_columns_data)
Out[13]:
{'boxes': [<matplotlib.lines.Line2D at 0x7fbdab4609e8>, <matplotlib.lines.Line2D at 0x7fbdab400f60>], 'caps': [<matplotlib.lines.Line2D at 0x7fbdab46be10>, <matplotlib.lines.Line2D at 0x7fbdab477cf8>, <matplotlib.lines.Line2D at 0x7fbdab410f98>, <matplotlib.lines.Line2D at 0x7fbdab419828>], 'fliers': [<matplotlib.lines.Line2D at 0x7fbdab400dd8>, <matplotlib.lines.Line2D at 0x7fbdab422908>], 'means': [], 'medians': [<matplotlib.lines.Line2D at 0x7fbdab477ef0>, <matplotlib.lines.Line2D at 0x7fbdab419a20>], 'whiskers': [<matplotlib.lines.Line2D at 0x7fbdab460be0>, <matplotlib.lines.Line2D at 0x7fbdab46bc18>, <matplotlib.lines.Line2D at 0x7fbdab40aeb8>, <matplotlib.lines.Line2D at 0x7fbdab410748>]}
In [16]:
sns.boxplot(data=two_columns_data)
Out[16]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fbdab294d68>
In [19]:
years = np.arange(2012, 2015)
values = [2, 5, 9]
plt.figure()
plt.bar(years, values)
Out[19]:
<Container object of 3 artists>
In [20]:
sns.barplot(years, values)
Out[20]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fbdab107f60>
In [3]:
counts = [17, 14]
plt.figure()
plt.pie(counts)
Out[3]:
([<matplotlib.patches.Wedge at 0x7f8941b91828>, <matplotlib.patches.Wedge at 0x7f8941ba14a8>], [<matplotlib.text.Text at 0x7f8941b91f98>, <matplotlib.text.Text at 0x7f8941ba1c18>])
In [4]:
counts = [17, 14]
plt.figure(figsize=(4, 4))
plt.pie(counts,
colors=['blue', 'orange'],
labels=['Category A', 'Other categories'],
startangle=90,
autopct='%1.1f%%')
Out[4]:
([<matplotlib.patches.Wedge at 0x7f8941b44860>, <matplotlib.patches.Wedge at 0x7f8941acfa58>], [<matplotlib.text.Text at 0x7f8941b44f60>, <matplotlib.text.Text at 0x7f8941ad6240>], [<matplotlib.text.Text at 0x7f8941acf518>, <matplotlib.text.Text at 0x7f8941ad6710>])
In [6]:
x = range(20)
y = np.arange(50, 70) + (np.random.random(20) * 10.)
plt.figure()
plt.scatter(x, y)
Out[6]:
<matplotlib.collections.PathCollection at 0x7f894198c4e0>
In [11]:
x = np.arange(20)
y = np.arange(50, 70) + (np.random.random(20) * 10.)
plt.figure()
plt.scatter(x,
y,
c='red',
s=40,
marker='s',
edgecolor='none')
Out[11]:
<matplotlib.collections.PathCollection at 0x7f8941892a90>