继the plotly directions绘制的分布,我想画出类似下面的代码的东西:与长度不均匀
import plotly.plotly as py
import plotly.figure_factory as ff
import numpy as np
# Add histogram data
x1 = np.random.randn(200) - 2
x2 = np.random.randn(200)
x3 = np.random.randn(200) + 2
x4 = np.random.randn(200) + 4
# Group data together
hist_data = [x1, x2, x3, x4]
group_labels = ['Group 1', 'Group 2', 'Group 3', 'Group 4']
# Create distplot with custom bin_size
fig = ff.create_distplot(hist_data, group_labels, bin_size = [.1, .25, .5, 1])
# Plot!
py.iplot(fig, filename = 'Distplot with Multiple Bin Sizes')
不过,我有一个现实世界的数据集是不均匀的样品尺寸(即第1组的计数与组2中的计数不同等)。此外,它是名称 - 值对格式。
下面是一些假的数据来说明:
# Add histogram data
x1 = pd.DataFrame(np.random.randn(100))
x1['name'] = 'x1'
x2 = pd.DataFrame(np.random.randn(200) + 1)
x2['name'] = 'x2'
x3 = pd.DataFrame(np.random.randn(300) - 1)
x3['name'] = 'x3'
df = pd.concat([x1, x2, x3])
df = df.reset_index(drop = True)
df.columns = ['value', 'names']
df
正如你所看到的,每个域名(X1,X2,X3)具有不同的数量,也是“名称”一栏是我想什么用作颜色。
有谁知道我怎么可以阴谋策划这个?
FYI在R,它非常简单,我只是简单的叫ggplot,并在aes(fill = names)
。
任何帮助将不胜感激,谢谢!
感谢您一个完美的解决方案。 –