Professional Documents
Culture Documents
• df = pd.DataFrame(np.random.randn(10,
4).cumsum(0), columns=['A', 'B', 'C', 'D'],
index=np.arange(0, 100, 10))
• df.plot()
• df.plot.bar()
Seaborn
• import seaborn as sns
• sns.set()
• plt.plot(x, y)
• plt.legend('ABCDEF', ncol=2, loc='upper left')
Plotting histogram
• data = np.random.multivariate_normal([0, 0],
[[5, 2], [2, 2]], size=2000)
• data = pd.DataFrame(data, columns=['x', 'y'])
• for col in 'xy':
– plt.hist(data[col], normed=True, alpha=0.5)
Kernel density plot
• for col in 'xy':
– sns.kdeplot(data[col], shade=True)
Distplot
• sns.distplot(data['x'])
• sns.distplot(data['y']);
Pair plot
• iris = sns.load_dataset("iris")
• iris.head()
• sns.pairplot(iris, hue='species', size=2.5);
Factor plot
• tips = sns.load_dataset('tips')
• tips.head()
• with sns.axes_style(style='ticks'):
– g = sns.factorplot("day", "total_bill", "sex",
data=tips, kind="box")
– g.set_axis_labels("Day", "Total Bill");
Scatter plot
• sns.relplot(x="Views", y="Upvotes", data = df)
• sns.relplot(x="Views", y="Upvotes", hue =
"Tag", data = df)
• sns.relplot(x="Views", y="Upvotes", hue =
"Answers", data = df);
Box plot
• sns.catplot(x="education",
y="avg_training_score", kind = "box",
data=df2)
Violin plot
• sns.catplot(x="education",
y="avg_training_score", hue = "is_promoted",
kind = "violin", data=df2)
Heatmaps
• corrmat = df2.corr()
• f, ax = plt.subplots(figsize=(9, 6))
• sns.heatmap(corrmat, vmax=.8, square=True)
Other tools
• As is common with open source, there are a
plethora of options for creating graphics in
Python
• With tools like Bokeh and Plotly, it’s now
possible to specify dynamic, interactive
graphics in Python that are destined for a web
browser