是否可以结合使用plotly distplot:
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=.2)
# Plot!
py.iplot(fig, filename='Distplot with Multiple Datasets')
使用plotly facet plots按行/列组进行直方图绘制(例如ggplot facet_grid?-我知道python的ggplot,但不是很必要):
import plotly.plotly as py
import plotly.figure_factory as ff
import pandas as pd
mpg = pd.read_table('https://raw.githubusercontent.com/plotly/datasets/master/mpg_2017.txt')
fig = ff.create_facet_grid(
mpg,
x='displ',
y='cty',
facet_row='cyl',
facet_col='drv',
marker={'color': 'rgb(234, 239, 155)'},
)
py.iplot(fig, filename='facet by row and col')
我希望能够使用DF,而不是手动拆分行/列单元格的所有组合,例如分为两个类别:
df = pd.DataFrame({'x': np.random.randn(200),
'cat1': ["a"]*100 + ["b"]*100,
'cat2': ["c"]*50 + ["d"]*50 + ["e"]*50 + ["f"]*50 })
ggplot(df, aes(x='x')) +\
geom_density(alpha=1 ) +\
facet_grid("cat1","cat2") + theme_bw()