[英]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.