From aa1016b8636686f81a748ee9f16113b592ad8b2a Mon Sep 17 00:00:00 2001 From: Valentin Cazin Date: Thu, 21 May 2026 21:38:27 +0200 Subject: [PATCH] Add chart watermark helper --- corporate-travel/main.py | 6 ++++++ food/main.py | 6 ++++++ pay/main.py | 6 ++++++ store-sales/main.py | 6 ++++++ watermark.py | 14 ++++++++++++++ 5 files changed, 38 insertions(+) create mode 100644 watermark.py diff --git a/corporate-travel/main.py b/corporate-travel/main.py index 597b288..0d2a895 100644 --- a/corporate-travel/main.py +++ b/corporate-travel/main.py @@ -1,8 +1,13 @@ from collections import OrderedDict import matplotlib.pyplot as plt from operator import itemgetter +from pathlib import Path import requests import re +import sys + +sys.path.append(str(Path(__file__).resolve().parents[1])) +from watermark import add_watermark # from https://www.businesstravelnews.com/Corporate-Travel-100/2018 s = """Deloitte @@ -119,4 +124,5 @@ plt.xlabel('$M') plt.title('2017 U.S.-Booked Air Volume') plt.gca().get_xaxis().get_major_formatter().set_scientific(False) +add_watermark() plt.show() diff --git a/food/main.py b/food/main.py index fb9a360..a48fb30 100644 --- a/food/main.py +++ b/food/main.py @@ -1,4 +1,9 @@ import matplotlib.pyplot as plt +from pathlib import Path +import sys + +sys.path.append(str(Path(__file__).resolve().parents[1])) +from watermark import add_watermark fruit = { 'banana': [.45, 7, '🍌'], @@ -51,4 +56,5 @@ plt.legend([plt.plot([], [], 'o')[0], plt.plot([], [], 'oC2')[0]], ['Fruit', 'Vegetable'], labelcolor="markerfacecolor") +add_watermark() plt.show() diff --git a/pay/main.py b/pay/main.py index b6258a6..7a23541 100644 --- a/pay/main.py +++ b/pay/main.py @@ -1,4 +1,9 @@ import matplotlib.pyplot as plt +from pathlib import Path +import sys + +sys.path.append(str(Path(__file__).resolve().parents[1])) +from watermark import add_watermark map = { 'Amazon': [4836, 164, 3.8], @@ -79,4 +84,5 @@ plt.legend([plt.plot([], [], 'o')[0] for i in range(3)], ['West coast', 'Rest of USA', 'Rest of World'], labelcolor=['C0', 'C1', 'C2']) +add_watermark() plt.show() diff --git a/store-sales/main.py b/store-sales/main.py index 628bf8a..85217b2 100644 --- a/store-sales/main.py +++ b/store-sales/main.py @@ -1,6 +1,11 @@ from collections import OrderedDict import matplotlib.pyplot as plt from operator import itemgetter +from pathlib import Path +import sys + +sys.path.append(str(Path(__file__).resolve().parents[1])) +from watermark import add_watermark # from https://stores.org/stores-top-retailers-2018/ s = """Walmart $374.80 Bentonville, Ark. 5,328 @@ -114,4 +119,5 @@ plt.xlabel('$') plt.title('Annual Sales per Store') plt.gca().get_xaxis().get_major_formatter().set_scientific(False) +add_watermark() plt.show() diff --git a/watermark.py b/watermark.py new file mode 100644 index 0000000..9afc51a --- /dev/null +++ b/watermark.py @@ -0,0 +1,14 @@ +import matplotlib.pyplot as plt + + +def add_watermark(text="github.com/PatMyron/data"): + plt.gcf().text( + 0.99, + 0.01, + text, + ha="right", + va="bottom", + fontsize=8, + color="0.35", + alpha=0.5, + )