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

TDJ*_*J92 3 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
Run Code Online (Sandbox Code Playgroud)

数据格式如下:

TagID    ProfileNo   ProfileDirn     DateTime    Lat     Lon     Depth   Temperature
Run Code Online (Sandbox Code Playgroud)

tac*_*ell 6

你想要( Docs )的orientationkwarg 。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()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明