forked from bendichter/brokenaxes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
108 lines (84 loc) · 2.69 KB
/
test.py
File metadata and controls
108 lines (84 loc) · 2.69 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import matplotlib.pyplot as plt
from brokenaxes import brokenaxes
import numpy as np
from matplotlib.gridspec import GridSpec
import datetime
import pytest
def test_standard():
fig = plt.figure(figsize=(5, 2))
bax = brokenaxes(
xlims=((0, 0.1), (0.4, 0.7)), ylims=((-1, 0.7), (0.79, 1)), hspace=0.05
)
x = np.linspace(0, 1, 100)
bax.plot(x, np.sin(10 * x), label="sin")
bax.plot(x, np.cos(10 * x), label="cos")
bax.legend(loc=3)
bax.set_xlabel("time")
bax.set_ylabel("value")
def test_subplots():
sps1, sps2 = GridSpec(2, 1)
bax = brokenaxes(xlims=((0.1, 0.3), (0.7, 0.8)), subplot_spec=sps1)
x = np.linspace(0, 1, 100)
bax.plot(x, np.sin(x * 30), ls=":", color="m")
x = np.random.poisson(3, 1000)
bax = brokenaxes(xlims=((0, 2.5), (3, 6)), subplot_spec=sps2)
bax.hist(x, histtype="bar")
def test_log():
fig = plt.figure(figsize=(5, 5))
bax = brokenaxes(
xlims=((1, 500), (600, 10000)),
ylims=((1, 500), (600, 10000)),
hspace=0.15,
xscale="log",
yscale="log",
)
x = np.logspace(0.0, 4, 100)
bax.loglog(x, x, label="$y=x=10^{0}$ to $10^{4}$")
bax.legend(loc="best")
bax.grid(axis="both", which="major", ls="-")
bax.grid(axis="both", which="minor", ls="--", alpha=0.4)
bax.set_xlabel("x")
bax.set_ylabel("y")
def test_datetime():
fig = plt.figure(figsize=(5, 5))
xx = [datetime.datetime(2020, 1, x) for x in range(1, 20)]
yy = np.arange(1, 20)
bax = brokenaxes(
xlims=(
(
datetime.datetime(2020, 1, 1),
datetime.datetime(2020, 1, 3),
),
(
datetime.datetime(2020, 1, 6),
datetime.datetime(2020, 1, 20),
),
)
)
bax.plot(xx, yy)
fig.autofmt_xdate()
[x.remove() for x in bax.diag_handles]
bax.draw_diags()
def test_legend():
fig = plt.figure(figsize=(5, 2))
bax = brokenaxes(
xlims=((0, 0.1), (0.4, 0.7)), ylims=((-1, 0.7), (0.79, 1)), hspace=0.05
)
x = np.linspace(0, 1, 100)
h1 = bax.plot(x, np.sin(10 * x), label="sin")
h2 = bax.plot(x, np.cos(10 * x), label="cos")
bax.legend(handles=[h1, h2], labels=["1", "2"])
def test_text():
bax = brokenaxes(
xlims=((0, 0.1), (0.4, 0.7)), ylims=((-1, 0.7), (0.79, 1)), hspace=0.05
)
bax.text(0.5, 0.5, "hello")
def test_text_error():
bax = brokenaxes(
xlims=((0, 0.1), (0.4, 0.7)), ylims=((-1, 0.7), (0.79, 1)), hspace=0.05
)
with pytest.raises(ValueError):
bax.text(-11, -11, "hello")
def test_lims_arrays():
lims = np.arange(6).reshape((-1,2))
brokenaxes(xlims=lims, ylims=lims)