Interactive Line Charts
Basic interactive line
Interactive line
import pandas as pd
import plotly.express as px
df = pd.DataFrame({
"date": pd.date_range("2025-01-01", periods=7, freq="D"),
"orders": [120, 140, 130, 160, 155, 170, 180],
})
fig = px.line(df, x="date", y="orders", markers=True, title="Daily orders")
fig.show()Interactive line
import pandas as pd
import plotly.express as px
df = pd.DataFrame({
"date": pd.date_range("2025-01-01", periods=7, freq="D"),
"orders": [120, 140, 130, 160, 155, 170, 180],
})
fig = px.line(df, x="date", y="orders", markers=True, title="Daily orders")
fig.show()Multiple lines (color)
Multiple lines
import pandas as pd
import plotly.express as px
df = pd.DataFrame({
"date": list(pd.date_range("2025-01-01", periods=5, freq="D")) * 2,
"orders": [120, 140, 130, 160, 155, 100, 110, 120, 125, 140],
"product": ["A"] * 5 + ["B"] * 5,
})
fig = px.line(df, x="date", y="orders", color="product", markers=True, title="Orders by product")
fig.show()Multiple lines
import pandas as pd
import plotly.express as px
df = pd.DataFrame({
"date": list(pd.date_range("2025-01-01", periods=5, freq="D")) * 2,
"orders": [120, 140, 130, 160, 155, 100, 110, 120, 125, 140],
"product": ["A"] * 5 + ["B"] * 5,
})
fig = px.line(df, x="date", y="orders", color="product", markers=True, title="Orders by product")
fig.show()Tips
- Use
hover_data=[...]hover_data=[...]to show extra fields. - Use
fig.update_layout(...)fig.update_layout(...)for labels and margins.
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
