[英]How do you set the axes on a histogram and swap the x and y axes?
我有一個數據集,我想繪制每個深度的測量數量的直方圖。 我想繪制深度列中每個測量頻率的直方圖。 我希望將數據從0m開始分成5m的塊,最高可達155m。 這個代碼,給我一個直方圖,它看起來是一個合理的形狀,但值似乎是錯誤的,我不能讓它從0開始。另外,我希望能夠交換x軸和y -axis,使深度在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
你想要hist
( Docs )的orientation
kwarg。
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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.