如何在直方图上设置轴并交换x和y轴?

时间:2014-09-11 10:17:14

标签: python matplotlib histogram bin

我有一个数据集,我想在其中绘制每个深度的测量数量的直方图。我想绘制深度列中每个测量频率的直方图。我希望将数据从0m开始分成5m的块,最高可达155m。这个代码,给我一个直方图,看起来形状合理,但值似乎错了,我不能从0开始。此外,我希望能够交换x轴和y轴,使得深度在y轴上,并且频率在x轴上。

    import numpy as np
    import datetime as dt
    import matplotlib.pyplot as plt
    import glob


    #The data is read in, and then formatted so that an array Dout (based on depth) is created. This is done since multiple files will be read into the code, and so I can create the histogram for all the files I have up until this point.

    Dout = np.array(depthout)


    bins = np.linspace(0, 130, num=13) #, endpoint=True, retstep=False)


    plt.hist(Dout, bins)
    plt.xlabel('Depth / m')
    plt.ylabel('Frequency')
    plt.show()


    # the end

数据采用以下格式:

TagID    ProfileNo   ProfileDirn     DateTime    Lat     Lon     Depth   Temperature

1 个答案:

答案 0 :(得分:3)

您需要orientation hist import matplotlib.pyplot as plt import numpy as np fig, ax = plt.subplots() data = np.random.randn(1500) bins = np.linspace(-5, 5, 25, endpoint=True) ax.hist(data, bins, orientation='horizontal') ax.set_ylim([-5, 5]) plt.show() 的{​​{1}} kourg。{/ 3}}。

{{1}}

enter image description here