使用matplotlib(尤其是twinx())制作好图形时遇到麻烦

时间:2019-11-01 21:05:54

标签: python matplotlib graph twinx

我无法使用matplotlib使图形看起来正确/不错。线条不会切换颜色,不会显示轴,并且为了防止图形与标签重叠以及彼此之间相互重叠,我必须使图形很大。sample graph代码处于循环中,但这是与绘图有关的重要内容。摘要:

  • 线条只保留一种颜色
  • 图形必须很大,否则图形和标签将全部重叠
  • 缩放比例一直处于关闭状态
  • 根本没有出现几行
  • 标签不见了

'''

    fig = plt.figure()


    ax1 = plt.subplot2grid((5,2), (0,0), rowspan=1, colspan=1)
    ax2 = plt.subplot2grid((5,2), (0,1), rowspan=1, colspan=1)
    ax3 = plt.subplot2grid((5,2), (1,0), rowspan=2, colspan=2)
    ax4 = plt.subplot2grid((5,2), (1,0), rowspan=2, colspan=2)
    ax5 = plt.subplot2grid((5,2), (3,0), rowspan=2, colspan=2)
    ax6 = plt.subplot2grid((5,2), (3,0), rowspan=2, colspan=2)

    ax1.plot(x, y)
    ax1.set(xlabel='X (GSE) in km', ylabel='Y (GSE) in km',
            title=' X vs Y position')


    ax2.plot(x, z)
    ax2.set(xlabel='X (GSE) in km', ylabel='Z (GSE) in km',
            title=' X vs Z position')


    ax3.plot(FGM_time, Bx)

    ax3.set(xlabel='time', ylabel='Bx',
            title='Our Bx and Vx')
    ax3.set_xlim([start_Time, end_Time])


    ax4 = ax3.twinx()
    ax4.set_ylabel('Vx')    
    ax4.plot(CIS_time, maskVx)
    ax4.set_xlim([start_Time, end_Time])

    ax5.set_xlabel('time')
    ax5.set_ylabel('protons in cm^-3')
    ax5.plot(CIS_time, maskpro, color = 'tab:red')
    ax5.set_title('Proton and Oxygen densities')
    ax5.tick_params(axis = 'y', labelcolor = 'tab:red')
    ax5.set_xlim([start_Time, end_Time])

    ax6 = ax5.twinx()
    ax6.set_ylabel('Oxygen in cm ^ -3')    
    ax6.plot(CIS_time, maskoxy, color = 'tab:blue')
    ax6.tick_params(axis = 'y', labelcolor = 'tab:blue')
    ax6.set_xlim([start_Time, end_Time])

    plt.tight_layout()

    fig = matplotlib.pyplot.gcf()
    fig.set_size_inches(36, 48, forward = True)


    plt.show()

    fig.savefig("The graph for " + Filename + " with interval hours: " +  str(n) + ".pdf")

'''

0 个答案:

没有答案