【发布时间】:2020-01-19 03:58:08
【问题描述】:
我想使用以下简单代码叠加两个直方图,我目前只显示一个并排显示。这两个数据帧长度不同,但叠加它们的直方图值仍然有意义。
import plotly.express as px
fig1 = px.histogram(test_lengths, x='len', histnorm='probability', nbins=10)
fig2 = px.histogram(train_lengths, x='len', histnorm='probability', nbins=10)
fig1.show()
fig2.show()
纯情节,就是这样,抄自the documentation:
import plotly.graph_objects as go
import numpy as np
x0 = np.random.randn(500)
# Add 1 to shift the mean of the Gaussian distribution
x1 = np.random.randn(500) + 1
fig = go.Figure()
fig.add_trace(go.Histogram(x=x0))
fig.add_trace(go.Histogram(x=x1))
# Overlay both histograms
fig.update_layout(barmode='overlay')
# Reduce opacity to see both histograms
fig.update_traces(opacity=0.75)
fig.show()
我只是想知道情节表达是否有任何特别惯用的方式。希望这也有助于说明 plotly 和 plotly express 之间的完整性和不同抽象级别。
【问题讨论】:
标签: plotly plotly-express