Image for post
Image for post

Visualization for Data Science in Python

Getting started & overview.

Choosing a library :

Dataset : (Coindesks Bitcoin's yearly close price) :https://github.com/KenoLeon/PythonDev/blob/master/visualization/coindeskBTC.csvSourceFiles: https://github.com/KenoLeon/PythonDev/tree/master/visualization

1. Matplotlib:

#Import Libraries
import matplotlib.pyplot as plt
import pandas as pd
# Read DataFrame ( and parse axis dates)
df = pd.read_csv("visualization/coindeskBTC.csv", usecols=['Date','BTC Close'], parse_dates=['Date'])
# Use Date as index
df.set_index('Date',inplace=True)
# Plot & show
plt.plot(df['BTC Close'])
plt.show()
Image for post
Image for post
Note: While not a pandas tutorial, formatting and reading is easier with a data frame. 

2. Seaborn:

#Import Libraries
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
# Read DataFrame,parse and set axis dates)
df = pd.read_csv("visualization/coindeskBTC.csv", usecols=['Date','BTC Close'], parse_dates=['Date'])
df.set_index('Date',inplace=True)# Seaborn Style:
sns.set(style="darkgrid")
# Same as with matplotlib:
plt.plot(df['BTC Close'])
plt.show()
# Notice it is basically the same as the matplotlib example, we just imported seaborn.
Image for post
Image for post

3. Bokeh:

#Import Libraries
import pandas as pd
from bokeh.plotting import figure, output_file, show
# Read DataFrame and parse x axis datesdf = pd.read_csv("visualization/coindeskBTC.csv", usecols=['Date','BTC Close'], parse_dates=['Date'])# Notice we don't need to set the index, bokeh takes care of that# Create a file, this will save your plot in html format
output_file("BTC_Price_Chart.html")
# create a new plot with a datetime axis type
p = figure(plot_width=1200, plot_height=800, x_axis_type="datetime")
# Add the series with some minimal styling
p.line(df['Date'], df['BTC Close'], color='cornflowerblue', line_width= 3, alpha=1)
show(p)
Image for post
Image for post
p.xgrid.grid_line_color = "purple"
p.xgrid.grid_line_alpha = 0.4
p.ygrid.grid_line_color = "purple"
p.ygrid.grid_line_alpha = 0.6
p.ygrid.grid_line_dash = [6, 4]
p.background_fill_color = "Darkgrey"
p.background_fill_alpha = 0.2
Image for post
Image for post

Conclusion:

4. Plotly:

# Import Libraries
import plotly as py
import plotly.graph_objs as go
import pandas as pd
# Read DataFrame
df = pd.read_csv("visualization/coindeskBTC.csv", usecols=['Date','BTC Close'], parse_dates=['Date'])
# Basic plotly plot
data = [go.Scatter(
x=df.Date,
y=df['BTC Close'])]
py.offline.plot(data)
Image for post
Image for post

About the Author :

Written by

AI, Software Developer, Designer : www.k3no.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store