Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Using with `matplotlib.testing.decorators.image_comparison`

Đang mở
#661 6 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
38/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
matplotlib, python

Hướng nghiên cứu

Bắt đầu bằng cách đọc src/mplfinance/_styles.py, đặc biệt là _apply_mpfstyle, và so sánh nó với matplotlib.testing.setup() và set_font_settings_for_testing(). Xem xét các bài kiểm thử so sánh hình ảnh và xác định cách tiếp cận nào giữ cho các font được kết xuất nhất quán giữa các Dev Containers cục bộ và GitHub Actions mà không yêu cầu mỗi bài kiểm thử phải truyền một style tùy chỉnh; được xem là hoàn tất khi các phép so sánh baseline hiện có đều vượt qua trong cả hai môi trường.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

question

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 of DejaVu Sans.

To quick fix it:

  1. Install Liberation fonts locally
    sudo apt install fonts-liberation
  2. Drop matplotlib fonts cache (file location and name can be different)
    rm ~/.cache/matplotlib/fontlist-v330.json
  3. Re-generate baseline images

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 sets font.family to DejaVu Sans.

But for mplfinance that makes no difference because the font.family gets overridden by _apply_mpfstyle call. For example, the default style sets it to sans-serif (comes from base_mpl_style='seaborn-darkgrid'), and then nobody knows which font maptlotlib is going to use for rendering.

Here I came up with two solutions:

pytest fixture

Pros:

  • uses only public API

Cons:

  • need to pass to every .plot(...)
@pytest.fixture
def mpf_style():
    return mpf.make_mpf_style(
        base_mpf_style="default", rc={"font.family": "DejaVu Sans"}
    )

@image_comparison(baseline_images=["test.png"])
def test(mpf_style):
  mpf.plot(..., style=mpf_style)
pytest before-all hook that mutates default style

Pros:

  • all the existing tests left untouched
  • never forget passing style=... in new ones

Cons:

  • gets broken on the underlying mplfinance implementation changes
def pytest_configure() -> None:
    mpf._styledata.default.style["rc"].append(("font.family", "DejaVu Sans"))
Ngôn ngữ chính
Python
Star
4.4k
Fork
678
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của matplotlib/mplfinance

Tất cả issue của matplotlib/mplfinance

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.