<jupyter_start><jupyter_text>Again, we have to read some data first,...<jupyter_code># first, the imports
import os
import datetime as dt

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display

np.random.seed(19760812)
plt.style.use('bmh')
%matplotlib inline<jupyter_output><empty_output><jupyter_text>We read some wind data<jupyter_code># read the file 'mast.txt'
ipath = os.path.join('Datos', 'mast.txt')

def dateparse(date, time):
    YY = 2000 + int(date[:2])
    MM = int(date[2:4])
    DD = int(date[4:])
    hh = int(time[:2])
    mm = int(time[2:])
    
    return dt.datetime(YY, MM, DD, hh, mm, 0)
    

cols = ['Date', 'time', 'wspd', 'wspd_max', 'wdir',
        'x1', 'x2', 'x3', 'x4', 'x5', 
        'wspd_std']
wind = pd.read_csv(ipath, sep = "\s*", names = cols, 
                   parse_dates = {'Timestamp': [0, 1]}, index_col = 0,
                   date_parser = dateparse)<jupyter_output>/home/tornadin/miniconda3/envs/sciconda/lib/python3.5/site-packages/ipykernel/__main__.py:19: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators; you can avoid this warning by specifying engine='python'.
/home/tornadin/miniconda3/envs/sciconda/lib/python3.5/site-packages/pandas/io/parsers.py:1588: FutureWarning: split() requires a non-empty pattern match.
  yield pat.split(line.strip())
/home/tornadin/miniconda3/envs/sciconda/lib/python3.5/site-packages/pandas/io/parsers.py:1590: FutureWarning: split() requires a non-empty pattern match.
  yield pat.split(line.strip())<jupyter_text>We read a file of environmental data<jupyter_code># we read the file 'model.txt'
ipath = os.path.join('Datos', 'model.txt')

model = pd.read_csv(ipath, sep = "\s*", skiprows = 3,
                    parse_dates = {'Timestamp': [0, 1]}, index_col = 'Timestamp')
for c in ['x1','x2','x3','x4','x5']: # Remove unnecesary columns
    _ = wind.pop(c)
wind.head(3)
model.head(3)
wind['Timestamp'] = wind.index
print(wind['Timestamp'].diff().min())
del wind['Timestamp']
model['Timestamp'] = model.index
print(model['Timestamp'].diff().min())
del model['Timestamp']<jupyter_output>0 days 01:00:00<jupyter_text>`plot` is our *silver bullet*<jupyter_code>wind.loc[:, 'wspd':'wspd_max'].plot(figsize = (15, 6))
wind.loc['2014/01/01 00:00': '2014/01/01 02:00', 'wspd':'wspd_max'].plot(kind = 'bar', figsize = (15, 6))
wind.loc['2014/01/01': '2014/12/31', 'wspd':'wspd_max'].plot(
    kind = 'scatter', 
    x = 'wspd',
    y = 'wspd_max',
    figsize = (15, 6)
)
wind.loc['2014/01/01': '2014/12/31', 'wspd':'wspd_max'].plot(
    kind = 'scatter', 
    x = 'wspd',
    y = 'wspd_max',
    figsize = (15, 6),
    xlim = (0, 32),
    ylim = (0, 40)
)
wind.loc['2014/01/01 00:00': '2014/01/01 02:00', 'wspd':'wspd_max'].plot(
    kind = 'bar', 
    figsize = (15, 6),
    subplots = True
)<jupyter_output><empty_output><jupyter_text>Another way to do it, `plot` provides us an API to use each plotting type:<jupyter_code>s1 = wind.loc['2014/01/01': '2014/01/05', 'wspd']
s2 = s1.rolling(13, center = True).mean()
tmp = pd.DataFrame({'wspd': s1, 'mov_avg': s2})
tmp.plot.line(figsize = (15, 6))<jupyter_output><empty_output><jupyter_text>But what happens if I want to highlight the line `'mov_avg'`. We can do it in the following manner:<jupyter_code>ax = tmp['wspd'].plot.line(figsize = (15, 6))
tmp['mov_avg'].plot.line(figsize = (15, 6), lw = 5, ax = ax)<jupyter_output><empty_output><jupyter_text>Other kind of plots:<jupyter_code>possible = dir(pd.DataFrame.plot)
for p in possible:
    if '_' not in p: print(p)<jupyter_output>area
bar
barh
box
density
hexbin
hist
kde
line
pie
scatter<jupyter_text>Let's see, for instance, the wind speed histogram:<jupyter_code>wind['wspd'].plot.hist(bins = np.arange(0, 50), figsize = (15, 6))<jupyter_output><empty_output><jupyter_text>Also, there is a `plotting` submodule with tools that mix analysis and visualisation.<jupyter_code>pd.tools.plotting.scatter_matrix(
    wind.iloc[0:1000, :], 
    diagonal = 'kde',
    figsize = (12, 12)
)
# Make your own plots using different plots to taht used before<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17114093959731544, 'fraction_numerical': 0.05081495685522531, 'mean_word_length': 4.51984126984127, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '538439', 'license': 'MIT', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1623, 'n_words': 367, 'path': 'workshops_materials/20160408_1100_Pandas_for_beginners/tutorial/EN - Tutorial 06 - plotting results.ipynb', 'repo_name': 'PyDataMadrid2016/Conference-Info', 'size': '4172'}