From 75c449e352df7999be7568078e5204da00942bd4 Mon Sep 17 00:00:00 2001 From: Ihor Dotsenko Date: Sun, 25 Feb 2024 19:14:47 +0000 Subject: [PATCH] Playground for matplotlib/mplfinance#661 --- .gitignore | 4 ++++ 1-without-liberation-fonts/.keep | 0 2-with-liberation-fonts/.keep | 0 Makefile | 15 +++++++++++++++ README.md | 12 ++++++++++-- script.py | 19 +++++++++++++++++++ 6 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 1-without-liberation-fonts/.keep create mode 100644 2-with-liberation-fonts/.keep create mode 100644 Makefile create mode 100644 script.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c8f8835 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +1-without-liberation-fonts/* +2-with-liberation-fonts/* + +!.keep diff --git a/1-without-liberation-fonts/.keep b/1-without-liberation-fonts/.keep new file mode 100644 index 0000000..e69de29 diff --git a/2-with-liberation-fonts/.keep b/2-with-liberation-fonts/.keep new file mode 100644 index 0000000..e69de29 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f444a75 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +setup: + pip install mplfinance pyarrow # install pyarrow only to get rid of pandas warning + +test: + sudo apt remove -y fonts-liberation + rm -f ~/.cache/matplotlib/fontlist-v330.json + FILE=1-without-liberation-fonts/image.png python script.py 2> 1-without-liberation-fonts/mpl-debug-logs.txt + + sudo apt update + sudo apt install fonts-liberation + rm -f ~/.cache/matplotlib/fontlist-v330.json + FILE=2-with-liberation-fonts/image.png python script.py 2> 2-with-liberation-fonts/mpl-debug-logs.txt + + echo && md5sum 1-without-liberation-fonts/image.png 2-with-liberation-fonts/image.png && echo + echo && tail -n 1 1-without-liberation-fonts/mpl-debug-logs.txt 2-with-liberation-fonts/mpl-debug-logs.txt diff --git a/README.md b/README.md index 6c97a1b..67cdad9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ -# mplfinance -For matplotlib/mplfinance#661 +1. Run `make setup` - installs the latest `mplfinance` + +2. Run `make test`: + +- remove fonts-liberation if installed +- renders the simplest chart +- installs fonts-liberation +- renders the chart again +- prints MD5 sums of the images +- prints the last lines of the `matplotlib` debug logs diff --git a/script.py b/script.py new file mode 100644 index 0000000..858eac8 --- /dev/null +++ b/script.py @@ -0,0 +1,19 @@ +import os + +import matplotlib.pyplot as plt +import pandas as pd + +import mplfinance as mpf + +plt.set_loglevel("debug") + +window = pd.DataFrame( + [ + [2.00, 4.00, 1.00, 3.00], + ], + columns=["open", "high", "low", "close"], +) + +window.index = pd.date_range("2022-01-01", periods=len(window), freq="D") + +mpf.plot(window, type="candle", savefig=os.environ["FILE"])