-
Notifications
You must be signed in to change notification settings - Fork 636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using with matplotlib.testing.decorators.image_comparison
#661
Comments
I spent some hours investigating the issue and looking for solutions. @DanielGoldfarb What do you think? |
@GarrisonD Thanks for putting time into this. Just a quick glance at what you wrote above, sounds like a similar issue I had, a year or two ago, when I upgraded Ubuntu and it took me a while to realize that the upgrade had a different set of fonts. I will try later this week to make time to look into this in more detail. In the meantime, can you please describe in some detail the steps you went through that initially led you to find this problem? Thanks. |
@DanielGoldfarb Are you familiar with Docker? I want to create a reproducible setup and share it with you. |
@GarrisonD |
@DanielGoldfarb Sorry, but no Docker this time... I found a better option 😄 Just open https://github.com/GarrisonD/mplfinance, create a new GitHub Codespace, and follow If I can help you with GitHub Codespaces, the code, testing, or whatever, just let me know! |
@GarrisonD sounds good. will take a look. |
The problem is that the baseline images generated locally (in a Dev Container) don't match the ones on CI (GitHub Actions running the latest Ubuntu LTS) and thus my tests fail. When I compared the images I figured out that different fonts are being used: CI's Ubuntu has more fonts pre-installed than a Dev Container so the text was rendered with
Liberation Sans
instead ofDejaVu Sans
.To quick fix it:
sudo apt install fonts-liberation
matplotlib
fonts cache (file location and name can be different)rm ~/.cache/matplotlib/fontlist-v330.json
Also to find a solution that won't fail when some font is added/removed locally/remotely, I dug deeper and figured out that
matpltolib
has a solution for this well-known issue: matplotlib.testing.setup() that calls set_font_settings_for_testing() that setsfont.family
toDejaVu Sans
.But for
mplfinance
that makes no difference because thefont.family
gets overridden by _apply_mpfstyle call. For example, thedefault
style sets it tosans-serif
(comes frombase_mpl_style='seaborn-darkgrid'
), and then nobody knows which fontmaptlotlib
is going to use for rendering.Here I came up with two solutions:
pytest
fixturePros:
Cons:
.plot(...)
pytest
before-all hook that mutatesdefault
stylePros:
style=...
in new onesCons:
mplfinance
implementation changesThe text was updated successfully, but these errors were encountered: