File: test_fill.py

package info (click to toggle)
python-mpld3 0.3git%2B20140910dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,808 kB
  • ctags: 1,095
  • sloc: python: 3,595; makefile: 187
file content (36 lines) | stat: -rw-r--r-- 760 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Plot to test text"""
import matplotlib.pyplot as plt
import numpy as np
import mpld3


def create_plot():
    fig, ax = plt.subplots()
    ax.grid(color='lightgray')

    x = np.linspace(0, 4 * np.pi, 1000)
    y1 = 0.5 * np.sin(0.5 * x)
    y2 = np.sin(x)
    y3 = np.cos(x)

    y1[450:550] = np.nan

    ax.fill(x, y1, alpha=0.3, facecolor='green')
    ax.fill_between(x, y2, y3, alpha=0.3, facecolor='red')
    ax.fill_between(x, -y2, -y3, alpha=0.3, facecolor='blue')

    ax.set_xlim(0, 4 * np.pi)
    ax.set_ylim(-1.1, 1.1)

    ax.set_title("fill() and fill_between()", size=18)
    return fig


def test_fill():
    fig = create_plot()
    html = mpld3.fig_to_html(fig)
    plt.close(fig)


if __name__ == "__main__":
    mpld3.show(create_plot())