Python Matplotlib中直方图上的多个断轴

Python Matplotlib中直方图上的多个断轴,python,macos,python-2.7,matplotlib,histogram,Python,Macos,Python 2.7,Matplotlib,Histogram,所以我得到了一些数据,我希望通过频率密度(不相等的类宽度)直方图来绘制,通过一些在线搜索,我创建了这个来允许我这样做 import numpy as np import matplotlib.pyplot as plt plt.xkcd() freqs = np.array([3221, 1890, 866, 529, 434, 494, 382, 92, 32, 7, 7]) bins = np.array([0, 5, 10, 15, 20, 30, 50, 100, 200, 500,

所以我得到了一些数据,我希望通过频率密度(不相等的类宽度)直方图来绘制,通过一些在线搜索,我创建了这个来允许我这样做

import numpy as np
import matplotlib.pyplot as plt

plt.xkcd()
freqs = np.array([3221, 1890, 866, 529, 434, 494, 382, 92, 32, 7, 7])
bins = np.array([0, 5, 10, 15, 20, 30, 50, 100, 200, 500, 1000, 1500])
widths = bins[1:] - bins[:-1]
heights = freqs.astype(np.float)/widths

plt.xlabel('Cost in Pounds')
plt.ylabel('Frequency Density')

plt.fill_between(bins.repeat(2)[1:-1], heights.repeat(2), facecolor='steelblue')
plt.show()  
但是,正如您可能看到的,这些数据在x轴上延伸到数千,在y轴上(密度)从微小的数据(100)延伸到数千。要解决这个问题,我需要断开两个轴。到目前为止,我发现最接近的帮助是,我发现很难使用它。您能帮忙吗?

谢谢,Aj。

你可以用条形图。设置xtick标签以表示仓位值

对数标度


谢谢然而,我试图做的部分工作是通过按区域表示频率来表示不同的类宽度。为此,我需要显示绘图的宽度。谢谢你的帮助。@user3033981啊,好的。我猜两个方向的对数刻度也不会有多大帮助。在对数刻度上很难看到相对宽度。在本例中,您还可以单独设置每个条的宽度,但同样的问题也会出现,因为需要缩小宽度才能使其更有意义。
import numpy as np
import matplotlib.pyplot as plt

plt.xkcd()
fig, ax = plt.subplots()
freqs = np.array([3221, 1890, 866, 529, 434, 494, 382, 92, 32, 7, 7])
freqs = np.log10(freqs)
bins = np.array([0, 5, 10, 15, 20, 30, 50, 100, 200, 500, 1000, 1500])
width = 0.35
ind = np.arange(len(freqs))
rects1 = ax.bar(ind, freqs, width)
plt.xlabel('Cost in Pounds')
plt.ylabel('Frequency Density')
tick_labels = [ '{0} - {1}'.format(*bin) for bin in  zip(bins[:-1], bins[1:])]
ax.set_xticks(ind+width)
ax.set_xticklabels(tick_labels)
fig.autofmt_xdate()
plt.show()