當使用matplotlib
繪製直方圖時,手動給出箱的列表相對容易,如示例here所示。如何使用plotly +袖釦使用DataFrame中的多個直方圖的特定列表框?
的一個簡單的例子如下:
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.hist(np.random.randn(10000), bins=np.arange(-4, 4, 0.1))
ax.hist(0.2 * np.random.randn(10000), bins=np.arange(-4, 4, 0.1))
plt.show()
這也可以從一個pandas.DataFrame
被等效地完成與:
pd.DataFrame({
'firstHistogram': np.random.randn(10000),
'secondHistogram': 0.2 * np.random.randn(10000)
}).plot(kind='hist', bins=np.arange(-4, 4, 0.1))
去進一步,plotly
允許直接接口pandas
通過cufflinks
模塊,它允許做東西像下面這樣:
pd.DataFrame({
'firstHistogram': np.random.randn(10000),
'secondHistogram': 0.2 * np.random.randn(10000)
}).iplot(kind='hist', bins=100)
但這裏是收集:通過cufflinks
提供的iplot
方法似乎並不接受bins
列表。 當上面的例子中提供了一個數字時,該數字將被用於獨立地對兩個數據集進行分類,這會導致不相等的分箱,並帶來潛在的誤導結果(請參閱上面圖中的相同高度)。
雖然使用histnorm='density'
選項可以稍微減輕此影響,但可能需要查看每個容器的計數而不是密度。
有沒有辦法解決這個問題?