Exemple #1
0
def test4():
    data = pd.read_csv("https://raw.githubusercontent.com/selva86/datasets/master/mpg_ggplot2.csv")
    # 画 cty 城市里程/加仑 和 hwy 公路里程/加仑 的 点图
    DrawTools.init()
    DrawTools.scatter(data=data, feature_x='cty', feature_y='hwy')
    DrawTools.font_desc(title='关系图', xlabel='城市里程/加仑', ylabel='公路里程/加仑', legends=None)
    plt.show()
Exemple #2
0
def test7():
    # 画 displ 发动机排量,cyl 气缸数量,hwy 公路里程/加仑  cyl是 4和8的
    data = pd.read_csv("https://raw.githubusercontent.com/selva86/datasets/master/mpg_ggplot2.csv")
    DrawTools.init()
    fig = plt.figure(figsize=(16, 10), dpi=80)
    grid = plt.GridSpec(4, 4, hspace=0.5, wspace=0.2)
    ax_main = fig.add_subplot(grid[:-1, :-1])
    ax_right = fig.add_subplot(grid[:-1, -1], xticklabels=[], yticklabels=[])
    ax_bottom = fig.add_subplot(grid[-1, :-1], xticklabels=[], yticklabels=[])
    # displ 发动机排量(L)
    # hwy 公路里程/加仑
    DrawTools.scatter(data=data, feature_x='displ', feature_y='hwy', feature_c='manufacturer', feature_s='cty',
                      ax=ax_main)
    DrawTools.font_desc(ax_main, title='边缘直方图 \n 发动机排量 vs 公路里程/加仑', xlabel='发动机排量(L)', ylabel='公里路程/加仑')
    DrawTools.hist(data, feature_x='hwy', bins=40, vertical=False, color='deeppink', ax=ax_right)
    DrawTools.hist(data, feature_x='displ', bins=40, vertical=True, invert_y=True, color='deeppink',
                   ax=ax_bottom)

    xlabels = ax_main.get_xticks().tolist()  # 将现有的标尺取出来,转化为带一位小数的浮点数
    ax_main.set_xticklabels(xlabels)  # 再将带一位小数的浮点数变成标尺
    plt.show()
Exemple #3
0
def test8():
    data = pd.read_csv("https://raw.githubusercontent.com/selva86/datasets/master/mpg_ggplot2.csv")
    DrawTools.init()
    fig = plt.figure(figsize=(16, 10), dpi=80)
    grid = plt.GridSpec(4, 4, hspace=0.5, wspace=0.2)
    ax_main = fig.add_subplot(grid[:-1, :-1])
    ax_right = fig.add_subplot(grid[:-1, -1], xticklabels=[], yticklabels=[])
    ax_bottom = fig.add_subplot(grid[-1, :-1], xticklabels=[], yticklabels=[])
    # displ 发动机排量(L)
    # hwy 公路里程/加仑
    DrawTools.scatter(data=data, feature_x='displ', feature_y='hwy', feature_c='manufacturer', feature_s='cty',
                      ax=ax_main, xlim=(1, 7), ylim=(0, 50))
    DrawTools.font_desc(ax_main, title='边缘直方图 \n 发动机排量 vs 公路里程/加仑', xlabel='发动机排量(L)', ylabel='公里路程/加仑')
    # 对右侧和下方绘制箱线图
    DrawTools.boxplot(data, 'hwy', vertical=True, color="red", ax=ax_right)
    DrawTools.boxplot(data, 'displ', vertical=False, color="red", ax=ax_bottom)
    ax_bottom.set(xlabel='')
    ax_right.set(ylabel='')

    xlabels = ax_main.get_xticks().tolist()  # 将现有的标尺取出来,转化为带一位小数的浮点数
    ax_main.set_xticklabels(xlabels)  # 再将带一位小数的浮点数变成标尺
    plt.show()