在线不卡日本ⅴ一区v二区_精品一区二区中文字幕_天堂v在线视频_亚洲五月天婷婷中文网站

  • <menu id="lky3g"></menu>
  • <style id="lky3g"></style>
    <pre id="lky3g"><tt id="lky3g"></tt></pre>

    python可視化分析(四)-繪制邊緣直方圖

    python可視化分析(四)-繪制邊緣直方圖

    實(shí)現(xiàn)功能

    python繪制邊緣直方圖,用于展示X和Y之間的關(guān)系、及X和Y的單變量分布情況,常用于數(shù)據(jù)探索分析。

    實(shí)現(xiàn)代碼

    1

    import pandas as pd

    2

    import matplotlib as mpl

    3

    import matplotlib.pyplot as plt

    4

    import seaborn as sns

    5

    import warnings

    6

    warnings.filterwarnings(action=’once’)

    7

    plt.style.use(‘seaborn-whitegrid’)

    8

    sns.set_style(“whitegrid”)

    9

    print(mpl.__version__)

    10

    print(sns.__version__)

    11

    12

    def draw_Marginal_Histogram(file):

    13

    # Import Data

    14

    df = pd.read_csv(file)

    15

    16

    # Create Fig and gridspec

    17

    fig = plt.figure(figsize=(10, 6), dpi=100)

    18

    grid = plt.GridSpec(4, 4, hspace=0.5, wspace=0.2)

    19

    20

    # Define the axes

    21

    ax_main = fig.add_subplot(grid[:-1, :-1])

    22

    ax_right = fig.add_subplot(grid[:-1, -1], xticklabels=[], yticklabels=[])

    23

    ax_bottom = fig.add_subplot(grid[-1, 0:-1], xticklabels=[], yticklabels=[])

    24

    25

    # Scatterplot on main ax

    26

    ax_main.scatter(‘displ’,

    27

    ‘hwy’,

    28

    s=df.cty * 4,

    29

    c=df.manufacturer.astype(‘category’).cat.codes,

    30

    alpha=.9,

    31

    data=df,

    32

    cmap=”Set1″,

    33

    edgecolors=’gray’,

    34

    linewidths=.5)

    35

    36

    # histogram on the right

    37

    ax_bottom.hist(df.displ,

    38

    40,

    39

    histtype=’stepfilled’,

    40

    orientation=’vertical’,

    41

    color=’#098154′)

    42

    ax_bottom.invert_yaxis()

    43

    44

    # histogram in the bottom

    45

    ax_right.hist(df.hwy,

    46

    40,

    47

    histtype=’stepfilled’,

    48

    orientation=’horizontal’,

    49

    color=’#098154′)

    50

    51

    # Decorations

    52

    ax_main.set(title=’Scatterplot with Histograms displ vs hwy’,

    53

    xlabel=’displ’,

    54

    ylabel=’hwy’)

    55

    ax_main.title.set_fontsize(10)

    56

    for item in ([ax_main.xaxis.label, ax_main.yaxis.label] +

    57

    ax_main.get_xticklabels() + ax_main.get_yticklabels()):

    58

    item.set_fontsize(10)

    59

    60

    xlabels = ax_main.get_xticks().tolist()

    61

    ax_main.set_xticklabels(xlabels)

    62

    plt.show()

    63

    64

    draw_Marginal_Histogram(“F:數(shù)據(jù)雜壇datasetsmpg_ggplot2.csv”)

    實(shí)現(xiàn)效果

    喜歡記得點(diǎn)贊,在看,收藏,

    關(guān)注V訂閱號(hào):數(shù)據(jù)雜壇,獲取數(shù)據(jù)集,完整代碼和效果,將持續(xù)更新!

    鄭重聲明:本文內(nèi)容及圖片均整理自互聯(lián)網(wǎng),不代表本站立場(chǎng),版權(quán)歸原作者所有,如有侵權(quán)請(qǐng)聯(lián)系管理員(admin#wlmqw.com)刪除。
    上一篇 2022年6月23日 15:24
    下一篇 2022年6月23日 15:25

    相關(guān)推薦

    聯(lián)系我們

    聯(lián)系郵箱:admin#wlmqw.com
    工作時(shí)間:周一至周五,10:30-18:30,節(jié)假日休息