Python 1. 读取excel文件,2D密度图

2020-04-22  本文已影响0人  MJades
    # Library & dataset
    import seaborn as sns
    import re
    import pandas as pd
    import matplotlib.pyplot as plt

    # Data
    df = pd.read_excel("~/Documents/15.python/4. thala/1. Set_1-6.xlsx")
    data_scale = df.filter(regex="Scaled", axis=1)
    # print(data_scale.columns[0])
    name_list = []
      for col_name in data_scale.columns:
         pattern = re.search('([MIC][0-9]+)', col_name)
        name_list.append(pattern.group(1))
    #    print(pattern.group(1))
    data_scale.columns = name_list
    new = data_scale.dropna(axis=0, how='any')

    # Basic 2D density plot
    sns.set_style("white")
    sns.kdeplot(new.M1, new.M2)
    plt.show()
    # Custom it with the same argument as 1D density plot
    sns.kdeplot(new.M1, new.M2, cmap="Reds", shade=True, bw=.15)
    plt.show()
    # Some features are characteristic of 2D: color palette and wether or not color the lowest range
    sns.kdeplot(new.M1, new.M2, cmap="Blues", shade=True, shade_lowest=True, )
    plt.show()
output_0_0.png output_0_1.png output_0_2.png
上一篇下一篇

猜你喜欢

热点阅读