【发布时间】:2022-01-16 06:57:37
【问题描述】:
如果我使用plotly.express 制作直方图,那么颜色会相互覆盖:
import plotly.express as px
df = px.data.tips()
fig = px.histogram(df, x="total_bill", y="tip", color="sex", marginal="rug",
hover_data=df.columns)
fig.show()
但是,如果我使用ff.create_distplot,那么颜色会更透明:
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)
fig.show()
这样显示透明色,更好看。
有没有办法让颜色在px.histogram 中显示为那样?
【问题讨论】:
标签: python plotly plotly-python