Bar + line

two traces.

Two traces on one figure.

Goal

Run every block and confirm the chart is visible.

df = pd.DataFrame({
    "city": ["Nairobi", "Mombasa", "Kisumu", "Nakuru", "Eldoret"],
    "units": [21, 15, 15, 18, 12],
    "shillings": [2100, 1500, 1480, 1750, 1190],
})
fig = go.Figure()
fig.add_bar(x=df["city"], y=df["units"], name="units")
fig.add_scatter(x=df["city"], y=df["shillings"] / 100, name="shillings/100", yaxis="y2")
fig.update_layout(title="overlay", yaxis2=dict(overlaying="y", side="right"))
fig.show()
print("mix")
df = pd.DataFrame({
    "city": ["Nairobi", "Mombasa", "Kisumu", "Nakuru", "Eldoret"],
    "units": [21, 15, 15, 18, 12],
    "shillings": [2100, 1500, 1480, 1750, 1190],
})
fig = px.bar(df, x="city", y="units")
fig.add_scatter(x=df["city"], y=df["units"], mode="lines+markers", name="line")
fig.show()
print("bar+line")
df = pd.DataFrame({
    "month": ["Jan", "Feb", "Mar", "Apr"] * 2,
    "mm": [48, 55, 92, 150, 22, 18, 40, 80],
    "city": ["Nairobi"] * 4 + ["Mombasa"] * 4,
})
fig = px.line(df, x="month", y="mm", color="city")
fig.show()
print("rain")
print("Prefer one scale when you can.")