Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Using with `matplotlib.testing.decorators.image_comparison`

Abierto
#661 6 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
38/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
matplotlib, python

Línea de trabajo

Empieza leyendo src/mplfinance/_styles.py, especialmente _apply_mpfstyle, y compáralo con matplotlib.testing.setup() y set_font_settings_for_testing(). Revisa las pruebas de comparación de imágenes y determina qué enfoque mantiene coherentes las fuentes renderizadas entre los Dev Containers locales y GitHub Actions sin requerir que cada prueba pase un estilo personalizado; se considera hecho cuando las comparaciones de baseline existentes pasan en ambos entornos.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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"))
Lenguaje dominante
Python
Estrellas
4.4k
Forks
678
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de matplotlib/mplfinance

Todos los issues de matplotlib/mplfinance

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.