Tutorial hidrokit.viz.graph

  • Kategori: data visualization
  • Tujuan: Menampilkan dataset melalui bentuk grafik/plot
  • Dokumentasi: readthedocs

Informasi notebook

  • notebook name: taruma_hidrokit_viz_graph
  • notebook version/date: 1.0.1/20190713
  • notebook server: Google Colab
  • hidrokit version: 0.2.0
  • python version: 3.7

Instalasi hidrokit

In [0]:
### Instalasi melalui PyPI
!pip install hidrokit

### Instalasi melalui Github
# !pip install git+https://github.com/taruma/hidrokit.git

### Instalasi melalui Github (Latest)
# !pip install git+https://github.com/taruma/[email protected]
Requirement already satisfied: hidrokit in /usr/local/lib/python3.6/dist-packages (0.2.0)
Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from hidrokit) (1.16.4)
Requirement already satisfied: pandas in /usr/local/lib/python3.6/dist-packages (from hidrokit) (0.24.2)
Requirement already satisfied: matplotlib in /usr/local/lib/python3.6/dist-packages (from hidrokit) (3.0.3)
Requirement already satisfied: pytz>=2011k in /usr/local/lib/python3.6/dist-packages (from pandas->hidrokit) (2018.9)
Requirement already satisfied: python-dateutil>=2.5.0 in /usr/local/lib/python3.6/dist-packages (from pandas->hidrokit) (2.5.3)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/dist-packages (from matplotlib->hidrokit) (0.10.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->hidrokit) (2.4.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->hidrokit) (1.1.0)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/dist-packages (from python-dateutil>=2.5.0->pandas->hidrokit) (1.12.0)
Requirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (from kiwisolver>=1.0.1->matplotlib->hidrokit) (41.0.1)

Import Library

In [0]:
import numpy as np
import pandas as pd

Dataset

In [0]:
# Ambil dataset dari data test hidrokit
!wget -O dataset.csv "https://github.com/taruma/hidrokit/blob/master/tests/data/one_year_three_columns.csv?raw=true"
--2019-07-12 03:20:27--  https://github.com/taruma/hidrokit/blob/master/tests/data/one_year_three_columns.csv?raw=true
Resolving github.com (github.com)... 140.82.114.3
Connecting to github.com (github.com)|140.82.114.3|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github.com/taruma/hidrokit/raw/master/tests/data/one_year_three_columns.csv [following]
--2019-07-12 03:20:27--  https://github.com/taruma/hidrokit/raw/master/tests/data/one_year_three_columns.csv
Reusing existing connection to github.com:443.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/taruma/hidrokit/master/tests/data/one_year_three_columns.csv [following]
--2019-07-12 03:20:27--  https://raw.githubusercontent.com/taruma/hidrokit/master/tests/data/one_year_three_columns.csv
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.0.133, 151.101.64.133, 151.101.128.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7242 (7.1K) [text/plain]
Saving to: ‘dataset.csv’

dataset.csv         100%[===================>]   7.07K  --.-KB/s    in 0s      

2019-07-12 03:20:27 (65.6 MB/s) - ‘dataset.csv’ saved [7242/7242]

In [0]:
# Baca dataset
dataset = pd.read_csv('dataset.csv', index_col=0, parse_dates=True)
dataset.head(10)
Out[0]:
sta_a sta_b sta_c
2000-01-01 7 79 19
2000-01-02 17 79 65
2000-01-03 79 51 25
2000-01-04 48 75 31
2000-01-05 81 33 80
2000-01-06 26 3 96
2000-01-07 78 75 26
2000-01-08 71 95 65
2000-01-09 48 71 22
2000-01-10 32 89 88
In [0]:
# Info dataset
dataset.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 366 entries, 2000-01-01 to 2000-12-31
Data columns (total 3 columns):
sta_a    366 non-null int64
sta_b    366 non-null int64
sta_c    366 non-null int64
dtypes: int64(3)
memory usage: 11.4 KB

Fungsi graph.subplots()

  • Tujuan: Plot dataset numerik dalam bentuk baris dan kolom (subplots)
  • Sintaks: viz.graph.subplots(dataframe, ncols=3, nrows=5, figsize=None)
  • Return: (fig, axes)
  • Dokumentasi: readthedocs
In [0]:
from hidrokit.viz import graph

Gunakan ; untuk tidak menampilkan nilai yang dikembalikan oleh fungsi.

In [0]:
# Dalam bentuk satu kolom
graph.subplots(dataset, ncols=1, nrows=3, figsize=(15,10));
In [0]:
# Dalam bentuk satu kolom
graph.subplots(dataset, ncols=2, nrows=2, figsize=(15,10));

Changelog

- 20190713 - 1.0.1 - Informasi Notebook
- 20190712 - 1.0.0 - Initial

Source code in this notebook is licensed under a MIT License. Data in this notebook is licensed under a Creative Common Attribution 4.0 International.