我有2个单独的条形图,我想尝试并结合起来,但似乎无法将它们绑在一起
combinedPassengerSimulation['StartStation'].value_counts().sort_index().plot(kind='bar', color="Green")
combinedPassengerSimulation['EndStation'].value_counts().sort_index().plot(kind='bar', color="Blue")
这些行分别执行时效果很好,但我确实希望能够将它们组合在一起,理想地显示在2号和3号车站到达和离开的乘客的交叉路口
IIUC,您可以关注此
import pandas as pd
import numpy as np
import plotly.graph_objs as go
n = 100_000
df = pd.DataFrame({"StartStation":np.random.choice([1]*10+[2]*5+[3]*2, n),
"EndStation":np.random.choice([2]*4+[3]*7+[4]*2, n)})
# here you can use aggregate
out = df.agg({"StartStation": "value_counts",
"EndStation": "value_counts"})
fig = go.Figure()
for col in out.columns:
fig.add_trace(
go.Bar(x=out.index,
y=out[col],
name=col))
fig.show()
out.plot(kind='bar');