【问题标题】:Non-overlapping numbers on plot axis绘图轴上的非重叠数字
【发布时间】:2013-12-29 20:05:18
【问题描述】:

我正在尝试使我的 y 轴上的数字不重叠,如下图所示。我的代码使用 matplotlib 使用 plt.tight_layout() 命令一次绘制所有 8 个图。我不确定修复底部四个图中重叠的最佳方法是什么。

import matplotlib.pyplot as plt
fig = plt.figure()
a1 = fig.add_subplot(421)
a2 = fig.add_subplot(422)
a3 = fig.add_subplot(423)
a4 = fig.add_subplot(424)
a5 = fig.add_subplot(425)
a6 = fig.add_subplot(426)
a7 = fig.add_subplot(427)
a8 = fig.add_subplot(428)

a1.plot(Msol, ilP, color='blue')
a1.set_xlabel(r'$M/M\odot$')
a1.set_ylabel(r'$Log Pressure$')

a2.plot(Msol, ilT, color='blue')
a2.set_xlabel(r'$M/M\odot$')
a2.set_ylabel(r'$Log Temperature$')

a3.plot(Msol, ilRho, color='blue')
a3.set_xlabel(r'$M/M\odot$')
a3.set_ylabel(r'$Log Density$')

a4.plot(Msol, Rsol, color='blue')
a4.set_xlabel(r'$M/M\odot$')
a4.set_ylabel(r'$R/R\odot$')

a5.plot(Msol, Lsol, color='blue')
a5.set_xlabel(r'$M/M\odot$')
a5.set_ylabel(r'$L/L\odot$')

a6.plot(Msol, iK, color='blue')
a6.set_xlabel(r'$M/M\odot$')
a6.set_ylabel(r'$Opacity$')

a7.plot(Msol, ieg, color='blue')
a7.set_xlabel(r'$M/M\odot$')
a7.set_ylabel(r'$\epsilon$')

a8.plot(Msol, ir_c, color='blue')
a8.set_xlabel(r'$M/M\odot$')
a8.set_ylabel(r'$Convective Ratio$')

plt.tight_layout()
plt.show()

【问题讨论】:

    标签: python matplotlib plot


    【解决方案1】:

    使用get_ylimset_yticks 可能还有set_fontsize

    import numpy as np
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot( np.random.randn( 1000 ).cumsum( ) )
    
    lb, ub = ax.get_ylim( )
    ax.set_yticks( np.linspace(lb, ub, 25 ) )
    
    for x in ax.get_yticklabels( ):
        x.set_fontsize( 'small' )
    

    【讨论】:

      【解决方案2】:

      根据this pagetight_layout 仅适用于图形的位置和填充,而不适用于刻度范围和数量。你知道你的图表会很小,也许你应该自己adjust the number of ticks

      【讨论】:

        猜你喜欢
        • 2015-06-10
        • 1970-01-01
        • 2016-08-25
        • 2019-03-25
        • 1970-01-01
        • 1970-01-01
        • 2017-05-10
        • 2020-10-14
        • 2018-03-29
        相关资源
        最近更新 更多