Python
  • Introduction
  • Chapter 1.Notes from research
    • 1.Introduction of Python
    • 2. Build developer environment
      • 2.1.Sublime Text3
      • 2.2.Jupyter(IPython notebook)
        • 2.2.1.Introduction
        • 2.2.2.Basic usage
        • 2.2.3.some common operations
      • 2.3.Github
        • 2.3.1.Create Github account
        • 2.3.2.Create a new repository
        • 2.3.3.Basic operations: config, clone, push
      • 2.4.Install Python 3.4 in Windows
    • 3. Write Python code
      • 3.1.Hello Python
      • 3.2.Basic knowledges
      • 3.3.撰寫獨立python程式
      • 3.4.Arguments parser
      • 3.5.Class
      • 3.6.Sequence
    • 4. Web crawler
      • 4.1.Introduction
      • 4.2.requests
      • 4.3.beautifulSoup4
      • 3.4.a little web crawler
    • 5. Software testing
      • 5.1. Robot Framework
        • 1.1.Introduction
        • 1.2.What is test-automation framework?
        • 1.3.Robot Framework Architecture
        • 1.4.Robot Framework Library
        • 1.5.Reference
    • 6. encode/ decode
      • 6.1.編碼/解碼器的基本概念
      • 6.2.常見的編碼/ 解碼錯誤訊息與其意義
      • 6.3 .處理文字檔案
    • 7. module
      • 7.1.Write a module
      • 7.2.Common module
        • 7.2.1.sched
        • 7.2.2.threading
    • 8. Integrate IIS with django
      • 8.1.Integrate IIS with django
  • Chapter 2.Courses
    • 2.1.Python for Data Science and Machine Learning Bootcamp
      • 2.1.1.Virtual Environment
      • 2.1.2.Python crash course
      • 2.1.3.Python for Data Analysis - NumPy
        • 2.1.3.1.Numpy arrays
        • 2.1.3.2.Numpy Array Indexing
        • 2.1.3.3.Numpy Operations
      • 2.1.4.Python for Data Analysis - Pandas
        • 2.1.4.1.Introduction
        • 2.1.4.2.Series
        • 2.1.4.3.DataFrames
        • 2.1.4.4.Missing Data
        • 2.1.4.5.GroupBy
        • 2.1.4.6.Merging joining and Concatenating
        • 2.1.4.7.Data input and output
      • 2.1.5.Python for Data Visual Visualization - Pandas Built-in Data Visualization
      • 2.1.6.Python for Data Visualization - Matplotlib
        • 2.1.6.1.Introduction of Matplotlib
        • 2.1.6.2.Matplotlib
      • 2.1.7.Python for Data Visualization - Seaborn
        • 2.1.7.1.Introduction to Seaborn
        • 2.1.7.2.Distribution Plots
        • 2.1.7.3.Categorical Plots
        • 2.1.7.4.Matrix Plots
        • 2.1.7.5.Grids
        • 2.1.7.6.Regression Plots
      • 2.1.8. Python for Data Visualization - Plotly and Cufflinks
        • 2.1.8.1.Introduction to Plotly and Cufflinks
        • 2.1.8.2.Plotly and Cufflinks
      • 2.1.9. Python for Data Visualization - Geographical plotting
        • 2.1.9.1.Choropleth Maps - USA
        • 2.1.9.2.Choropleth Maps - World
      • 2.1.10.Combine data analysis and visualization to tackle real world data sets
        • 911 calls capstone project
      • 2.1.11.Linear regression
        • 2.1.11.1.Introduction to Scikit-learn
        • 2.1.11.2.Linear regression with Python
      • 2.1.12.Logistic regression
        • 2.1.12.1.Logistic regression Theory
        • 2.1.12.2.Logistic regression with Python
      • 2.1.13.K Nearest Neighbors
        • 2.1.13.1.KNN Theory
        • 2.1.13.2.KNN with Python
      • 2.1.14.Decision trees and random forests
        • 2.1.14.1.Introduction of tree methods
        • 2.1.14.2.Decision trees and Random Forests with Python
      • 2.1.15.Support Vector Machines
      • 2.1.16.K means clustering
      • 2.1.17.Principal Component Analysis
    • 2.2. Machine Learning Crash Course Jam
Powered by GitBook
On this page
  • 1.使用library
  • 2.資料判讀與讀取
  • 3.Setting before plot
  • 4.Histogram plot
  • 5.Area plot
  • 6.Line plot
  • 6.Bar plot
  • 7.Scatter plot
  • 8.Box plot
  • 9.Density plot
  • 10.Hexbin plot

Was this helpful?

  1. Chapter 2.Courses
  2. 2.1.Python for Data Science and Machine Learning Bootcamp

2.1.5.Python for Data Visual Visualization - Pandas Built-in Data Visualization

Previous2.1.4.7.Data input and outputNext2.1.6.Python for Data Visualization - Matplotlib

Last updated 5 years ago

Was this helpful?

1.使用library

import numpy as np
import pandas as pd
  • 將matplotlib的圖表直接嵌入到Notebook之中

%matplotlib inline

2.資料判讀與讀取

  • 讀取資料格式 (df1)

    • 由於df1的資料有時間這個索引值, 因此必須指定index為0

    • 讀取資料

      df1 = pd.read_csv('df1', index_col = 0)
      df1.head()
  • 讀取資料格式 (df2)

    • 讀取資料

      df2 = pd.read_csv('df2')
      df2.head()

3.Setting before plot

    • 設定圖的大小

      plt.figure(figsize=(10,6))

4.Histogram plot

  • 將df1的資料畫成長條圖

df1['A'].hist(bins = 30)
  • 也可以用

df1['A'].plot(kind='hist', bins = 30)
  • 可以搭配filter使用, 例如

df[df[B] == 1][A].plot(kind='hist', bins = 30)
  • 用hist比較不同性質的資料

df = pd.read_csv('loan_data.csv')
df.head()
plt.figure()
df[df['credit.policy']==1]['fico'].plot(kind = 'hist', bins = 30, color = 'blue', alpha = 0.5, label = 'Credit.Policy=1')
df[df['credit.policy']==0]['fico'].plot(kind = 'hist', bins = 30, color = 'red', alpha = 0.5, label = 'Credit.Policy=0')
plt.legend()
plt.xlabel('FICO')

5.Area plot

  • alpha為透明度參數

df2.plot.area(alpha = 0.4)

6.Line plot

  • 基本用法

df1.plot.line(x=df1.index, y = 'B')

6.Bar plot

  • 基本用法

df2.plot.bar(alpha = 0.4)
  • stacked

df2.plot.bar(alpha = 0.4, stacked = True)

7.Scatter plot

  • 基本用法

df1.plot.scatter(x='A', y='B')
  • 將原始資料作為色調值的來源

df1.plot.scatter(x='A', y='B', c='C', cmap='coolwarm')
  • 將原始資料作為尺度的來源

df1.plot.scatter(x='A', y='B', s=df1['C']*100)

8.Box plot

df2.plot.box()
  • 將兩資料的box plot畫在一起

df1[['A','B']].plot.box()

9.Density plot

  • 基本用法

df2.plot.density()
  • 改變線條的style (width, size)

df2.plot.density(lw=5,ls='--')

10.Hexbin plot

  • 基本用法

df = pd.DataFrame(np.random.randn(1000, 2), columns=['a', 'b'])df.plot.hexbin(x='a', y='b', gridsize=25, cmap='coolwarm')

由於此資料沒有索引值, 不需指定index

一般會配合一起使用

基本用法, 關於boxplot的定義可以參考

Matplotlib
此篇筆記