import matplotlib import pandas as pd from matplotlib import pyplot from matplotlib.axes import Axes matplotlib.use("TkAgg") pyplot.style.use('ggplot') pyplot.rcParams["font.family"] = "Cabin" data = pd.DataFrame(data={ "product": ["pomme", "poire", "banane", "pêche"], "price": [1.99, 2.49, 2.99, 3.49], "wpu": [200, 180, 140, 200] }) # Générer un graphique dans Matplotlib data.plot.bar(x="product", y=["price", "wpu"], rot=0.0, secondary_y="wpu", legend="reverse", title="Prix et poids unitaires") prices, weights = pyplot.gcf().axes # type: Axes prices.legend(bbox_to_anchor=(0.0, 1.1), loc="upper left") weights.legend(bbox_to_anchor=(1.0, 1.1), loc="upper right") # Il est difficile de personnaliser le contenu du graphique options: dict = {"fontsize": 8, "color": "w", "rotation": 90, "label_type": "center"} prices.bar_label(prices.containers[0], labels=[f"{p}€" for p in data["price"]], **options) weights.bar_label(weights.containers[0], labels=[f"{p}g" for p in data["wpu"]], **options) pyplot.gcf().savefig("eda-matplotlib-bar-labeled.png")