<commit_before># -*- coding: utf-8 -*-
import os

import numpy as np
import pytest

from moviepy.video.io.bindings import mplfig_to_npimage
from moviepy.video.VideoClip import VideoClip

from tests.test_helper import TMP_DIR

try:
    import matplotlib
except ImportError:
    matplotlib = None


@pytest.mark.skipif(True, reason="testing on github actions")
@pytest.mark.skipif(not matplotlib, reason="no mpl")
def test_matplotlib():
    # for now, python 3.5 installs a version of matplotlib that complains
    # about $DISPLAY variable, so lets just ignore for now.

    x = np.linspace(-2, 2, 200)

    duration = 2

    matplotlib.use("Agg")
    fig, ax = matplotlib.pyplot.subplots()

    def make_frame(t):
        ax.clear()
        ax.plot(x, np.sinc(x ** 2) + np.sin(x + 2 * np.pi / duration * t), lw=3)
        ax.set_ylim(-1.5, 2.5)
        return mplfig_to_npimage(fig)

    animation = VideoClip(make_frame, duration=duration)
    animation.write_gif(os.path.join(TMP_DIR, "matplotlib.gif"), fps=20)<commit_msg>Fix test 'test_matplotlib' in 'test_examples.py' (#1427)<commit_after># -*- coding: utf-8 -*-
import os

import numpy as np
import pytest

from moviepy.video.io.bindings import mplfig_to_npimage
from moviepy.video.VideoClip import VideoClip

from tests.test_helper import TMP_DIR

try:
    import matplotlib
except ImportError:
    matplotlib = None


@pytest.mark.skipif(not matplotlib, reason="no mpl")
def test_matplotlib_simple_example():
    import matplotlib.pyplot as plt

    plt.switch_backend("agg")

    x = np.linspace(-2, 2, 200)
    duration = 2

    fig, ax = plt.subplots()

    def make_frame(t):
        ax.clear()
        ax.plot(x, np.sinc(x ** 2) + np.sin(x + 2 * np.pi / duration * t), lw=3)
        ax.set_ylim(-1.5, 2.5)
        return mplfig_to_npimage(fig)

    animation = VideoClip(make_frame, duration=duration)
    animation.write_gif(os.path.join(TMP_DIR, "matplotlib.gif"), fps=20)
{'fraction_non_alphanumeric': 0.12074303405572756, 'fraction_numerical': 0.0196078431372549, 'mean_word_length': 3.447247706422018, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6401242', 'n_tokens_mistral': 732, 'n_tokens_neox': 700, 'n_words': 169}