Files
training.python.datascience/source/plotting/plotly-compose.py

19 lines
701 B
Python

import pandas as pd
from plotly.graph_objs import Figure, Bar
data = pd.DataFrame(data={
"product": ["pomme", "poire", "banane", "pêche"],
"price": [1.99, 2.49, 2.99, 3.49], "wpu": [200, 180, 140, 200]
})
figure = Figure([
Bar(name="Prix", x=data["product"], y=data["price"], yaxis="y", offsetgroup=1),
Bar(name="Poids", x=data["product"], y=data["wpu"], yaxis="y2", offsetgroup=2),
])
# Afficher le dernier graphique généré
figure.layout.update({
"template": "seaborn",
"title": "Prix et poids unitaires", "font": {"family": "Cabin", "size": 13},
"yaxis": {"title": "Prix (€)"}, "yaxis2": {"title": "Poids (g)", "overlaying": "y", "side": "right"}
})
figure.show()