Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Codes for information visualization using python lab report 2
import plotly.plotly as py
import pandas as pd
df = pd.read_csv('2014_world_gdp_with_codes.csv')
data = [ dict(
type = 'choropleth',
locations = df['CODE'],
z = df['GDP (BILLIONS)'],
text = df['COUNTRY'],
colorscale = [[0,"rgb(5, 10, 172)"],[0.35,"rgb(40, 60, 190)"],[0.5,"rgb(70, 100, 245)"],\
[0.6,"rgb(90, 120, 245)"],[0.7,"rgb(106, 137, 247)"],[1,"rgb(220, 220, 220)"]],
autocolorscale = False,
reversescale = True,
marker = dict(
line = dict (
color = 'rgb(180,180,180)',
width = 0.5
) ),
colorbar = dict(
autotick = False,
tickprefix = '$',
title = 'GDP<br>Billions US$'),
) ]
layout = dict(
title = '2014 Global GDP',
geo = dict(
showframe = False,
showcoastlines = False,
projection = dict(
type = 'Mercator'
)
)
)
fig = dict( data=data, layout=layout )
py.iplot( fig, validate=False, filename='d3-world-map' )
import plotly.plotly as py
import plotly.figure_factory as ff
import numpy as np
X = np.random.rand(10, 10)
names = ['Jack', 'Oxana', 'John', 'Chelsea', 'Mark', 'Alice', 'Charlie', 'Rob', 'Lisa', 'Lily']
fig = ff.create_dendrogram(X, orientation='left', labels=names)
fig['layout'].update({'width':800, 'height':800})
py.iplot(fig, filename='dendrogram_with_labels')
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# Read the Pharma Sector data
df = pd.read_csv("Pharma_Heatmap_data.csv")
# Create an array of stock symbols & their respective percentage price change
symbol = ((np.asarray(df['Symbol'])).reshape(6,5))
perchange = ((np.asarray(df['Change'])).reshape(6,5))
# Create a pivot table
result = df.pivot(index='Yrows',columns='Xcols',values='Change')
# Create an array to annotate the heatmap
labels = (np.asarray(["{0} \n {1:.2f}".format(symb,value)
for symb, value in zip(symbol.flatten(),
perchange.flatten())])
).reshape(6,5)
# Define the plot
fig, ax = plt.subplots(figsize=(13,7))
# Add title to the Heat map
title = "Pharma Sector Heat Map"
# Set the font size and the distance of the title from the plot
plt.title(title,fontsize=18)
ttl = ax.title
ttl.set_position([0.5,1.05])
# Hide ticks for X & Y axis
ax.set_xticks([])
ax.set_yticks([])
# Remove the axes
ax.axis('off')
# Use the heatmap function from the seaborn package
sns.heatmap(result,annot=labels,fmt="",cmap='RdYlGn',linewidths=0.30,ax=ax)
# Display the Pharma Sector Heatmap
plt.show()
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")
# We use violinplot to plot the data
sns.violinplot(x="species", y="petal_length", data=iris, size=6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment