zoukankan      html  css  js  c++  java
  • 子图subplot

     
    1)第一种方式subplot:

    plt.figure()

    plt.subplot(2,3,1)

    plt.plot(x, y)

    plt.subplot(232)

    plt.bar(x, y)

    plt.subplot(233)

    plt.barh(x, y)

    plt.subplot(234)

    plt.bar(x, y)

    y1 = [7,8,5,3]

    plt.bar(x, y1, bottom=y, color = 'r')

    plt.subplot(235)

    plt.boxplot(x)

    plt.subplot(236)

    plt.scatter(x,y)

    plt.show()

    2)第二种方式add_subplot()

    fig = plt.figure()

    ax1 = fig.add_subplot(221)

    ax1.plot(x, x)

    ax2 = fig.add_subplot(222)

    ax2.plot(x, -x)

    ax3 = fig.add_subplot(223)

    ax3.plot(x, x ** 2)

    ax4 = fig.add_subplot(224)

    ax4.plot(x, np.log(x))

    plt.show()

    3)第三种方式

    fig, axes = plt.subplots(2, 2)

    axes[0,0].hist(np.random.randn(500), bins=50, color='k', alpha=0.5)

    axes[0,1].hist(np.random.randn(500), bins=50, color='r', alpha=0.5)

    4)subplot的一些参数的设置

    nrows            subplot的行数

    ncols             subplot的列数

    sharex            sharex=True使得所有subplot使用同一个X轴刻度(调节xlim将会影响所有的subplot)

    sharey            sharey=True使得所有subplot使用同一个Y轴刻度(调节ylim将会影响所有的subplot)

    subplot_kw    用于创建subplot的关键字字典

    **fig_kw       创建figure时的其他关键字

    plt.subplots_adjust(left=None, bottom=None, right=None, top=None,wspace=None, hspace=None)

    fig, axes = plt.subplots(2, 2, sharex=True, sharey=True)

    for i in range(2):

        for j in range(2):

            axes[i, j].hist(randn(500), bins=50, color='k', alpha=0.5)

    plt.subplots_adjust(wspace=0, hspace=0)

     

  • 相关阅读:
    Lombok 安装、入门
    详细解析@Resource和@Autowired的区别 , 以及@Qualifier的作用
    Spring中@Resource与@Autowired、@Qualifier的用法与区别
    springMVC整合swagger
    jetty maven插件
    【原创】Sagger使用
    Eclipse详细设置护眼背景色和字体颜色
    eclipse中相同代码的高亮显示
    Mybatis分页插件
    mybatis
  • 原文地址:https://www.cnblogs.com/yongfuxue/p/10107282.html
Copyright © 2011-2022 走看看