Skip to content

Instantly share code, notes, and snippets.

@iCHAIT
Last active January 21, 2018 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iCHAIT/6e81d611f5bbad15d927f44c1c25f28d to your computer and use it in GitHub Desktop.
Save iCHAIT/6e81d611f5bbad15d927f44c1c25f28d to your computer and use it in GitHub Desktop.
Codes for Information Visualisation using python.
import plotly.plotly as py
import plotly.graph_objs as go
import pandas as pd
iris = pd.read_csv("iris.csv")
data = [go.Histogram(x=iris['sepal_length'].tolist())]
layout = go.Layout(title='Iris Dataset - Sepal.Length',
xaxis=dict(title='Sepal.Length'),
yaxis=dict(title='Count')
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig)
from bokeh.plotting import figure, show, output_file
import pandas as pd
data = pd.read_csv('iris.csv')
colormap = {'setosa': 'red', 'versicolor': 'green', 'virginica': 'blue'}
colors = [colormap[x] for x in data['species']]
p = figure(title = "Iris Morphology")
p.xaxis.axis_label = 'Petal Length'
p.yaxis.axis_label = 'Petal Width'
p.circle(data["petal_length"], data["petal_width"],
color=colors, fill_alpha=0.2, size=10)
output_file("iris.html", title="iris.py example")
show(p)
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
fig, ax = plt.subplots()
ax.plot(t, s)
ax.set(xlabel = 'time (s)', ylabel = 'voltage (mV)', title = 'Simple Line Plot')
ax.grid()
plt.show()
import matplotlib.pyplot as plt
import pandas as pd
iris = pd.read_csv('iris.csv')
p_length = iris['petal_length'].tolist()
bins = [0,1,2,3,4,5,6,7,8,9]
plt.hist(p_length, bins, histtype = 'bar', rwidth=0.8)
plt.xlabel("Petal Length")
plt.ylabel("Count")
plt.title("Petal Length Distribution")
plt.legend()
plt.show()
import matplotlib.pyplot as plt
# Data to plot
labels = 'Python', 'C++', 'Ruby', 'Java'
sizes = [215, 130, 245, 210]
colors = ['gold', 'yellowgreen', 'lightcoral', 'lightskyblue']
explode = (0.1, 0, 0, 0) # explode 1st slice
# Plot
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=140)
plt.axis('equal')
plt.show()
import plotly.plotly as py
import plotly.graph_objs as go
import pandas as pd
iris = pd.read_csv("iris.csv")
data = [go.Bar(x=['setosa','versicolor','virginica'],
y=[iris.loc[iris['species']=='setosa'].shape[0],
iris.loc[iris['species']=='versicolor'].shape[0],iris.loc[iris['species']=='virginica'].shape[0]]
)]
layout = go.Layout(title='Iris Dataset - Species',
xaxis=dict(title='Iris Dataset - Species'),
yaxis=dict(title='Count')
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig)
import matplotlib.pyplot as plt
import pandas as pd
iris = pd.read_csv('iris.csv')
for n in range(0,150):
if iris['species'][n] == 'setosa':
plt.scatter(iris['sepal_length'][n],iris['sepal_width'][n],color='red')
plt.xlabel('sepal_length')
plt.ylabel('sepal_width')
elif iris['species'][n] == 'versicolor':
plt.scatter(iris['sepal_length'][n],iris['sepal_width'][n],color='blue')
else:
plt.scatter(iris['sepal_length'][n],iris['sepal_width'][n],color='green')
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style='white', color_codes=True)
iris = pd.read_csv("iris.csv")
sns.boxplot(x="species", y="petal_length", data=iris)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment