代码之家  ›  专栏  ›  技术社区  ›  crabcanon

PyPr-扩展X轴

  •  0
  • crabcanon  · 技术社区  · 6 年前

    这是我用来生成以下输出的代码:

        import pandas as pd
        import matplotlib.pyplot as plt
        import numpy as np
    
        xedges = [27.5, 35, 42.5, 50, 57.5, 65, 72.5, 80, 87.5, 95, 102.5, 110, 117.5, 125, 132.5, 140, 147.5, 155, 162.5]
        yedges = [0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320, 340, 360, 380]
        H = pd.read_stata ('R:/data.dta')
        fig = plt.figure()
        plt.imshow(H, cmap="nipy_spectral", interpolation='bilinear', origin='low',extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]])
    

    enter image description here

    图表上的x轴看起来非常压缩。我想能够产生相同的图表,但具有更大的X轴,我怎么能做到这一点?

    我怀疑这与“extent”参数有关,但我不确定如何做。

    1 回复  |  直到 6 年前
        1
  •  1
  •   crabcanon    6 年前

    我刚想好了解决方案是在代码中将纵横比设置为“auto”,如下所示:

    plt.imshow(H, cmap="nipy_spectral", interpolation='bilinear', origin='low',aspect = 'auto', extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]])