08 ,Seaborn :入門,pycharm 集成 anaconda ,五種風格,線框是否顯示

1 ,Seaborn 簡介 :

Seaborn 是對 matplotlib 的封裝可增強

2 ,安裝 : pycharm

file - settings - priject

3 ,異常解決 :

  1. 異常 :
    OSError: [WinError 126] 找不到指定的模塊。
  2. 解決 : dos 界面操作
    1、pip uninstall scipy seaborn
    2、pip install -i https://pypi.tuna.tsinghua.edu.cn/simple scipy seaborn
  3. 如果還是不對,說明 : 問題是各個庫之間版本不兼容
  4. 解決辦法 : 將各個庫都更新到最新版本
pip install --user --upgrade numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install --user --upgrade pandas -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install --user --upgrade matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install --user --upgrade seaborn -i https://pypi.tuna.tsinghua.edu.cn/simple
  1. 一頓操作猛如虎 : 結果 anaconda 不能使用了
  2. 打開 anaconda prompt 發現出錯了 :
    AttributeError: ‘_NamespacePath’ object has no attribute ‘sort’
  3. 原因是 :conda 中的 pip 版本與 python 中的 pip 版本混亂
  4. 更新 pip :
python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
  1. anaconda 修好了,但是 pycharm 依然報錯
  2. pycharm 引入 Seaborn 的時候報錯 :
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "D:\58pycharm\file\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "D:\58pycharm\file\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/space/pycharm/python03/demo03/d1.py", line 2, in <module>
    import seaborn as sns
  File "D:\58pycharm\file\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\86182\AppData\Roaming\Python\Python36\site-packages\seaborn\__init__.py", line 6, in <module>
    from .rcmod import *
  File "D:\58pycharm\file\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\86182\AppData\Roaming\Python\Python36\site-packages\seaborn\rcmod.py", line 7, in <module>
    from . import palettes, _orig_rc_params
  File "D:\58pycharm\file\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\86182\AppData\Roaming\Python\Python36\site-packages\seaborn\palettes.py", line 9, in <module>
    from .utils import desaturate, set_hls_values, get_color_cycle
  File "D:\58pycharm\file\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\86182\AppData\Roaming\Python\Python36\site-packages\seaborn\utils.py", line 6, in <module>
    from scipy import stats
  File "D:\58pycharm\file\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\86182\AppData\Roaming\Python\Python36\site-packages\scipy\__init__.py", line 104, in <module>
    from . import _distributor_init
  File "D:\58pycharm\file\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\86182\AppData\Roaming\Python\Python36\site-packages\scipy\_distributor_init.py", line 61, in <module>
    WinDLL(os.path.abspath(filename))
  File "D:\75python\file\lib\ctypes\__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] 找不到指定的模塊。
  1. 原因 :
    libmxnet.dll 找不到必需的依賴了
  2. 解決辦法 :
    1 ,用 Dependency Walker 看看缺少哪些 dll
    2 ,把缺少的複製到系統的 path 下或放到 libmxnet 的同目錄
  3. 具體做法 :
pip install Shapely‑1.6.4.post2‑cp36‑cp36m‑win_amd64.whl  -i https://pypi.tuna.tsinghua.edu.cn/simple
  1. 最終找到了原因 :
    1 ,pychrm 用的是 python3.6 ,dos 用的是 python3.5
    2 ,剛纔在 dos 做的所有事情,都是在 python3.5 中做的
  2. 解決 : 修改 pycharm 的 python 版本
    在 pycharm 中集成 anaconda 環境

3 ,pycharm 集成 anaconda 環境 :

  1. file - settings - project interpreter -
    在這裏插入圖片描述
  2. add
  3. 選系統默認的環境 : ( 也就是 anaconda 環境 )
    在這裏插入圖片描述
  4. apply - ok
  5. 等着他集成 :
    在這裏插入圖片描述
  6. pycharm 集成 anaconda 總結 :
    1 ,anaconda 安裝之後,會修改環境變量 : 將系統的 python 變量修改爲 anaconda 的變量
    2 ,爲什麼 pycharm 運行出錯 : 因爲 pycharm 在集成 anaconda 之前,一直用的都是自己安裝的 python ,而我們沒有對自己的 python 做任何操作,pip 安裝的內容都安裝到 anaconde 中的 python 中了
    3 ,pycharm 集成 anaconda 本質 : 將 anaconda 中的 python.exe 拖過來,到 pycharm 中的環境去就好了。

4 ,Seaborn 模板 :

  1. 共幾套 : 5 套
  2. 默認模板的使用 :
    sns.set()

5 ,畫正弦曲線 : 參數 ( 最大高度 )

  1. 代碼 :
# Author:SFL
import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

def sinplot(flip=1):
    # x 座標:生成 ndarray ( 開始,結束,100 個數字 )
    x = np.linspace(0, 14, 100)
    # y 座標
    y = np.sin(x) * flip
    plt.plot(x, y)

if __name__ == '__main__':
    sinplot(2)
  1. 結果 :
  2. 思考 :
    1 ,生成 ndarray : x = np.linspace(0, 14, 100)
    2 ,對全部元素計算 : y = np.sin(x) * flip

6 ,畫 6 條線 : plt 自帶畫風

  1. 代碼 :
if __name__ == '__main__':
    for i in range(6):
        high = i + 1
        sinplot(high)
  1. 結果 :

7 ,畫六條線 : seaborn 默認畫風

  1. 代碼 : sns.set()
if __name__ == '__main__':
    sns.set()
    for i in range(6):
        high = i + 1
        sinplot(high)
  1. 結果 :

8 ,畫 6 條線 : seaborn 五種風格

  1. 五種風格 :
darkgrid : 
whitegrid : 白色背景,有橫線
dark : 灰色背景,沒有線
white : 白色背景,沒有線
ticks : 有座標,沒有線

9 ,darkgrid :就是默認的那個風格 ( 灰色網格 )

  1. 代碼 :
if __name__ == '__main__':
    sns.set_style("darkgrid")
    for i in range(6):
        high = i + 1
        sinplot(high)
  1. 結果 :

10,whitegrid :白色網格

  1. 代碼 :
sns.set_style("whitegrid")
  1. 結果 :

11 ,sns.set_style(“dark”) :黑色背景

  1. 結果 :

12 ,sns.set_style(“white”) : 白色背景

  1. 結果 :

13 ,sns.set_style(“ticks”) : 有座標點

  1. 結果 :

14 ,只有 x ,y 軸 :

  1. 代碼 :
if __name__ == '__main__':
    sns.set_style("ticks")
    for i in range(6):
        high = i + 1
        sinplot(high)
    sns.despine(left=False,bottom=False,top=True,right=True)
  1. 結果 :

15 ,seaborn 盒圖 :

  1. 造集合 ndarray : np.arange(6)
res = np.arange(6)

結果 : [0,1,2,3,4,5]
  1. 造矩陣 :
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章