1

我无法使用 matplotlib 使我的图表看起来正确/体面。线条不切换颜色,轴不显示,为了防止图形与标签重叠,我必须使图形非常大。示例图 代码在一个循环中,但这是与绘图相关的重要内容。总结:

  • 线条只停留一种颜色
  • 图表必须非常大,否则图表和标签将全部重叠
  • 缩放不断关闭
  • 有些线条根本没有出现
  • 标签正在消失

'''

    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")

'''

4

0 回答 0