# Data-visualization-2
In the second part of data visualization,Almost all the plot in this repo is drawn using “Seaborn” library:
>The boxplot is drawn with the randomely generated data,
>Data visualization of the iris data is also show
>Reg plot is also drawn
>lmplot is also ploted
>And also you will learn how to make an network of data
>You can also learn to plot area chart
>And lastly we will learn to plot FactGrid
Look at the code in ploting.ipynb
In [1]:
#import all the modules
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import pandas as pd
In [ ]:
#creating an random data frame for box plot
a=pd.DataFrame({'group': np.repeat('A', 500), 'value': np.random.normal(10,5,500)})
b=pd.DataFrame({'group': np.repeat('B', 500), 'value': np.random.normal(13,1.2,500)})
c=pd.DataFrame({'group': np.repeat('B', 500), 'value': np.random.normal(18,1.2,500)})
d=pd.DataFrame({'group': np.repeat('C', 20), 'value': np.random.normal(25,4,20)})
e=pd.DataFrame({'group': np.repeat('D', 100), 'value': np.random.uniform(12, size=100)})
df=a.append(b).append(c).append(d).append(e)
In [ ]:
sns.boxplot(x='group', y='value', data=df)
In [2]:
import seaborn as sns
import numpy as np
df=sns.load_dataset('iris')
In [12]:
ax=sns.boxplot(x='species', y='sepal_length', data=df)
median=df.groupby(['species'])['sepal_length'].median().values
nobs=df['species'].value_counts().values
nobs=[str(x) for x in nobs.tolist()]
nobs=["n: " +i for i in nobs]
pos=range(len(nobs))
for tick, label in zip(pos, ax.get_xticklabels()):
ax.text(pos[tick], median[tick]+0.03,nobs[tick],horizontalalignment='center', size='x-small', color='yellow', weight='semibold')
In [15]:
sns.regplot(x=df["sepal_length"], y=df["sepal_width"], fit_reg=False)
Out[15]:
In [24]:
sns.regplot(x=df["sepal_length"], y=df["sepal_width"], fit_reg=False, marker="+", scatter_kws={"color":"darkred"})
Out[24]:
In [29]:
sns.lmplot(x="sepal_length", y="sepal_width", data=df, fit_reg=False, hue='species', legend=False)
plt.legend(loc="lower right")
Out[29]:
In [30]:
sns.lmplot(x="sepal_length", y="sepal_width", data=df, fit_reg=False, hue='species', legend=False, markers=["o", "x", "1"])
plt.legend(loc="lower right")
Out[30]:
In [37]:
sns.lmplot(x="sepal_length", y="sepal_width", data=df, fit_reg=False, hue='species', legend=False, palette=dict(setosa="red", virginica='skyblue', versicolor="blue"))
plt.legend(loc="lower right")
Out[37]:
In [39]:
import networkx as nx
In [40]:
df= pd.DataFrame({ 'from':['A', 'B','C', 'A'], 'to':['D','A','E','C']})
df
Out[40]:
In [60]:
G=nx.from_pandas_edgelist(df, 'from', 'to', create_using=nx.Graph())
nx.draw(G, with_labels=True, node_size=200, node_color="skyblue", pos=nx.random_layout(G))
plt.show()
In [3]:
x = range(1,6)
y = [1,4,6,8,4]
In [5]:
plt.fill_between(x, y, color = "green")
plt.title("are chart")
plt.xlabel("xval")
plt.ylabel('y_label')
Out[5]:
In [15]:
country = ['india', 'usa', 'canada', 'russia', 'brazil']
In [16]:
df = pd.DataFrame({"Country": np.repeat(country, 10), 'years': range(2000, 2050), 'value' : np.random.rand(50)})
In [17]:
df
Out[17]:
In [22]:
g = sns.FacetGrid(df, col = "Country", hue = "Country", col_wrap = 4)
g = g.map(plt.plot, 'years','value')
g = g.map(plt.fill_between, 'years', 'value')
In [23]:
g
Out[23]:
In [ ]:
Also check-https://github.com/theone9807/Data-visualization-2
